两个商店都有不同的根类别.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());
};
Run Code Online (Sandbox Code Playgroud)
如果我打印商店ID,它会给我正确的号码.我在第二个商店只有一个产品,为什么我要从所有商店回收所有产品?我可以将主商店中的每个产品设置为不在Store2中显示,然后添加可见性过滤器,但这将需要永远.
另外,我刚注意到,如果我回应产品商店ID,我会得到当前ID,而不是它分配给的商店:
echo $_testproduct->getStoreId()
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
您还可以尝试将商店过滤器添加到资源模型,如下所示:
$collection = Mage::getResourceModel('catalog/product_collection')
->addStoreFilter($this->getStoreId())
->addAttributeToSelect('*');
Run Code Online (Sandbox Code Playgroud)
试试这个你得到你想要的
$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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39200 次 |
| 最近记录: |