[英]how to get all product collection using product name like and price ascending in magento?
I have different affiliate products with almost same name in database, how can we do a price comparison of those products in product details page? 我在数据库中有几乎相同名称的不同联盟产品,我们如何在产品详细信息页面中对这些产品进行价格比较? Can anyone help me with the shortest way? 谁能以最短的方式帮助我?
I tried this 我试过了
$product_id = Mage::registry('current_product')->getId();
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id);
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('name', ['like' => $_product->getName().'%']);
That seems like a good way to go about it to me, but you could probably simplify your code to just: 对我来说,这似乎是个好方法,但是您可以将代码简化为:
$_product = Mage::registry('current_product');
$_collection = $_product->getCollection()->addAttributeToFilter('name', ['like' => $_product->getName() . '%']);
Finally, the code below is working for me: 最后,以下代码对我有用:
$productName = Mage::registry('current_product')->getName();
$categoryId = Mage::registry('current_product')->getCategoryId();
$manufacturerId = Mage::registry('current_product')->getManufacturer();
$products = Mage::getModel('catalog/category')->load($categoryId);
$productslist = $products->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('manufacturer',$manufacturerId)
->addAttributeToFilter('name', ['like' => $productName . '%'])
->setOrder('price', 'ASC');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.