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]_Magento_Magento 1.7 - Fatal编程技术网

按自定义属性检索多个产品[magento]

按自定义属性检索多个产品[magento],magento,magento-1.7,Magento,Magento 1.7,我有一个产品的自定义属性,假设我有3-4个产品在该属性上具有相同的值。现在我想加载这3个产品并将它们存储在一个数组中。我是这样做的: $all_products = array(); $count = 0; $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('ordernumber'); foreach($collection as $

我有一个产品的自定义属性,假设我有3-4个产品在该属性上具有相同的值。现在我想加载这3个产品并将它们存储在一个数组中。我是这样做的:

$all_products = array();
$count = 0;
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('ordernumber');
foreach($collection as $product)
{
    $all_products[count] = array ('sku' => $product->getSku(), 'qty' => $this->getRequest()->get('qty'), 'size' => $product->getSize());
    $count++;
}
return $all_products;
注意:
ordernumber
有一个值,我只是从另一个地方得到它

无论如何,当我运行它时,我没有值。调试时-调试器终止于
$products[count]=…

我尝试通过自定义属性加载单个产品-
Mage::…->loadByAttribute('ordernumber',$ordernumber)并且它工作得很好

因此,我的猜测是,我没有正确地使用集合操作或数组,尽管我看到了一些示例,从中我得到了这个想法

我做错了什么?

试着这样做:

$all_products = array();
$count = 0;
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('ordernumber');
//add a filter if needed - uncomment the next 2 lines and adjust the value or $ordernumber
//$ordernumber = '123';
//$addAttributeToFilter('ordernumber', $ordernumber)

foreach($collection as $product)
{
    $all_products[$count] = array ('sku' => $product->getSku(), 'qty' => $this->getRequest()->get('qty'), 'size' => $product->getSize());
    $count++;
}
return $all_products;