好的,我运行了一个非常简单的模块,但是遇到了我无法解决的产品集合问题。这是问题所在:
1)我根据发布的搜索类别加载产品集合:
$products = Mage::getModel('catalog/product')
->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addAttributeToSelect('*')
->addAttributeToFilter('search_category', array('eq' => $data['search_category']));
Run Code Online (Sandbox Code Playgroud)
2)我在基本函数中使用此集合来检索属性:
$section = $this->getSections($products);
Run Code Online (Sandbox Code Playgroud)
3)接下来,在代码中,如果发布了另一个值,我将进一步过滤产品集合,这将运行另一个功能。
if($data['section'] != "")
{
$products->addAttributeToFilter('section', array('eq' => $data['section']));
$profile = $this->getProfiles($products);
echo count($products);
echo count($products->getIds());
}
Run Code Online (Sandbox Code Playgroud)
基本上,进入第二功能的产品是未经过滤的。如果在此阶段回显$ products对象的计数,它将为我提供产品集合中的原始金额,而不是过滤后的金额。
如果我回显$ products-> getIds(),它将为我提供正确的过滤计数。
我真的不明白为什么这行不通,我已经详细检查了代码,而且都是正确的。看来,如果我在函数中使用产品集合,就无法进一步过滤它。
如果将过滤器移到第一个函数上方,它将起作用,但显然可以给我所需的结果。
如果有人可以解释请帮忙!
我在prestashop数据库的产品表中添加了一个字段"mystock".现在我想在编辑产品页面中显示/编辑此文件.产品更新时也会更新.
我试图从数据库中创建一个产品的搜索.
我的DB:
tbl_brand
-----------
brand_id Brand_name
1 Canon
2 Nikon
tbl_product
-------------
prod_id prod_name brand_id
1 Canon PowerShot A810 16MP Point & Shoot Digital Camera 1
2 Canon Digital Camera PowerShot 8MP Point & Shoot 1
3 PowerShot 8MP Point & Shoot Digital Camera 1
4 PowerShot 8MP Point & Shoot Digital 1
Run Code Online (Sandbox Code Playgroud)
我的搜索关键字:
$keyword = 'Camera';
$keyword = 'Digital Camera';
$keyword = 'Canon Digital Camera';
$keyword = 'Canon Camera';
我的查询
Select * from tbl_product where prod_name like '%$keyword%'
Run Code Online (Sandbox Code Playgroud)
我得到前三个关键字的结果.但对于第四个关键字,我得到结果为空. …
我正在尝试制作一个 python 脚本来计算一些赢/输的机会。要做到这一点,我试图获得所有可能的输赢组合(K 是赢得比赛所需的胜利次数):
for combination in itertools.product(['W','L'], repeat=(K*2)-1):
if ((combination.count('L') < K) and (combination.count('W') == K)):
#calculate the chance of this situation happening
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这工作正常,直到重复变得很大(例如,如果 K=25)有人能给我一些关于如何解决这个问题的指示吗?
我想在列表中找出夫妻产品的总和.例如,给出了一个列表[1, 2, 3, 4]
.我想得到的是答案= 1*2 + 1*3 + 1*4 + 2*3 + 2*4 + 3*4
.
我使用暴力破解,它给了我非常大的列表的超时错误.我想要一种有效的方法来做到这一点.请告诉我,我该怎么做?
这是我的代码,这是有效的,但我需要更高效的一个:
def proSum(list):
count = 0
for i in range(len(list)- 1):
for j in range(i + 1, len(list)):
count += list[i] * list[j]
return count
Run Code Online (Sandbox Code Playgroud) 我想将每个项目放在一个数组中,将它们彼此相乘,然后找到倍数的最大值。
我尝试了很多事情,直到找到了该cycle
方法,然后才知道并陷入困境:
def adjacentElementsProduct(inputArray)
outArray = inputArray.cycle(inputArray.length){|num| num[0] * num[1]}.to_a
return outArray.max
end
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为Ruby显然没有(陈述的)能力来知道什么num[0]
或是什么num[1]
。
例如:
adjacentElementsProduct([3, 6, -2, -5, 7, 3]) => 21
Run Code Online (Sandbox Code Playgroud)
因为3*7
当所有数字相乘时是最大的乘积。
我想替换特定产品类别的"添加到购物车"按钮,当产品类型为a时'simple product'
.
我想在我可以看到所有产品(商店和存档页面)和单个产品页面的页面上这样做.
下面的代码只是隐藏我的产品类别的所有帖子中的添加到购物车按钮:
function western_custom_buy_buttons(){
$product = get_product();
if ( has_term( 'categ1', 'product_cat') ){
// removing the purchase buttons
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
}
}
add_action( 'wp', 'western_custom_buy_buttons' );
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?请帮忙.
是否可以在后端的WooCommerce产品页面中添加一些额外的字段,因为我需要添加12个自定义字段.
我试图找到一些相关的钩子没有成功.我发现的唯一方法是属性,但它不是一个方便的解决方案......
如何在运送选项卡中将自定义字段添加到WooComerce产品设置页面?
谢谢.
我在网上找到了一段代码,目前列出了这个 WooCommerce 网站上的所有类别。
如何使其具体显示与他们正在查看的产品相关的类别?
这是我调整过的代码:
<div id="ListCat">
<h3>Listed in the following categories<?php the_category(); ?></h3>
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 0; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => …
Run Code Online (Sandbox Code Playgroud) 我在互联网上搜索过,但无论有多少人问这个问题,它似乎都没有任何答案.
有没有办法从所有优惠券中排除特定产品?
我知道你可以在优惠券级别上做到这一点,但这是相当混乱的,特别是因为很多人都有自动优惠券,有几个人创建优惠券等...
TLDR:任何方式使产品从产品级别的所有优惠券中排除.
product ×10
php ×6
woocommerce ×4
wordpress ×4
categories ×2
python ×2
arrays ×1
brute-force ×1
collections ×1
coupon ×1
cycle ×1
list ×1
magento ×1
mysql ×1
prestashop ×1
probability ×1
ruby ×1
search ×1
shipping ×1
sum ×1