Get PRODUСT per categoria IDS è passato come parametro di query
-
12-12-2019 - |
Domanda
Voglio usare l'url http://mydomain.test/Categoria-Name.html? Cat= 9,10,40 Ho bisogno di ottenere tutti i prodotti dalla categoria "Nome categoria" e categorie con ID 9, 10 e 40.
Come posso farlo.Forse c'è un'estensione del genere?
Soluzione
Se vuoi tutti i prodotti per la categoria 9 puoi farlo:
$category_id = 9;
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getResourceModel('catalog/product_collection')
->setStoreId(Mage::app()->getStore()->getId())
->addCategoryFilter($category);
.
Puoi farlo per le altre categorie.
Per stampare i prodotti che puoi fare qualcosa del genere:
foreach ($products as $_product) { ?>
<a href="<?php echo $_product->getProductUrl() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" />
</a>
<a href="<?php echo $_product->getProductUrl(); ?>">
<?php echo $_product->getName(); ?>
</a>
<?php } ?>
.
Se vuoi una lista prova qualcosa del genere:
$collection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => '9'),
array('finset' => '10'),
array('finset' => '40')
)
->addAttributeToSort('created_at', 'desc');
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange