/** * observes eav_collection_abstract_load_before to add attributes and joins to grid collection * * @param Varien_Event_Observer $event * @return void */ public function eavCollectionAbstractLoadBefore(Varien_Event_Observer $event) { $columnJoinField = array(); if (Mage::registry('firegento_gridcontrol_current_block')) { $blockId = Mage::registry('firegento_gridcontrol_current_block')->getId(); /** * @var FireGento_GridControl_Model_Config $config */ $config = Mage::getSingleton('firegento_gridcontrol/config'); // add attributes to eav collection if ($event->getCollection() instanceof Mage_Eav_Model_Entity_Collection_Abstract) { foreach ($config->getCollectionUpdates(FireGento_GridControl_Model_Config::TYPE_ADD_ATTRIBUTE, $blockId) as $entry) { $event->getCollection()->addAttributeToSelect($entry); } } // join attributes to collection foreach ($config->getCollectionUpdates(FireGento_GridControl_Model_Config::TYPE_JOIN_ATTRIBUTE, $blockId) as $attribute) { $attribute = explode('|', $attribute); // 5 parameters needed for joinAttribute() if (count($attribute) < 5) { continue; } try { $event->getCollection()->joinAttribute($attribute[0], $attribute[1], $attribute[2], strlen($attribute[3]) ? $attribute[3] : null, $attribute[4]); } catch (Exception $e) { Mage::logException($e); } } // join fields to collection foreach ($config->getCollectionUpdates(FireGento_GridControl_Model_Config::TYPE_JOIN_FIELD, $blockId) as $field) { $field = explode('|', $field); // 6 parameters needed for joinField() if (count($field) < 6) { continue; } try { $event->getCollection()->joinField($field[0], $field[1], $field[2], $field[3], $field[4], $field[5]); } catch (Exception $e) { Mage::logException($e); } } // joins to collection foreach ($config->getCollectionUpdates(FireGento_GridControl_Model_Config::TYPE_JOIN, $blockId) as $field) { try { $event->getCollection()->join($field['table'], str_replace('{{table}}', '`' . $field['table'] . '`', $field['condition']), $field['field']); $columnJoinField[$field['column']] = $field['field']; } catch (Exception $e) { Mage::logException($e); } } // update index from join_index (needed for joins) foreach (Mage::registry('firegento_gridcontrol_current_block')->getColumns() as $column) { if (isset($columnJoinField[$column->getId()])) { $column->setIndex($columnJoinField[$column->getId()]); } } } }
/** * Add default ddq data to loaded product collection. * * @param Varien_Event_Observer $observer */ public function addDefaultDdqValuesToProductCollection(Varien_Event_Observer $observer) { if ($this->_getHelper()->isEnabled() && $this->_getHelper()->isEnabledForProductCollections() && !$this->_getHelper()->isInCart(false)) { if ($observer->getCollection() && count($observer->getCollection())) { foreach ($observer->getCollection() as $product) { $this->_getHelper()->assignDefaultProductData($product); } } } }
/** * @param Varien_Event_Observer $observer */ public function catalogProductCollectionApplyLimitationsBefore(Varien_Event_Observer $observer) { $filters = $observer->getCategoryId(); if (isset($filters['visibility']) && !Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')) { $storeId = Mage::app()->getStore()->getId(); $observer->getCollection(); $selectFrom = $observer->getCollection()->getSelect()->getPart(Zend_Db_Select::FROM); if (!isset($selectFrom['stock_status_index'])) { $observer->getCollection()->getSelect()->join(array('stock_status_index' => Mage::getSingleton('core/resource')->getTableName('demac_multilocationinventory/stock_status_index')), 'e.entity_id = stock_status_index.product_id' . ' AND stock_status_index.qty > 0' . ' AND stock_status_index.is_in_stock = 1' . ' AND stock_status_index.store_id = ' . $storeId, array()); } } }
/** * Attach children products after product list load * Observes: catalog_block_product_list_collection * * @param Varien_Event_Observer $observer */ public function productListCollectionLoadAfter(Varien_Event_Observer $observer) { if (!Mage::helper('configurableswatches')->isEnabled()) { // check if functionality disabled return; // exit without loading swatch functionality } /* @var $helper Mage_ConfigurableSwatches_Helper_Mediafallback */ $helper = Mage::helper('configurableswatches/mediafallback'); /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $collection = $observer->getCollection(); if ($collection instanceof Mage_ConfigurableSwatches_Model_Resource_Catalog_Product_Type_Configurable_Product_Collection) { // avoid recursion return; } $products = $collection->getItems(); $helper->attachChildrenProducts($products, $collection->getStoreId()); $helper->attachConfigurableProductChildrenAttributeMapping($products, $collection->getStoreId()); $helper->attachGallerySetToCollection($products, $collection->getStoreId()); /* @var $product Mage_Catalog_Model_Product */ foreach ($products as $product) { $helper->groupMediaGalleryImages($product); Mage::helper('configurableswatches/productimg')->indexProductImages($product, $product->getListSwatchAttrValues()); } }
public function onEavLoadBeforeProductFlag(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (get_class($collection) == "Mage_Catalog_Model_Resource_Product_Collection" or get_parent_class($collection) == "Mage_Catalog_Model_Resource_Product_Collection") { $collection->joinAttribute(Kontenta_CodesWholesale_Model_Product::CW_SYNC_PRICE, 'catalog_product/' . Kontenta_CodesWholesale_Model_Product::CW_SYNC_PRICE, 'entity_id', null, 'left'); $collection->joinAttribute(Kontenta_CodesWholesale_Model_Product::CW_SYNC_STOCK, 'catalog_product/' . Kontenta_CodesWholesale_Model_Product::CW_SYNC_STOCK, 'entity_id', null, 'left'); $collection->joinAttribute(Kontenta_CodesWholesale_Model_Product::KONTENTA_CW_PRODUCT_ID, 'catalog_product/' . Kontenta_CodesWholesale_Model_Product::KONTENTA_CW_PRODUCT_ID, 'entity_id', null, 'left'); } }
public function catalogBlockProductListCollection(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); foreach ($collection as $product) { $mark = new Aitoc_Aitunits_Model_Entity_Mark(); $mark->addHandler('Aitoc_Aitunits_Model_Observer_Block_Replacer_Catalogproductprice'); $mark->insertInObject($product); } }
/** * @param Varien_Event_Observer $observer */ public function addExtraColumnsToCollection(Varien_Event_Observer $observer) { // Get the collection $collection = $observer->getCollection(); if ($collection instanceof Mage_Reports_Model_Resource_Quote_Collection && Mage::registry('abandonedcart_report')) { // Add the extra fields // Using columns() instead of addFieldToSelect seems to fix the ambiguous column error $collection->getSelect()->columns(array('abandoned_notified' => 'main_table.abandoned_notified', 'abandoned_sale_notified' => 'main_table.abandoned_sale_notified')); } }
public function onEavLoadBefore(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } if (is_a($collection, 'Mage_Catalog_Model_Resource_Product_Collection')) { $collection->addAttributeToSelect('factfinder_updated'); } }
public function addFeaturedAttributeToSelect(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } if ($collection instanceof Mage_Catalog_Model_Resource_Product_Collection) { $collection->addAttributeToSelect('is_featured'); } }
public function catalogProductCollectionLoadBefore(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); $collection->getSelect()->joinLeft(array('_inventory_table' => $collection->getTable('cataloginventory/stock_item')), "_inventory_table.product_id = e.entity_id", array('is_in_stock', 'manage_stock')); $collection->addExpressionAttributeToSelect('on_top', '(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)', array()); $collection->getSelect()->order('on_top DESC'); // Make sure on_top is the first order directive $order = $collection->getSelect()->getPart('order'); array_unshift($order, array_pop($order)); $collection->getSelect()->setPart('order', $order); }
/** * If Freeshipping method is allowed, disallow all other shipping methods * * @param Varien_Event_Observer $observer * @return void * @event core_collection_abstract_load_after */ public function afterLoadCollection($observer) { $collection = $observer->getCollection(); if (!$collection instanceof Mage_Sales_Model_Resource_Quote_Address_Rate_Collection) { return; } if (!$this->_isFreeshippingIncluded($collection)) { return; } $shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress(); $shippingAddress->setLimitCarrier('freeshipping'); }
public function catalogProductCollectionLoadBefore(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); /** @var Mage_Catalog_Model_Category $category */ $category = Mage::registry('current_category'); /** @var Mage_Catalog_Block_Product_List $productListBlock */ $productListBlock = Mage::app()->getLayout()->getBlock('product_list'); if ($collection instanceof Mage_Catalog_Model_Resource_Product_Collection && $productListBlock && $category && $category->getIsLook()) { /** @var Mage_Catalog_Block_Product_List $categoryBlock */ $categoryBlock = Mage::app()->getLayout()->getBlock('product_list'); $categoryBlock->setTemplate('codekunst_looks/catalog/product/list.phtml'); $categoryBlock->getToolbarBlock()->setData('_current_limit', 'all'); } }
public function afterCollectionLoad(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } if ($collection instanceof Mage_Catalog_Model_Resource_Product_Collection) { if (Mage::helper('actions')->HideAddToCart()) { foreach ($collection as $product) { $product->setIsSalable(false); } } } }
public function beforeCollectionLoad(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } /** * Mage_Customer_Model_Resource_Customer_Collection */ if ($collection instanceof Mage_Customer_Model_Resource_Customer_Collection) { /* @var $collection Mage_Customer_Model_Resource_Customer_Collection */ $collection->addAttributeToSelect('points'); // Zend_Debug::dump( $collection->addAttributeToSelect('points')->getData());die(); } }
/** * Revert item order in loaded collection if flag is set. This is used to maintain the * descending order WITHIN the page, that Magento needs. * * @event core_collection_abstract_load_after * @area adminhtml * @param Varien_Event_Observer $observer * @throws Exception */ public function revertLoadedCollection(Varien_Event_Observer $observer) { if (!$this->_pager) { return $this; } /** @var Mage_Core_Model_Resource_Db_Collection_Abstract $collection */ $collection = $observer->getCollection(); if ($collection->getFlag(IntegerNet_AttributeOptionPager_Model_Pager::FLAG_REVERT_COLLECTION)) { $items = $collection->getItems(); foreach ($collection as $key => $item) { $collection->removeItemByKey($key); } foreach (array_reverse($items) as $item) { $collection->addItem($item); } } }
public function hideProducts(Varien_Event_Observer $observer) { if (Mage::getStoreConfig('amgroupcat/general/disable') || Mage::registry('amgroupcat_fetching_category')) { return false; } Mage::register('amgroupcat_fetching_category', true, true); $productIds = array(); $activeRules = Mage::helper('amgroupcat')->getActiveRules(array('remove_product_links = 1')); if ($activeRules) { foreach ($activeRules as $rule) { // get directly restricted products $currentRuleProductIds = Mage::getModel('amgroupcat/product')->getCollection()->addFieldToSelect('product_id')->addFieldToFilter('rule_id', $rule['rule_id'])->getData(); foreach ($currentRuleProductIds as $productId) { $productIds[] = $productId['product_id']; } // get all restricted products from restricted categories $catIds = array_merge(explode(',', trim($rule['categories'], ','))); if (!empty($catIds)) { foreach ($catIds as $catId) { if ($catId > 0) { $products = Mage::getModel('catalog/category')->load($catId)->getProductCollection()->addAttributeToSelect('*')->addAttributeToFilter('status', 1); // enabled foreach ($products as $product) { $productIds[] = $product->getId(); } } } } } // add products to collection filter if (!empty($productIds)) { $productIds = array_unique($productIds); $observer->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds)); } // delete trigger Mage::unregister('amgroupcat_fetching_category'); } return $this; }
/** * Récupération de la référence produit au chargement de la collection * @param Varien_Event_Observer $observer * @return type */ public function onEavLoadBefore(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } //Affichage des filtres "visibilité" et "statut" dans le listing des produits des catégories if (Mage::getStoreConfig('system/hhennes_productgridfilter/category_status_filter') == 1 && is_a($collection, 'Mage_Catalog_Model_Resource_Product_Collection') && Mage::app()->getRequest()->getControllerName() == 'catalog_category') { $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', Mage::app()->getRequest()->getParam('store')); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', Mage::app()->getRequest()->getParam('store')); } if (!Mage::getStoreConfig('system/hhennes_productgridfilter/attributes_to_display')) { return; } //Si la collection est une collection Mage_Catalog_Model_Resource_Product_Collection on ajoute les valeurs de ces champs à la collection if (is_a($collection, 'Mage_Catalog_Model_Resource_Product_Collection')) { $fields = explode(',', Mage::getStoreConfig('system/hhennes_productgridfilter/attributes_to_display')); foreach ($fields as $field) { $collection->addAttributeToSelect($field); } //Le champ reference peu être remplacé par l'attribut existant de votre choix } }
/** * Join columns to the Customers Collection. * @param Varien_Event_Observer $observer */ public function modifyCustomerCollection($observer) { $collection = $observer->getCollection(); if ($collection instanceof Mage_Customer_Model_Entity_Customer_Collection || $collection instanceof Mage_Customer_Model_Resource_Customer_Collection) { $attributesCollection = Mage::getModel('customer/attribute')->getCollection(); $alias = Mage::helper('amcustomerattr')->getProperAlias($attributesCollection->getSelect()->getPart('from'), 'eav_attribute'); $attributesCollection->getSelect()->where($alias . 'is_user_defined = ?', 1)->where($alias . 'attribute_code != ?', 'customer_activated'); $alias = Mage::helper('amcustomerattr')->getProperAlias($attributesCollection->getSelect()->getPart('from'), 'customer_eav_attribute'); $attributesCollection->getSelect()->where($alias . 'is_filterable_in_search = ?', 1); if ($attributesCollection->getSize() > 0) { foreach ($attributesCollection as $attribute) { $collection->addAttributeToSelect($attribute->getAttributeCode()); } } // add `activated` attribute to data selection $attributesCollectionFull = Mage::getModel('customer/attribute')->getCollection(); foreach ($attributesCollectionFull as $attribute) { $attrCode = $attribute->getAttributeCode(); if ($attrCode == 'am_is_activated') { $collection->addAttributeToSelect($attrCode); break; } } } }
public function updatePrescriptionCategoryListPrice(Varien_Event_Observer $observer) { $products = $observer->getCollection(); $noPay = Mage::getStoreConfig(self::NO_PAY); $pay = Mage::getStoreConfig(self::PAY); $private = Mage::getStoreConfig(self::PRI); $payMethod = Mage::getSingleton("core/session")->getPerscriptionCheck(); foreach ($products as $product) { if ($product->getData('is_prescription_product') == '1') { if ($payMethod === 'no_pay') { $exemption = Mage::getSingleton("core/session")->getPrescriptionExemptionCheck(); if ($exemption > 0) { $product->setFinalPrice($noPay); $product->setPrice($noPay); } } if ($payMethod === 'pay') { $product->setFinalPrice($pay); $product->setPrice($pay); } if ($payMethod === 'private') { $product->setFinalPrice($private); $product->setPrice($private); } } } }
function onEavCollectionLoad(Varien_Event_Observer $event) { $collection = $event->getCollection(); $sqlStruct = array(); $sqlStruct['sql'] = $collection->getSelectSql(true); $sqlStruct['type'] = 'eav'; $sqlStruct['class'] = get_class($collection); $this->collections[] = $sqlStruct; }
/** * Adds filter to collection which excludes all rules that can't be used in Email Remainder Rules * * @param Varien_Event_Observer $observer */ public function addSalesRuleFilter($observer) { $collection = $observer->getCollection(); $collection->addAllowedSalesRulesFilter(); }
/** * Add Seo suffix to product's URL if doesn't exists. * * @param Varien_Event_Observer $observer */ public function addSeoSuffixToProductUrl(Varien_Event_Observer $observer) { $seoSuffix = (string) Mage::app()->getStore()->getConfig(Mage_Catalog_Helper_Product::XML_PATH_PRODUCT_URL_SUFFIX); $this->_addSuffixToUrl($observer->getCollection()->getItems(), $seoSuffix); }
/** * Join columns to the Customers Collection. * * @param Varien_Event_Observer $observer */ public function modifyCustomerCollection($observer) { $collection = $observer->getCollection(); if ($collection instanceof Mage_Customer_Model_Entity_Customer_Collection || $collection instanceof Mage_Customer_Model_Resource_Customer_Collection) { $attributesCollection = Mage::getModel('customer/attribute')->getCollection(); $filters = array("is_user_defined = 1", "attribute_code != 'customer_activated' "); $attributesCollection = Mage::helper('amcustomerattr')->addFilters($attributesCollection, 'eav_attribute', $filters); $filters = array("is_filterable_in_search = 1"); $attributesCollection = Mage::helper('amcustomerattr')->addFilters($attributesCollection, 'customer_eav_attribute', $filters); if ($attributesCollection->getSize() > 0) { foreach ($attributesCollection as $attribute) { $collection->addAttributeToSelect($attribute->getAttributeCode()); } } // add `activated` attribute to data selection $attributesCollectionFull = Mage::getModel('customer/attribute')->getCollection(); foreach ($attributesCollectionFull as $attribute) { $attrCode = $attribute->getAttributeCode(); if ($attrCode == 'am_is_activated') { $collection->addAttributeToSelect($attrCode); break; } } } }
/** * Checks if the product can be added to the cart and if not, adds a dummy required * option in order to replace the add-to-cart button's url with the view-details url * * @param Varien_Event_Observer $oObserver */ public function catalogBlockProductListCollectionLoadAfter(Varien_Event_Observer $oObserver) { $oProductCollection = $oObserver->getCollection(); $oDummyOption = Mage::getModel('catalog/product_option'); foreach ($oProductCollection as $oProduct) { if ($this->oB2BHelper->isProductActive($oProduct) === false) { $oProduct->setRequiredOptions(array($oDummyOption)); } } return $oProductCollection; }
public function addLabelProductCollectionScript(Varien_Event_Observer $observer) { if (Mage::registry('amlabel_getting_product')) { return $this; } /* * register global flag to prevent grouped/configurable/bundle products * loading all child products caught by observer */ Mage::register('amlabel_getting_product', true); $productCollection = $observer->getCollection(); $blockClass = get_class($productCollection); $blockedClasses = array('Mage_Reports_Model_Resource_Product_Index_Viewed_Collection'); if (in_array($blockClass, $blockedClasses)) { return $this; } if ($productCollection) { foreach ($productCollection as $item) { $label = Mage::helper('amlabel')->getLabels($item, 'category', true); if ($label) { $this->addScript($item->getId(), addslashes($label)); } } } Mage::unregister('amlabel_getting_product'); return $this; }
public function addSelect(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); $collection->addAttributeToSelect('is_featured'); }
/** * Add the groupscatalog filter to the product collection count so the numbers * beside the categories in the sidebar navigation are correct. * * @param Varien_Event_Observer $observer * @return void */ public function catalogProductCollectionBeforeAddCountToCategories(Varien_Event_Observer $observer) { /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $collection = $observer->getCollection(); $helper = $this->_getHelper(); if ($helper->isModuleActive($collection->getStoreId()) && !$this->_isDisabledOnRequest()) { $customerGroupId = $helper->getCustomerGroupId(); $this->_getResource()->addGroupsCatalogFilterToProductCollectionCountSelect($collection, $customerGroupId); } }
public function beforeCollectionLoad(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); if (!isset($collection)) { return; } /** * Mage_Customer_Model_Resource_Customer_Collection */ if ($collection instanceof Mage_Customer_Model_Resource_Customer_Collection) { /* @var $collection Mage_Customer_Model_Resource_Customer_Collection */ $collection->addAttributeToSelect('business_descriptions_title'); $collection->addAttributeToSelect('furnizor_account_status'); $collection->addAttributeToSelect('furnizor_account_type'); } }
/** * Check deal_status when using product collection * * @param Varien_Event_Observer $observer observed object */ public function catalogBlockProductListCollection(Varien_Event_Observer $observer) { $observer->getCollection()->addAttributeToSelect('*'); }
public function catalogProductCollectionLoadBefore(Varien_Event_Observer $observer) { $collection = $observer->getCollection(); //echo $collection->getSelect(); }