コード例 #1
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @param Mana_Filters_Model_Filter_Attribute $model
  * @param array $value
  * @return Mana_Filters_Resource_Filter_Attribute
  */
 public function applyToCollection($collection, $model, $value)
 {
     $attribute = $model->getAttributeModel();
     $connection = $this->_getReadAdapter();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value in (" . implode(',', array_filter($value)) . ")");
     $conditions = join(' AND ', $conditions);
     $collection->getSelect()->distinct()->join(array($tableAlias => $this->getMainTable()), $conditions, array());
     return $this;
 }
コード例 #2
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @param Mana_Filters_Resource_Filter_Attribute $model
  * @param array $value
  * @return Mana_Filters_Resource_Filter_Attribute
  */
 public function applyToCollection($collection, $model, $value)
 {
     $attribute = $model->getAttributeModel();
     $connection = $this->_getReadAdapter();
     foreach ($value as $i => $singleValue) {
         $tableAlias = $attribute->getAttributeCode() . '_idx' . $i;
         $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value = {$singleValue}");
         $conditions = join(' AND ', $conditions);
         $collection->getSelect()->distinct()->join(array($tableAlias => $this->getMainTable()), $conditions, array());
     }
     return $this;
 }
コード例 #3
0
ファイル: Decimal.php プロジェクト: smitmanglam/staging
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @param Mana_Filters_Model_Filter_Attribute $model
  * @return Mana_Filters_Resource_Filter_Decimal
  */
 public function countOnCollection($collection, $model)
 {
     $select = $collection->getSelect();
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $attributeId = $model->getAttributeModel()->getId();
     $storeId = $collection->getStoreId();
     $select->join(array('decimal_index' => $this->getMainTable()), 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), array());
     $adapter = $this->_getReadAdapter();
     $countExpr = new Zend_Db_Expr("COUNT(*)");
     $rangeExpr = new Zend_Db_Expr("FLOOR(decimal_index.value / {$model->getRange()}) + 1");
     $select->columns(array('range' => $rangeExpr, 'count' => $countExpr));
     $select->group('range');
     return $adapter->fetchPairs($select);
 }
コード例 #4
0
ファイル: Decimal.php プロジェクト: xiaoguizhidao/ortodon
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @param Morphes_Filters_Model_Filter_Decimal $model
  * @param array $value
  * @return Morphes_Filters_Resource_Filter_Decimal
  */
 public function applyToCollection($collection, $model, $value)
 {
     $attribute = $model->getAttributeModel();
     $connection = $this->_getReadAdapter();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()));
     $condition = '';
     foreach ($value as $selection) {
         if (strpos($selection, ',') !== false) {
             list($index, $range) = explode(',', $selection);
             $range = $this->getRange($index, $range);
             if ($condition != '') {
                 $condition .= ' OR ';
             }
             $condition .= '((' . "{$tableAlias}.value" . ' >= ' . $range['from'] . ') ' . 'AND (' . "{$tableAlias}.value" . ($this->isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))';
         }
     }
     if ($condition) {
         $collection->getSelect()->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array())->distinct()->where("NOT ({$condition})");
     }
     return $this;
 }
コード例 #5
0
ファイル: Index.php プロジェクト: chucky515/Magento-CE-Mirror
 /**
  * Add bundle price range index to Product collection
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @return Mage_Bundle_Model_Price_Index
  */
 public function addPriceIndexToCollection($collection)
 {
     $productObjects = array();
     $productIds = array();
     foreach ($collection->getItems() as $product) {
         /* @var $product Mage_Catalog_Model_Product */
         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
             $productIds[] = $product->getEntityId();
             $productObjects[$product->getEntityId()] = $product;
         }
     }
     $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
     $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
     $addOptionsToResult = false;
     $prices = $this->_getResource()->loadPriceIndex($productIds, $websiteId, $groupId);
     foreach ($productIds as $productId) {
         if (isset($prices[$productId])) {
             $productObjects[$productId]->setData('_price_index', true)->setData('_price_index_min_price', $prices[$productId]['min_price'])->setData('_price_index_max_price', $prices[$productId]['max_price']);
         } else {
             $addOptionsToResult = true;
         }
     }
     if ($addOptionsToResult) {
         $collection->addOptionsToResult();
     }
     return $this;
 }
コード例 #6
0
 /**
  * Add information about stock status to product collection
  *
  * @param   Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $productCollection
  * @param   int|null $websiteId
  * @param   int|null $stockId
  * @return  Mage_CatalogInventory_Model_Stock_Status
  */
 public function addStockStatusToProducts($productCollection, $websiteId = null, $stockId = null)
 {
     if ($stockId === null) {
         $stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
     }
     if ($websiteId === null) {
         $websiteId = Mage::app()->getStore()->getWebsiteId();
         if ((int) $websiteId == 0 && $productCollection->getStoreId()) {
             $websiteId = Mage::app()->getStore($productCollection->getStoreId())->getWebsiteId();
         }
     }
     $productIds = array();
     foreach ($productCollection as $product) {
         $productIds[] = $product->getId();
     }
     if (!empty($productIds)) {
         $stockStatuses = $this->_getResource()->getProductStatus($productIds, $websiteId, $stockId);
         foreach ($stockStatuses as $productId => $status) {
             if ($product = $productCollection->getItemById($productId)) {
                 $product->setIsSalable($status);
             }
         }
     }
     /* back compatible stock item */
     foreach ($productCollection as $product) {
         $object = new Varien_Object(array('is_in_stock' => $product->getData('is_salable')));
         $product->setStockItem($object);
     }
     return $this;
 }
コード例 #7
0
ファイル: Status.php プロジェクト: codercv/urbansurprisedev
 /**
  * Add only is in stock products filter to product collection
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @return Mage_CatalogInventory_Model_Stock_Status
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
     $collection->getSelect()->join(array('stock_status_index' => $this->getMainTable()), 'e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = ' . $websiteId . ' AND stock_status_index.stock_id = ' . Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID, array())->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
     return $this;
 }
コード例 #8
0
ファイル: Index.php プロジェクト: jpbender/mage_virtual
 /**
  * Add index select in product collection
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @return Enterprise_CatalogPermissions_Model_Mysql4_Permission_Index
  */
 public function addIndexToProductCollection($collection, $customerGroupId)
 {
     $parts = $collection->getSelect()->getPart(Zend_Db_Select::FROM);
     $conditions = array();
     if (isset($parts['cat_index']) && $parts['cat_index']['tableName'] == $this->getTable('catalog/category_product_index')) {
         $conditions[] = 'permission_index_product.category_id = cat_index.category_id';
         $conditions[] = 'permission_index_product.product_id = cat_index.product_id';
         $conditions[] = 'permission_index_product.store_id = cat_index.store_id';
     } else {
         $conditions[] = 'permission_index_product.category_id IS NULL';
         $conditions[] = 'permission_index_product.product_id = e.entity_id';
         $conditions[] = 'permission_index_product.store_id=' . intval($collection->getStoreId());
     }
     $conditions[] = 'permission_index_product.customer_group_id=' . intval($customerGroupId);
     $condition = join(' AND ', $conditions);
     if (isset($parts['permission_index_product'])) {
         $parts['permission_index_product']['joinCondition'] = $condition;
         $collection->getSelect()->setPart(Zend_Db_Select::FROM, $parts);
     } else {
         $collection->getSelect()->joinLeft(array('permission_index_product' => $this->getTable('permission_index_product')), $condition, array('grant_catalog_category_view', 'grant_catalog_product_price', 'grant_checkout_items'));
         if (!Mage::helper('enterprise_catalogpermissions')->isAllowedCategoryView()) {
             $collection->getSelect()->where('permission_index_product.grant_catalog_category_view = ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
         } else {
             $collection->getSelect()->where('permission_index_product.grant_catalog_category_view != ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . '
                          OR permission_index_product.grant_catalog_category_view IS NULL');
         }
         /*
          * Checking if passed collection has link model attached
          */
         if (method_exists($collection, 'getLinkModel')) {
             $linkTypeId = $collection->getLinkModel()->getLinkTypeId();
             $linkTypeIds = array(Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL, Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL);
             /*
              * If collection has appropriate link type (cross-sell or up-sell) we need to
              * limit products by permissions (display price and add to cart)
              */
             if (in_array($linkTypeId, $linkTypeIds)) {
                 if (!Mage::helper('enterprise_catalogpermissions')->isAllowedProductPrice()) {
                     $collection->getSelect()->where('permission_index_product.grant_catalog_product_price = ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
                 } else {
                     $collection->getSelect()->where('permission_index_product.grant_catalog_product_price != ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . '
                                  OR permission_index_product.grant_catalog_product_price IS NULL');
                 }
                 if (!Mage::helper('enterprise_catalogpermissions')->isAllowedCheckoutItems()) {
                     $collection->getSelect()->where('permission_index_product.grant_checkout_items = ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
                 } else {
                     $collection->getSelect()->where('permission_index_product.grant_checkout_items != ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . '
                                  OR permission_index_product.grant_checkout_items IS NULL');
                 }
             }
         }
     }
     return $this;
 }