当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Catalog_Model_Category::getProductCollection方法代码示例

本文整理汇总了PHP中Mage_Catalog_Model_Category::getProductCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::getProductCollection方法的具体用法?PHP Mage_Catalog_Model_Category::getProductCollection怎么用?PHP Mage_Catalog_Model_Category::getProductCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Catalog_Model_Category的用法示例。


在下文中一共展示了Mage_Catalog_Model_Category::getProductCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _initProductCollectionArray

 /**
  * Save the collection array as object property
  * Added name and url_key as part of the array.
  */
 private function _initProductCollectionArray()
 {
     if (!$this->_collectionArray && !$this->_doNothing) {
         $productCollection = $this->_category->getProductCollection();
         $productCollection->addAttributeToSelect(array('entity_id', 'name', 'url_key'))->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', 4)->addCategoryFilter($this->_category)->setOrder('entity_id', 'ASC');
         $this->_collectionArray = $productCollection->exportToArray();
     }
 }
开发者ID:danielozano,项目名称:magento_prevnext,代码行数:12,代码来源:Links.php

示例2: _getProductCollection

 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             // this is category id
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         $todayDate = date('m/d/y');
         $tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('y'));
         $tomorrowDate = date('m/d/y', $tomorrow);
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         //$collection->getSelect()->order('rand()');
         $collection->addAttributeToSort('created_at', 'desc');
         $collection->addStoreFilter();
         $collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
         $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
         $collection->setPage(1, $numProducts)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
开发者ID:xiaoguizhidao,项目名称:tyler-live,代码行数:26,代码来源:special.php

示例3: _getProductCollection

 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
             //Sort order parameters
             $sortBy = $this->getSortBy();
             //param: sort_by
             if ($sortBy === NULL) {
                 $sortBy = 'position';
             }
             $sortDirection = $this->getSortDirection();
             //param: sort_direction
             if ($sortDirection === NULL) {
                 $sortDirection = 'ASC';
             }
             $collection->addAttributeToSort($sortBy, $sortDirection);
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
开发者ID:klord9x,项目名称:project-nam1,代码行数:38,代码来源:Featured.php

示例4: getProductCollection

 /**
  * Get category products collection
  *
  * The method is redefined to load all descending products when it's allowed
  * and category is not anchor (anchor categories load descending products
  * by default)
  *
  * @return Varien_Data_Collection_Db
  */
 public function getProductCollection()
 {
     $default = $this->getIsAnchor() || !Mage::getStoreConfig(MVentory_Productivity_Model_Config::_DISPLAY_PRODUCTS);
     if ($default) {
         return parent::getProductCollection();
     }
     return Mage::getResourceModel('catalog/product_collection')->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')->addAttributeToFilter('category_id', array('in' => $this->getAllChildren(true)))->setStoreId($this->getStoreId());
 }
开发者ID:hughwilkie,项目名称:MVentory_Productivity,代码行数:17,代码来源:Category.php

示例5: getProductCollection

 /** @return Mage_Core_Model_Mysql4_Collection_Abstract */
 function getProductCollection()
 {
     $collection = parent::getProductCollection();
     if ($this->shouldFilter()) {
         $collection->addIdFilter($this->getProductIdsInFilter());
         $this->filtered = true;
         // test only
     } else {
         $this->filtered = false;
         // test only
     }
     return $collection;
 }
开发者ID:naz-ahmed,项目名称:ndap-magento-mirror,代码行数:14,代码来源:Category.php

示例6: _moveProducts

 /**
  */
 private function _moveProducts()
 {
     $productSourceIds = $this->_source->getProductCollection()->setOrder('position', 'asc')->getAllIds();
     $productSourceItems = array_fill_keys($productSourceIds, 1);
     $productInsert = array_diff_key($productSourceItems, $this->_target->getProductsPosition());
     if (!empty($productInsert)) {
         $data = array();
         foreach ($productInsert as $productId => $position) {
             $data[] = array('category_id' => (int) $this->_target->getId(), 'product_id' => (int) $productId, 'position' => (int) $position);
         }
         $this->_getWriteAdapter()->insertMultiple($this->_getTable(), $data);
     }
 }
开发者ID:hanicker,项目名称:magento-category-merge,代码行数:15,代码来源:Merge.php

示例7: getProductIds

 public function getProductIds()
 {
     $categories = array(20, 49, 62, 72, 88, 101, 105, 114, 115);
     foreach ($categories as $cat) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat);
         $collection = $category->getProductCollection()->addAttributeToFilter(array(array('attribute' => 'image', 'nlike' => 'no_selection'), array('attribute' => 'image', 'null' => false)))->setPageSize(4)->addAttributeToSort('created_at', 'desc');
         foreach ($collection as $product) {
             $result[] = $product->getId();
         }
     }
     return $result;
 }
开发者ID:shebin512,项目名称:Magento_Zoff,代码行数:13,代码来源:Listcategories.php

示例8: getProductsInCategory

 public function getProductsInCategory(int $catId)
 {
     $_category = Mage::getModel('catalog/category')->load($catId);
     $subs = $_category->getAllChildren(true);
     $result = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $result[] = $product->getId();
         }
     }
     return $result;
 }
开发者ID:xiaoguizhidao,项目名称:blingjewelry-prod,代码行数:15,代码来源:Category.php

示例9: getObject

 public function getObject(Mage_Catalog_Model_Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $productCollection = $productCollection->addMinimalPrice();
     $category->setProductCount($productCollection->getSize());
     $transport = new Varien_Object();
     Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport));
     $customData = $transport->getData();
     $storeId = $category->getStoreId();
     $category->getUrlInstance()->setStore($storeId);
     $path = '';
     foreach ($category->getPathIds() as $categoryId) {
         if ($path != '') {
             $path .= ' / ';
         }
         $path .= $this->getCategoryName($categoryId, $storeId);
     }
     $image_url = NULL;
     try {
         $image_url = $category->getImageUrl();
     } catch (Exception $e) {
         /* no image, no default: not fatal */
     }
     $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => Mage::getBaseUrl() . $category->getRequestPath(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount());
     if (!empty($image_url)) {
         $data['image_url'] = $image_url;
     }
     foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
         $value = $category->getData($attribute['attribute']);
         $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_ressource) {
             $value = $attribute_ressource->getFrontend()->getValue($category);
         }
         if (isset($data[$attribute['attribute']])) {
             $value = $data[$attribute['attribute']];
         }
         if ($value) {
             $data[$attribute['attribute']] = $value;
         }
     }
     $data = array_merge($data, $customData);
     foreach ($data as &$data0) {
         $data0 = $this->try_cast($data0);
     }
     return $data;
 }
开发者ID:IvanRybakov,项目名称:algoliasearch-magento,代码行数:47,代码来源:Categoryhelper.php

示例10: _getProductCollection

 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
开发者ID:jronatay,项目名称:ultimo-magento-jron,代码行数:26,代码来源:Featured.php

示例11: testGetProductCollection

 public function testGetProductCollection()
 {
     $collection = $this->_model->getProductCollection();
     $this->assertInstanceOf('Mage_Catalog_Model_Resource_Product_Collection', $collection);
     $this->assertEquals($this->_model->getStoreId(), $collection->getStoreId());
 }
开发者ID:natxetee,项目名称:magento2,代码行数:6,代码来源:CategoryTest.php

示例12: _getProductCollection

 /**
  * Initialise product collection from the category
  *
  * Code is taken from Mage_Catalog_Model_Layer::prepareProductCollection()
  * method
  *
  * @param Mage_Catalog_Model_Category $category
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _getProductCollection($category)
 {
     $productAttributes = Mage::getSingleton('catalog/config')->getProductAttributes();
     $collection = $category->getProductCollection()->addAttributeToSelect($productAttributes)->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($category->getId());
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
     //Dispatch the event to emul;ate loading collection of products in catalog
     Mage::dispatchEvent('catalog_block_product_list_collection', array('collection' => $collection));
     return $collection;
 }
开发者ID:hughwilkie,项目名称:MVentory_Productivity,代码行数:20,代码来源:Attribute.php

示例13: getFeaturedProductsBox

 /**
  * Render Featured products inside navigation menu
  *
  * @param Mage_Catalog_Model_Category $category
  * @return string
  */
 public function getFeaturedProductsBox($category)
 {
     $cid = $category->getId();
     $html = array();
     $html[] = '<!-- NOCACHE key="featured-' . $cid . '" -->';
     $html[] = '<div class="featured-products"><span class="category-title">Featured product(s)</span>';
     $featured_products = $category->getProductCollection()->addAttributeToSelect('*')->addFieldToFilter(array(array('attribute' => 'max_featured', 'eq' => '1')))->load();
     $ids = $featured_products->getAllIds();
     if (!$ids || $ids == '' || $ids == 0) {
         return '';
     } else {
         $keys = array_rand($ids, 3);
         $random_ids = array();
         foreach ($keys as $key) {
             $random_ids[] = $ids[$key];
         }
         foreach ($random_ids as $id) {
             $featured = $featured_products->getItemById($id);
             $html[] = '<div class="product">';
             $html[] = '<a href="' . $featured->getProductUrl($category) . '">';
             $html[] = '<img src="' . Mage::helper('catalog/image')->init($featured, 'small_image')->resize(190, 150) . '" alt="' . $featured->getName() . '" />';
             $html[] = '<span class="product-name">' . $featured->getName() . '</span></a>';
             $html[] = '</div>';
         }
         $html[] = '<a class="view-more" href="' . $this->getCategoryUrl($category) . '">+ View more products</a>';
         $html[] = '</div>';
         $html[] = '<!-- ENDNOCACHE -->';
         return implode("\n", $html);
     }
 }
开发者ID:jokusafet,项目名称:MagentoSource,代码行数:36,代码来源:Navigation.php

示例14: setRelatedProducts

 public function setRelatedProducts()
 {
     $this->_beforeQuery();
     echo date("\nY-d-m H:i:s") . " - Adding related products\n";
     $sku_arr = array();
     foreach ($this->values as $lenses) {
         $sku_arr[] = $lenses['sku'];
     }
     $reltedIds = null;
     foreach ($sku_arr as $sku) {
         $relatedIds[] = Mage::getModel('catalog/product')->getCollection()->getItemByColumnValue('sku', $sku)->getId();
     }
     $_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Prescription Sunglasses')->getFirstItem();
     $subs = $_category->getAllChildren(true);
     $idsFromCat = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $idsFromCat[] = $product->getId();
         }
     }
     // +++++ select Oakley Ids  +++++ //
     $productsOakley = Mage::getModel('catalog/category')->load($this->oakleyCategoryId)->getProductCollection();
     $oakleyIds = array();
     foreach ($productsOakley as $product) {
         $oakleyIds[] = $product->getEntityId();
     }
     // +++++ select Special Sunglasses +++++ //
     $selectSpecial = Mage::getModel('catalog/product')->getCollection()->getSelect()->reset(Zend_Db_Select::COLUMNS)->joinInner(array('ps' => 'prescription_sunglasses'), 'e.sku = ps.sku', 'e.entity_id');
     $productsSpecial = $selectSpecial->query()->fetchAll();
     $specialIds = array();
     foreach ($productsSpecial as $product) {
         $specialIds[] = $product['entity_id'];
     }
     $productIds = array_diff($idsFromCat, $oakleyIds, $specialIds);
     echo "count Sunglasses Standard = " . count($productIds) . " samples: " . current($productIds) . ", " . next($productIds) . ", " . next($productIds) . "\n";
     foreach ($productIds as $prodId) {
         $this->setRelatedProduct($prodId, $relatedIds);
     }
     echo date("\nY-d-m H:i:s") . " - Related products added\n";
     $this->_afterQuery();
 }
开发者ID:CherylMuniz,项目名称:fashion,代码行数:44,代码来源:3st.php

示例15: array

$currentCategory = Mage::registry('current_category');
foreach ($_categories as $_category) {
    $catid = $_category->getId();
    $caturl = $_helper->getCategoryUrl($_category);
    $cat_elt = $doc->createElement('category_id');
    $doc->appendChild($cat_elt);
    $catid_elt = $doc->createElement('catid', $catid);
    $doc->appendChild($catid_elt);
    $note_elt->appendChild($cat_elt);
    $cat_elt->appendChild($catid_elt);
    $result = array();
    $brandid = array();
    $bname = array();
    $category = new Mage_Catalog_Model_Category();
    $category->load($catid);
    $collection = $category->getProductCollection()->addAttributeToFilter('attribute', 'brand');
    foreach ($collection as $_product) {
        $result[] = $_product->getId();
    }
    $newa = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('attribute_code', 'brand')->addAttributeToFilter('entity_id', array('in' => $result))->addAttributeToSelect(array('brand'), 'inner');
    foreach ($newa as $product) {
        $brandid[] = $product->getBrand();
        $bname[] = $product->getAttributeText('brand');
    }
    $a = array_unique($brandid);
    $b = array_unique($bname);
    $brand = array_combine($a, $b);
    foreach ($brand as $key => $value) {
        $brandid = $key;
        $brandname = $value;
        $brandurl = $caturl . '?action=view_all&amp;fq[brand]=' . str_replace(" ", "+", $value);
开发者ID:shebin512,项目名称:Magento_Zoff,代码行数:31,代码来源:createbrandxml.php


注:本文中的Mage_Catalog_Model_Category::getProductCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。