Php 如何在magento中使用产品名称和价格升幅获取所有产品集合?
我在数据库中有不同的联属产品,名称几乎相同,我们如何在产品详细信息页面中对这些产品进行价格比较?谁能帮我找到最短的路吗 我试过这个Php 如何在magento中使用产品名称和价格升幅获取所有产品集合?,php,magento,product,Php,Magento,Product,我在数据库中有不同的联属产品,名称几乎相同,我们如何在产品详细信息页面中对这些产品进行价格比较?谁能帮我找到最短的路吗 我试过这个 $product_id = Mage::registry('current_product')->getId(); $obj = Mage::getModel('catalog/product'); $_product = $obj->load($product_id); $collection = Mage::getModel('catalog/
$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().'%']);
对我来说,这似乎是一个很好的方法,但您可以将代码简化为:
$_product = Mage::registry('current_product');
$_collection = $_product->getCollection()->addAttributeToFilter('name', ['like' => $_product->getName() . '%']);
最后,下面的代码适用于我:
$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');
谢谢,您能建议我们如何将按价格订购的ASC和产品名称添加到同一产品系列中吗?@Surekha-为了将来的参考,您不应该就原始问题的有效答案提出后续问题。有多种方法可以按价格排序,所以这应该是一个单独的问题,但是。