好的,我正在运行Magento 1.7并且我的老板已经要求我们在我们网站的顶部有一个栏,显示库存物品总数和所述库存的总 Value .
到目前为止,我已经找出了项目的总数 . 我不是很擅长PHP,所以它经历了很多试验和错误 .
这是我的代码到目前为止的样子[更新:有一个过滤器来排除缺货产品]:
$collection = Mage::getModel('catalog/product')->getCollection()
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
)
->addAttributeToFilter('qty', array('eq' <= 0));
$_coreHelper = $this->helper('core');
$sum = 0;
foreach ($collection as $product){
$sum += $product->getPrice();
}
?>
As of today our inventory consists of <?php echo $collection->count(); ?> items with a total value of <?php echo $_coreHelper->currency($sum); ?>
总和部分显然不起作用 .
任何人都可以给我一些关于如何实现这一目标的指示 . 我假设您将使用循环来加载所有产品价格,然后将一个总和添加到一起并显示总数,但正确到达这对我来说是一个问题 .
任何帮助,将不胜感激 .