两个商店都有不同的根类别. 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()
如何解决这个问题?
尝试这个你想要的
原文链接:https://www.f2er.com/php/132720.html$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;