本文整理汇总了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;
//.........这里部分代码省略.........
示例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;
}