繁体   English   中英

magento产品名称集合

[英]magento product collection by name

  <?php
$needle= $_GET["singleid"];

$collection = Mage::getModel('catalog/product')->getCollection()->load();

$_productCollection = $collection->addAttributeToFilter('name', array(
    array('like' => '% '.$needle.' %'), //spaces on each side
    array('like' => '% '.$needle), //space before and ends with $needle
    array('like' => $needle.' %') // starts with needle and space after
));
foreach ($_productCollection as $_product){
   echo $_product->getId().'</br>';
   echo $_product->getName().'</br>';
   **echo $_product->getProductUrl().'</br>';**//getting this only
   echo $_product->getPrice().'</br>';
}

?>

我正在尝试根据产品名称获取产品集合,但仅获得产品URL。 我正在尝试获取名称等其他属性。 我的目的是创建一个搜索页面。

您需要选择那些属性。

        $needle= $_GET["singleid"];         
        $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('name', array(
                array('like' => '% '.$needle.' %'), //spaces on each side
                array('like' => '% '.$needle), //space before and ends with $needle
                array('like' => $needle.' %') // starts with needle and space after
        ));
        $collection->addAttributeToSelect('name', 'entity_id', 'price');
        foreach ($collection as $_product){

            echo $_product->getId().'</br>';
            echo $_product->getName().'</br>';
            echo $_product->getProductUrl().'</br>';//getting this only
            echo $_product->getPrice().'</br>';

        }

在这里查看更多信息

可能这可能会有所帮助:

$searchstring = 'Slim fit';
$productCollection = Mage::getModel('catalog/product')
                        ->getCollection() 
                        ->addAttributeToSelect('name')
                        ->addAttributeToFilter('name', array('like' => '%'.$searchstring.'%'));

foreach ($productCollection as $_product){

            echo $_product->getId().'</br>';
            echo $_product->getName().'</br>';
            echo $_product->getProductUrl().'</br>';
            echo $_product->getPrice().'</br>';

        }

可能你可以尝试一些类似的事情

$ _category = Mage :: getModel('catalog / category')-> loadByAttribute('name','Some Name');
$ _product = Mage :: getModel('catalog / product')-> loadByAttribute('name','some name xyz');

可能对你有帮助

你可以试试这个

$searchstring  = 'abc'  // search string 
$product_collection = Mage::getResourceModel('catalog/product_collection')
              ->addAttributeToSelect('*')
              ->addAttributeToFilter('name', array('like' => '%'.$searchstring.'%'))
              ->load();

 foreach ($product_collection as $product) {
     $ids[] = $product->getId();
 }
//return array of product ids

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM