2013-10-29 13 views
7

Cả hai cửa hàng đều có một danh mục gốc khác. Cửa hàng chính là dữ liệu mẫu mặc định, Cửa hàng thứ hai chỉ có một sản phẩm tôi đã được thêm vào. Tôi đã nghĩ rằng bằng cách sử dụng bộ lọc cửa hàng, chỉ các sản phẩm trong danh mục gốc của cửa hàng hiện tại mới hiển thị. Nhưng tôi nhận được mọi sản phẩm hiển thị. Tôi đang thử nghiệm điều này bằng cách đặt thông tin sau vào mẫu xem danh mục của tôi:Magento Lấy bộ sưu tập sản phẩm Bộ lọc theo mã cửa hàng

$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()); 
}; 

Nếu tôi in ID cửa hàng, số này cung cấp cho tôi số chính xác. Tôi chỉ có một sản phẩm trong Cửa hàng thứ hai, vậy tại sao tôi nhận được mọi sản phẩm từ tất cả các cửa hàng được trả lại? Tôi có thể đặt mọi sản phẩm trong Cửa hàng chính để không hiển thị trong Store2 và sau đó thêm bộ lọc hiển thị, nhưng điều đó sẽ mất vĩnh viễn.

Ngoài ra, tôi chỉ nhận thấy, nếu tôi vang các sản phẩm lưu trữ ID, tôi nhận được ID hiện tại, không phải là cửa hàng nó giao cho:

echo $_testproduct->getStoreId() 

Làm thế nào để giải quyết vấn đề này?

Trả lời

5

Hãy thử này Bạn nhận được như bạn muốn

$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; 
5

Bạn cũng có thể thử thêm một bộ lọc cửa hàng để các mô hình tài nguyên như thế này:

$collection = Mage::getResourceModel('catalog/product_collection') 
    ->addStoreFilter($this->getStoreId()) 
    ->addAttributeToSelect('*'); 
2
$collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($store_id) 
->addAttributeToSelect('*') // select all attributes 
->setPageSize(5000) // limit number of results returned 
->setCurPage(1); // set the offset (useful for pagination) 

// we iterate through the list of products to get attribute values 
foreach ($collection as $product) { 
    echo $product->getName(); //get name 
    echo (float) $product->getPrice(); //get price as cast to float 
    echo $product->getDescription(); //get description 
    echo $product->getShortDescription(); //get short description 
    echo $product->getTypeId(); //get product type 
    echo $product->getStatus(); //get product status 

    // getCategoryIds(); returns an array of category IDs associated with the product 
    foreach ($product->getCategoryIds() as $category_id) { 
     $category = Mage::getModel('catalog/category')->load($category_id); 
     echo $category->getName(); 
     echo $category->getParentCategory()->getName(); // get parent of category 
    } 
    //gets the image url of the product 
    echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA). 
     'catalog/product'.$product->getImage(); 
    echo $product->getSpecialPrice(); 
    echo $product->getProductUrl(); //gets the product url 
    echo '<br />'; 
} 
Các vấn đề liên quan