/**
  * Add only is in stock products filter to product collection
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  *
  * @return Mage_CatalogInventory_Model_Resource_Stock_Status
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
     $joinCondition = $this->_getReadAdapter()->quoteInto('e.entity_id = status_table_mli.product_id' . ' AND status_table_mli.store_id = ?', Mage::app()->getStore()->getId());
     $collection->getSelect()->join(array('status_table_mli' => $this->getTable('demac_multilocationinventory/stock_status_index')), $joinCondition, array())->where('status_table_mli.is_in_stock=1');
     return $this;
 }
 /**
  * Add only is in stock products filter to product collection
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  * @return Mage_CatalogInventory_Model_Resource_Stock_Status
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
     $joinCondition = $this->_getReadAdapter()->quoteInto('e.entity_id = stock_status_index.product_id' . ' AND stock_status_index.website_id = ?', $websiteId);
     $joinCondition .= $this->_getReadAdapter()->quoteInto(' AND stock_status_index.stock_id = ?', Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID);
     $collection->getSelect()->join(array('stock_status_index' => $this->getMainTable()), $joinCondition, array())->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
     return $this;
 }
 /**
  * Add index select in product collection
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  * @param int $customerGroupId
  * @return Enterprise_CatalogPermissions_Model_Resource_Permission_Index
  */
 public function addIndexToProductCollection($collection, $customerGroupId)
 {
     $parts = $collection->getSelect()->getPart(Zend_Db_Select::FROM);
     if (isset($parts['perm'])) {
         return $this;
     }
     if ($collection->getFlag('disable_root_category_filter')) {
         $permColumns = $this->_getPermColumns();
     } else {
         $permColumns = array('grant_catalog_category_view', 'grant_catalog_product_price', 'grant_checkout_items');
     }
     $collection->getSelect()->joinLeft(array('perm' => $this->getTable('permission_index')), 'perm.category_id=cat_index.category_id
                     AND perm.customer_group_id= ' . $customerGroupId . ' AND perm.website_id=' . Mage::app()->getStore()->getWebsiteId(), $permColumns);
     if (!Mage::helper('enterprise_catalogpermissions')->isAllowedCategoryView()) {
         $collection->getSelect()->where('perm.grant_catalog_category_view = ?', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
     } else {
         $collection->getSelect()->where('perm.grant_catalog_category_view != ?' . ' OR perm.grant_catalog_category_view IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY);
     }
     $collection->getSelect()->where('cat_index.store_id=' . $collection->getStoreId());
     if ($collection->getFlag('disable_root_category_filter')) {
         $collection->getSelect()->where('cat_index.is_parent=1');
         $collection->getSelect()->group('cat_index.product_id');
     }
     if ($this->_isLinkCollection($collection)) {
         $collection->getSelect()->where('perm.grant_catalog_product_price!=' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . ' OR perm.grant_catalog_product_price IS NULL')->where('perm.grant_checkout_items!=' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . ' OR perm.grant_checkout_items IS NULL');
     }
     return $this;
 }
Example #4
0
 /**
  * Add bundle price range index to Product collection
  *
  * @param Mage_Catalog_Model_Resource_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('Mage_Customer_Model_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;
 }
 /**
  * Inner join the groupscatalog index table to not count products
  * not visible to the specified customer group id
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  * @param int $groupId
  * @return void
  */
 public function addGroupsCatalogFilterToProductCollectionCountSelect(Mage_Catalog_Model_Resource_Product_Collection $collection, $groupId)
 {
     /* @var $helper Netzarbeiter_GroupsCatalog2_Helper_Data */
     $helper = Mage::helper('netzarbeiter_groupscatalog2');
     // Switch index table depending on the specified entity
     $this->_init($helper->getIndexTableByEntityType(Mage_Catalog_Model_Product::ENTITY), 'id');
     if ($this->_doesIndexExists()) {
         $table = $this->getTable($helper->getIndexTableByEntityType(Mage_Catalog_Model_Product::ENTITY));
         $this->_addGroupsCatalogFilterToSelect($collection->getProductCountSelect(), $table, $groupId, $collection->getStoreId());
     }
 }
Example #6
0
 /**
  * Add information about stock status to product collection
  *
  * @param   Mage_Catalog_Model_Resource_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;
 }
 /**
  * Process all of the products within a given store.
  *
  * @param  Mage_Catalog_Model_Resource_Product_Collection $products products for a specific store
  * @param  EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances
  * @param  string $key
  * @param array $productIds
  * @return EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances
  */
 protected function _processProductCollection(Mage_Catalog_Model_Resource_Product_Collection $products, EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts, array &$productIds = null)
 {
     $excludedProductIds = array();
     $currentStoreId = $products->getStoreId();
     $config = Mage::helper('eb2ccore')->getConfigModel($currentStoreId);
     $clientId = $config->clientId;
     $catalogId = $config->catalogId;
     foreach ($products->getItems() as $product) {
         $product->setStoreId($currentStoreId);
         $pimProduct = $pimProducts->getItemForProduct($product);
         if (!$pimProduct) {
             $pimProduct = Mage::getModel('ebayenterprise_catalog/pim_product', array('client_id' => $clientId, 'catalog_id' => $catalogId, 'sku' => $product->getSku()));
             $pimProducts->addItem($pimProduct);
         }
         try {
             $pimProduct->loadPimAttributesByProduct($product, $this->_doc, $this->_getFeedConfig(), $this->_getFeedAttributes($currentStoreId));
         } catch (EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception $e) {
             $logData = ['sku' => $pimProduct->getSku()];
             $logMessage = 'Product "{sku}" excluded from export.';
             $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
             $excludedProductIds[] = $product->getId();
             $pimProducts->deleteItem($pimProduct);
         }
     }
     if ($productIds) {
         $productIds = array_diff($productIds, $excludedProductIds);
     }
     return $pimProducts;
 }
Example #8
0
 /**
  * Inner join the groupscatalog index table to not count products
  * not visible to the specified customer group id
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  * @param int $groupId
  * @return void
  */
 public function addGroupsCatalogFilterToProductCollectionCountSelect(Mage_Catalog_Model_Resource_Product_Collection $collection, $groupId)
 {
     $select = $collection->getProductCountSelect();
     $storeId = $collection->getStoreId();
     $this->addGroupsCatalogProductFilterToSelect($select, $groupId, $storeId);
 }
Example #9
0
 /**
  * Add index select in product collection
  *
  * @param Mage_Catalog_Model_Resource_Product_Collection $collection
  * @param int $customerGroupId
  * @return Enterprise_CatalogPermissions_Model_Resource_Permission_Index
  */
 public function addIndexToProductCollection($collection, $customerGroupId)
 {
     $adapter = $this->_getReadAdapter();
     $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[] = $adapter->quoteInto('permission_index_product.store_id = ?', $collection->getStoreId());
     }
     $conditions[] = $adapter->quoteInto('permission_index_product.customer_group_id = ?', $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 != ?' . ' OR permission_index_product.grant_catalog_category_view IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY);
         }
         /*
          * 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 != ?' . ' OR permission_index_product.grant_catalog_product_price IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY);
                 }
                 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 != ?' . ' OR permission_index_product.grant_checkout_items IS NULL', Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY);
                 }
             }
         }
     }
     return $this;
 }