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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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;

脚本宝典总结

以上是脚本宝典为你收集整理的php – Magento通过商店ID获取产品集合过滤器全部内容,希望文章能够帮你解决php – Magento通过商店ID获取产品集合过滤器所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。