簡體   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