本文整理汇总了PHP中Varien_Event_Observer::getCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Event_Observer::getCollection方法的具体用法?PHP Varien_Event_Observer::getCollection怎么用?PHP Varien_Event_Observer::getCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Event_Observer
的用法示例。
在下文中一共展示了Varien_Event_Observer::getCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: eavCollectionAbstractLoadBefore
/**
* 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()]);
}
}
}
}
示例2: addDefaultDdqValuesToProductCollection
/**
* 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);
}
}
}
}
示例3: catalogProductCollectionApplyLimitationsBefore
/**
* @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());
}
}
}
示例4: productListCollectionLoadAfter
/**
* 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());
}
}
示例5: onEavLoadBeforeProductFlag
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');
}
}
示例6: catalogBlockProductListCollection
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);
}
}
示例7: addExtraColumnsToCollection
/**
* @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'));
}
}
示例8: onEavLoadBefore
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');
}
}
示例9: addFeaturedAttributeToSelect
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');
}
}
示例10: catalogProductCollectionLoadBefore
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);
}
示例11: afterLoadCollection
/**
* 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');
}
示例12: catalogProductCollectionLoadBefore
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');
}
}
示例13: afterCollectionLoad
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);
}
}
}
}
示例14: beforeCollectionLoad
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();
}
}
示例15: revertLoadedCollection
/**
* 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);
}
}
}