微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Magento通过商店ID获取产品集合过滤器

两个商店都有不同的根类别. Main Store是认的样本数据,Second Store只添加一个产品.我会想到使用商店过滤器,只有当前商店的根类别中的商品才会显示出来.但是我正在得到每个产品的显示.我正在通过在我的类别视图模板中放置以下内容进行测试:
$store_id = Mage::app()->getStore()->getId();
$_testproductCollection = Mage::getResourceModel('reports/product_collection')
->setStoreId($storeId)
->addStoreFilter($store_id)
->addAttributetoSelect('*');
$_testproductCollection->load();
foreach($_testproductCollection as $_testproduct){ 
echo $this->htmlEscape($_testproduct->getName()); 
};

如果我打印商店ID,它给我正确的数字.我在第二家商店只有一种产品,那么为什么我从所有的商店中获得每个产品呢?我可以设置Main Store中的每个产品,不能在Store2中显示,然后添加一个可见性过滤器,但这将永远存在.

另外,我刚刚注意到,如果我回覆产品商店ID,我得到当前的ID,而不是分配给它的商店:

echo $_testproduct->getStoreId()

如何解决这个问题?

尝试这个你想要的
$counter = "";
/*$model=Mage::getModel('catalog/product')->setStoreId($post['stores']);
$rootCategoryId = Mage::app()->getStore($post['stores'])->getRootCategoryId();
$products = $model->getCollection();
$products->addStoreFilter($post['stores']);
$products->addAttributetoFilter('sku',array('nlike' => 'B%'));
$products->addAttributetoFilter('status',1);
$counter=$products->getData();*/
$model=Mage::getModel('catalog/product')->setStoreId($post['stores']);
$category_model = Mage::getModel('catalog/category');
$rootCategoryId = Mage::app()->getStore($post['stores'])->getRootCategoryId();
$_category = $category_model->load($rootCategoryId);
$all_child_categories = $category_model->getResource()->getAllChildren($_category);
foreach($all_child_categories as $storecategories):

$category = Mage::getModel('catalog/category')->load($storecategories);
$products = $category->getProductCollection();
//echo "Category id is::".$storecategories."Products are::".count($products);
//echo "<br/>";
foreach($products as $collection):
   $removecatindex = $collection->getData();
   unset($removecatindex['cat_index_position']);
   $counter[] = $removecatindex;
  endforeach;
endforeach;

原文地址:https://www.jb51.cc/php/132720.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐