Php 如何在Magento中显示产品总量和可配置产品总量?

Php 如何在Magento中显示产品总量和可配置产品总量?,php,magento,Php,Magento,我正试图写一个脚本来显示 1) 产品总量,, 2) 可配置产品的总量, 3) 属性集“无”内的产品总数, 4) 订单的总金额,以及 5) Magento中特定时间范围内的订单总数$ 我已经解决了4)和5),但在找到1)2)和3)的解决方案时遇到了问题。有人能帮忙吗 ---------------------------2015年2月3日之后--------------------------- 这是在@Blastfreak帮助下修改的代码版本,该代码的问题在于,它显示了错误数量的可配置产品和“无

我正试图写一个脚本来显示 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
}

您的解决方案如下:

<?php 

$productModel = Mage::geModel('catalog/product');
$collection = $productModel->getCollection;

//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

$TotalConfigurableProduct= $collection->addAttributeToFilter('attribute_set_id','attribute set id here')->getSize();

非常感谢你,怪物!我已经编辑了这个问题。