【发布时间】:2015-02-03 00:20:33
【问题描述】:
我正在尝试编写一个脚本来显示 1)产品总量, 2)可配置产品的总量, 3)属性集“无”内的产品总量, 4) 订单总量,以及 5) Magento中一定时间范围内订单的总金额$。
我已经解决了 4) 和 5),但在找出 1) 2) 和 3) 的解决方案时遇到了问题。有人可以帮忙吗?
---------------2015 年 2 月 3 日之后 -------------- -------------
这是在@Blastfreak 帮助下的代码修改版本,此代码的问题是它显示了错误的可配置产品数量和“无”产品 - 看起来总数量已经显示不管了:
$productModel = Mage::getModel('catalog/product');
$collection = $productModel->getCollection();
//Attribute Set "None" and "NONE"
$attributeSetId_None1 = Mage::getModel('eav/entity_attribute_set')
->load($attrSetName, 'None')
->getAttributeSetId();
$attributeSetId_NONE2 = Mage::getModel('eav/entity_attribute_set')
->load($attrSetName, 'NONE')
->getAttributeSetId();
//1) Total Products
$TotalProducts = $collection->getSize();
//2) Configurable Products
$TotalConfigurableProduct= $collection->addAttributeToFilter('type_id', array('eq' => 'configurable'))->getSize();
//3) Total Productw within attribute set none
if ($attributeSetId_None1 || $attributeSetId_NONE2){
$Total_None1= $collection->addAttributeToFilter('attribute_set_id',$attributeSetId_None1)->getSize();
$Total_NONE2= $collection->addAttributeToFilter('attribute_set_id',$attributeSetId_NONE2)->getSize();
$TotalNone=$Total_None1+$Total_NONE2;
}
else{
$TotalNone=0;
}
$TotalConfigurableAndNone=$TotalConfigurableProduct+$TotalNone;
我发现 foreach 循环可以显示正确数量的项目,而不是使用 getSize() 或 count()。例如:
foreach ($TotalConfigurableProduct as $total_config)
{
$k++; //the correct amount of configurable products
}
【问题讨论】: