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


PHP Mage_Catalog_Model_Resource_Product_Collection::count方法代码示例

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


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

示例1: _parseCollection

 /**
  * Returns a cleaner/well formed array of arrays of product data.
  *
  * Override this method in the child classes if you need to customize
  *
  * @param  Mage_Catalog_Model_Resource_Product_Collection   $collection
  * @return array
  */
 protected function _parseCollection(Mage_Catalog_Model_Resource_Product_Collection $collection)
 {
     // default return value
     $collectionToEncode = array();
     $itemType = $this->getItemType();
     $cacheKey = 'jewelrydesigner_' . $itemType . '_list';
     if ($this->getCache($cacheKey)) {
         Mage::log('hit ' . $cacheKey . ' cache!!!');
         $cachedData = $this->getCache($cacheKey);
         // Mage::log('cachedData: ' . print_r(unserialize($cachedData), true));
         return unserialize($cachedData);
     }
     if ($collection->count() > 0) {
         $skipAttributes = $this->getAttrsToSkipInJson();
         $visibilityOptions = $this->getVisibilityOptions();
         $attrsNeedingLabels = $this->getAttrsToFetchLabelsFrom();
         $baseUrl = Mage::getBaseUrl();
         $mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
         $baseDir = Mage::getBaseDir('base');
         $mediaDir = Mage::getBaseDir('media');
         foreach ($collection as $key => $product) {
             // $product = Mage::getModel('catalog/product')->load($product->getId());
             $productToEncode = array();
             $data = $product->getData();
             $productCatIds = $product->getCategoryIds();
             $excludedCategoryIds = $this->getExcludedCategoryIds();
             // check if the product's categories include any of the excluded categories
             $intersect = array_intersect($excludedCategoryIds, $productCatIds);
             if (empty($intersect)) {
                 // map common product data to flat array
                 foreach ($data as $k => $v) {
                     switch (true) {
                         case in_array($k, $skipAttributes):
                             # DO NOTHING: Skip these internal Magento attributes
                             break;
                             // format price as decimal instead of string
                         // format price as decimal instead of string
                         case $k === 'price':
                             $productToEncode['price'] = (double) $v;
                             break;
                             // item_type (i.e., 'bracelet', 'charm', 'clip', 'spacer', etc.)
                         // item_type (i.e., 'bracelet', 'charm', 'clip', 'spacer', etc.)
                         case $k === 'item_type_value':
                             // make sure the product's item_type value is present otherwise
                             // default to the value defined in the child classes
                             $productToEncode['item_type'] = !empty($v) ? $v : $itemType;
                             break;
                             // product type (i.e., 'configurable', 'simple', etc.)
                         // product type (i.e., 'configurable', 'simple', etc.)
                         case $k === 'type_id':
                             $productToEncode['product_type'] = $v;
                             break;
                             // product's id
                         // product's id
                         case $k === 'entity_id':
                             $productToEncode['id'] = $v;
                             break;
                             // stock related (is_in_stock, etc.)
                         // stock related (is_in_stock, etc.)
                         case $k === 'stock_item':
                             $stockData = $v->getData();
                             $productToEncode['is_in_stock'] = (bool) $stockData['is_in_stock'];
                             break;
                             // visibility
                         // visibility
                         case $k === 'visibility':
                             $productToEncode[$k] = $visibilityOptions[$v];
                             break;
                             // various select/multi-select attributes
                         // various select/multi-select attributes
                         case in_array($k, $attrsNeedingLabels):
                             $productToEncode[$k] = $this->getAttrOptionLabel($k, $v);
                             break;
                             // images
                         // images
                         case in_array($k, array('image', 'small_image', 'thumbnail', 'designer_canvas', 'designer_grid_thumb')):
                             $imgPath = $product->getData($k);
                             if (!empty($imgPath)) {
                                 // $imgUrl     = (string) $imgHelper->init($product, $k)->resize($resize);
                                 $imgUrl = $this->_resizeImage($product, $k, $itemType);
                                 $imgRelUrl = str_replace($mediaUrl, '/media/', $imgUrl);
                                 $imgPath = $baseDir . $imgRelUrl;
                                 if (file_exists($imgPath)) {
                                     /**
                                      * I know, I know...error suppression is usually bad, but the getimagesize()
                                      * will only produce E_WARNING (if accessing file is impossible) or
                                      * E_NOTICE for a read error
                                      *
                                      * @see  http://php.net/manual/en/function.getimagesize.php
                                      */
                                     list($imgWidth, $imgHeight) = @getimagesize($imgPath);
                                     $productToEncode['images'][$k]['url'] = $imgUrl;
//.........这里部分代码省略.........
开发者ID:AleksNesh,项目名称:pandora,代码行数:101,代码来源:Abstract.php

示例2: addDeleteErrors

 /**
  * given a Mage_Catalog_Model_Resource_Product_Collection object if there's any product
  * add them to the error confirmation file
  * @param  Mage_Catalog_Model_Resource_Product_Collection $collection
  * @param  string $fileName the file the sku was found on
  * @param  string $type the event type
  * @return self
  */
 protected function addDeleteErrors(Mage_Catalog_Model_Resource_Product_Collection $collection, $fileName, $type)
 {
     if ($collection->count()) {
         foreach ($collection as $product) {
             $this->appendError(self::SKU_NOT_REMOVE, '', $type, $fileName, $product->getSku());
         }
     }
     return $this;
 }
开发者ID:sirishreddyg,项目名称:magento-retail-order-management,代码行数:17,代码来源:Confirmations.php


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