Beispiel #1
0
 /**
  * add join to select only in stock products
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection $collection
  * @return Mage_CatalogInventory_Model_Mysql4_Stock
  */
 public function setInStockFilterToCollection($collection)
 {
     $manageStock = AO::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
     $cond = array('{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0');
     if ($manageStock) {
         $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1';
     } else {
         $cond[] = '{{table}}.use_config_manage_stock = 1';
     }
     $collection->joinField('inventory_in_stock', 'cataloginventory/stock_item', 'is_in_stock', 'product_id=entity_id', '(' . join(') OR (', $cond) . ')');
     return $this;
 }
Beispiel #2
0
 /**
  * Prepare crosssell items data
  *
  * @return Mage_Catalog_Block_Product_List_Crosssell
  */
 protected function _prepareData()
 {
     $product = Mage::registry('product');
     /* @var $product Mage_Catalog_Model_Product */
     $this->_itemCollection = $product->getCrossSellProductCollection()->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->setPositionOrder()->addStoreFilter();
     //        Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
 public function getSize()
 {
     // 2nd part of OR condition added to fix 20 item limit problem in the admin
     if (is_null($this->isLoaded()) || $this->getLinkModel()->isLinkSourceManual()) {
         // We haven't loaded the collection yet (probably Admin page). Get size
         // by querying the DB in the usual way (this gets only the size of manually defined links)
         return parent::getSize();
     } else {
         $this->_totalRecords = count(array_keys($this->getItems()));
     }
     return intval($this->_totalRecords);
 }
Beispiel #4
0
 /**
  * Export collection to editable array
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection $collection
  * @return array
  */
 protected function _collectionToEditableArray($collection)
 {
     $result = array();
     foreach ($collection as $linkedProduct) {
         $result[$linkedProduct->getId()] = array();
         foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
             $result[$linkedProduct->getId()][$attribute['code']] = $linkedProduct->getData($attribute['code']);
         }
     }
     return $result;
 }