Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-Varien网格-总计整个集合_Magento_Grid - Fatal编程技术网

Magento-Varien网格-总计整个集合

Magento-Varien网格-总计整个集合,magento,grid,Magento,Grid,我已经使用varien网格功能创建了一个定制产品网格,并将其用作订单。基本上,有一个产品名称、产品价格和一个输入字段供用户输入他们想要的产品数量 有数千种产品,我需要对用户选择的产品进行小计 我得到的最接近的结果是将以下内容添加到Grid.php中 protected function _afterLoadCollection() { $collection = $this->getCollection()->load(); $total = 0; if

我已经使用varien网格功能创建了一个定制产品网格,并将其用作订单。基本上,有一个产品名称、产品价格和一个输入字段供用户输入他们想要的产品数量

有数千种产品,我需要对用户选择的产品进行小计

我得到的最接近的结果是将以下内容添加到Grid.php中

   protected function _afterLoadCollection()
{
    $collection = $this->getCollection()->load();
    $total = 0;
    if ($collection) {
            foreach($collection as $item)  {
                    $itemPrice = $item->getPrice();
                    $itemQty = $item->getQty();
                    $total = $total + ($itemPrice * $itemQty);
            }
       echo $total;
    }
}
但是,结果受当前限制的影响,因此只对当前页面进行合计

有没有办法解决这个问题,或者有更好的方法来计算两列的运行总数


提前谢谢,这件事我已经坚持了好几天了

您可以尝试清除集合补充,并为第一页设置一个较大的限制

$\u productCollection=$this->getLoadedProductCollection; $\u productCollection->clear; $\u productCollection->SetPage199999;