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;

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...