public function getResource() { if (!$this->_resource) { $this->_resource = AO::getResourceSingleton('catalog_entity/convert'); } return $this->_resource; }
/** * Return queue collection with loaded neversent queues * * @return Mage_Newsletter_Model_Mysql4_Queue_Collection */ public function getQueueCollection() { if (is_null($this->_queueCollection)) { $this->_queueCollection = AO::getResourceSingleton('newsletter/queue_collection')->addTemplateInfo()->addOnlyUnsentFilter()->load(); } return $this->_queueCollection; }
public function joinCustomers() { $customer = AO::getResourceSingleton('customer/customer'); //TODO: add full name logic $firstnameAttr = $customer->getAttribute('firstname'); $firstnameAttrId = $firstnameAttr->getAttributeId(); $firstnameTable = $firstnameAttr->getBackend()->getTable(); if ($firstnameAttr->getBackend()->isStatic()) { $firstnameField = 'firstname'; $attrCondition = ''; } else { $firstnameField = 'value'; $attrCondition = ' AND _table_customer_firstname.attribute_id = ' . $firstnameAttrId; } $this->getSelect()->joinInner(array('_table_customer_firstname' => $firstnameTable), '_table_customer_firstname.entity_id=detail.customer_id' . $attrCondition, array()); $lastnameAttr = $customer->getAttribute('lastname'); $lastnameAttrId = $lastnameAttr->getAttributeId(); $lastnameTable = $lastnameAttr->getBackend()->getTable(); if ($lastnameAttr->getBackend()->isStatic()) { $lastnameField = 'lastname'; $attrCondition = ''; } else { $lastnameField = 'value'; $attrCondition = ' AND _table_customer_lastname.attribute_id = ' . $lastnameAttrId; } $this->getSelect()->joinInner(array('_table_customer_lastname' => $lastnameTable), '_table_customer_lastname.entity_id=detail.customer_id' . $attrCondition, array())->from("", array('customer_name' => "CONCAT(_table_customer_firstname.{$firstnameField}, ' ', _table_customer_lastname.{$lastnameField})", 'review_cnt' => "COUNT(main_table.review_id)"))->group('detail.customer_id'); return $this; }
/** * Add order items count expression * * @return Mage_Sales_Model_Mysql4_Order_Collection */ public function addItemCountExpr() { $orderTable = $this->getEntity()->getEntityTable(); $orderItemEntityTypeId = AO::getResourceSingleton('sales/order_item')->getTypeId(); $this->getSelect()->join(array('items' => $orderTable), 'items.parent_id=e.entity_id and items.entity_type_id=' . $orderItemEntityTypeId, array('items_count' => new Zend_Db_Expr('COUNT(items.entity_id)')))->group('e.entity_id'); return $this; }
public function getEntity() { if (!$this->_entityType) { if (!($entityType = $this->getVar('entity_type')) || !($entity = AO::getResourceSingleton($entityType)) instanceof Mage_Eav_Model_Entity_Interface) { $this->addException(AO::helper('eav')->__('Invalid entity specified'), Varien_Convert_Exception::FATAL); } $this->_entity = $entity; } return $this->_entity; }
/** * Prepare collection for grid * * @return Mage_Adminhtml_Block_Customer_Online_Grid */ protected function _prepareCollection() { $collection = AO::getResourceSingleton('log/visitor_collection')->useOnlineFilter(); $this->setCollection($collection); parent::_prepareCollection(); foreach ($this->getCollection()->getItems() as $item) { $item->addIpData($item)->addQuoteData($item); } return $this; }
/** * Check for email dublicates before saving customers sharing options * * @return Mage_Customer_Model_Config_Share * @throws Mage_Core_Exception */ public function _beforeSave() { $value = $this->getValue(); if ($value == self::SHARE_GLOBAL) { if (AO::getResourceSingleton('customer/customer')->findEmailDuplicates()) { AO::throwException(AO::helper('customer')->__('Can\'t share customer accounts global. Because some customer accounts with same emails exist on multiple websites and cannot be merged.')); } } return $this; }
/** * Prepare collection for grid * * @return Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { $collection = AO::getResourceSingleton('newsletter/subscriber_collection'); /* @var $collection Mage_Newsletter_Model_Mysql4_Subscriber_Collection */ $collection->showCustomerInfo(true)->addSubscriberTypeField()->showStoreInfo(); if ($this->getRequest()->getParam('queue', false)) { $collection->useQueue(AO::getModel('newsletter/queue')->load($this->getRequest()->getParam('queue'))); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * @return Mage_Catalog_Model_Mysql4_Convert */ public function getResource() { if (!$this->_resource) { $this->_resource = AO::getResourceSingleton('catalog_entity/convert'); #->loadStores() #->loadProducts() #->loadAttributeSets() #->loadAttributeOptions(); } return $this->_resource; }
/** * Conigure and start session * * @param string $sessionName * @return Mage_Core_Model_Session_Abstract_Varien */ public function start($sessionName = null) { if (isset($_SESSION)) { return $this; } if (VPROF) { Varien_Profiler::start(__METHOD__ . '/setOptions'); } if (is_writable(AO::getBaseDir('session'))) { session_save_path($this->getSessionSavePath()); } if (VPROF) { Varien_Profiler::stop(__METHOD__ . '/setOptions'); } switch ($this->getSessionSaveMethod()) { case 'db': ini_set('session.save_handler', 'user'); $sessionResource = AO::getResourceSingleton('core/session'); /* @var $sessionResource Mage_Core_Model_Mysql4_Session */ $sessionResource->setSaveHandler(); break; case 'memcache': ini_set('session.save_handler', 'memcache'); session_save_path($this->getSessionSavePath()); break; default: session_module_name('files'); break; } AO::dispatchEvent('core_session_before_set_cookie_params'); // set session cookie params session_set_cookie_params($this->getCookie()->getLifetime(), $this->getCookie()->getPath(), $this->getCookie()->getDomain(), $this->getCookie()->isSecure(), $this->getCookie()->getHttponly()); if (!empty($sessionName)) { session_name($sessionName); } // potential custom logic for session id (ex. switching between hosts) $this->setSessionId(); if (VPROF) { Varien_Profiler::start(__METHOD__ . '/start'); } if ($sessionCacheLimiter = AO::getConfig()->getNode('global/session_cache_limiter')) { session_cache_limiter((string) $sessionCacheLimiter); } session_start(); if (VPROF) { Varien_Profiler::stop(__METHOD__ . '/start'); } return $this; }
protected function _prepareData() { $product = AO::registry('product'); /* @var $product Mage_Catalog_Model_Product */ $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect('required_options')->addAttributeToSort('position', 'asc')->addStoreFilter(); AO::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, AO::getSingleton('checkout/session')->getQuoteId()); $this->_addProductAttributesAndPrices($this->_itemCollection); // AO::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); AO::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); $this->_itemCollection->load(); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }
/** * Load attribute options * * @return Mage_CatalogRule_Model_Rule_Condition_Product */ public function loadAttributeOptions() { $productAttributes = AO::getResourceSingleton('catalog/product')->loadAllAttributes()->getAttributesByCode(); $attributes = array(); foreach ($productAttributes as $attribute) { /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if (!$attribute->isAllowedForRuleCondition() || !$attribute->getIsUsedForPriceRules()) { continue; } $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel(); } $this->_addSpecialAttributes($attributes); asort($attributes); $this->setAttributeOption($attributes); return $this; }
protected function _initCollection() { $isFilter = $this->getParam('store') || $this->getParam('website') || $this->getParam('group'); $this->_collection = AO::getResourceSingleton('reports/order_collection')->prepareSummary($this->getParam('period'), 0, 0, $isFilter); if ($this->getParam('store')) { $this->_collection->addAttributeToFilter('store_id', $this->getParam('store')); } else { if ($this->getParam('website')) { $storeIds = AO::app()->getWebsite($this->getParam('website'))->getStoreIds(); $this->_collection->addAttributeToFilter('store_id', array('in' => implode(',', $storeIds))); } else { if ($this->getParam('group')) { $storeIds = AO::app()->getGroup($this->getParam('group'))->getStoreIds(); $this->_collection->addAttributeToFilter('store_id', array('in' => implode(',', $storeIds))); } } } $this->_collection->load(); }
public function __construct() { $this->_objectId = 'order_id'; $this->_controller = 'sales_order'; $this->_mode = 'view'; parent::__construct(); $this->_removeButton('delete'); $this->_removeButton('reset'); $this->_removeButton('save'); $this->setId('sales_order_view'); if ($this->_isAllowedAction('edit') && $this->getOrder()->canEdit()) { $onclickJs = 'deleteConfirm(\'' . AO::helper('sales')->__('Are you sure? This order will be cancelled and a new one will be created instead') . '\', \'' . $this->getEditUrl() . '\');'; $this->_addButton('order_edit', array('label' => AO::helper('sales')->__('Edit'), 'onclick' => $onclickJs)); // see if order has non-editable products as items $nonEditableTypes = array_keys(AO::getResourceSingleton('sales/order')->aggregateProductsByTypes($this->getOrder()->getId(), array_keys(AO::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()), false)); if ($nonEditableTypes) { $this->_updateButton('order_edit', 'onclick', 'if (!confirm(\'' . AO::helper('sales')->__('This order contains (%s) items and therefore cannot be edited through the admin interface at this time, if you wish to continue editing the (%s) items will be removed, the order will be cancelled and a new order will be placed', implode(', ', $nonEditableTypes), implode(', ', $nonEditableTypes)) . '\')) return false;' . $onclickJs); } } if ($this->_isAllowedAction('cancel') && $this->getOrder()->canCancel()) { $message = AO::helper('sales')->__('Are you sure you want to cancel this order?'); $this->_addButton('order_cancel', array('label' => AO::helper('sales')->__('Cancel'), 'onclick' => 'deleteConfirm(\'' . $message . '\', \'' . $this->getCancelUrl() . '\')')); } if ($this->_isAllowedAction('creditmemo') && $this->getOrder()->canCreditmemo()) { $this->_addButton('order_creditmemo', array('label' => AO::helper('sales')->__('Credit Memo'), 'onclick' => 'setLocation(\'' . $this->getCreditmemoUrl() . '\')')); } if ($this->_isAllowedAction('hold') && $this->getOrder()->canHold()) { $this->_addButton('order_hold', array('label' => AO::helper('sales')->__('Hold'), 'onclick' => 'setLocation(\'' . $this->getHoldUrl() . '\')')); } if ($this->_isAllowedAction('unhold') && $this->getOrder()->canUnhold()) { $this->_addButton('order_unhold', array('label' => AO::helper('sales')->__('Unhold'), 'onclick' => 'setLocation(\'' . $this->getUnholdUrl() . '\')')); } if ($this->_isAllowedAction('invoice') && $this->getOrder()->canInvoice()) { $this->_addButton('order_invoice', array('label' => AO::helper('sales')->__('Invoice'), 'onclick' => 'setLocation(\'' . $this->getInvoiceUrl() . '\')')); } if ($this->_isAllowedAction('ship') && $this->getOrder()->canShip()) { $this->_addButton('order_ship', array('label' => AO::helper('sales')->__('Ship'), 'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')')); } if ($this->_isAllowedAction('reorder') && $this->getOrder()->canReorder()) { $this->_addButton('order_reorder', array('label' => AO::helper('sales')->__('Reorder'), 'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')')); } }
/** * Retrieve item collection * * @return mixed */ public function getItemCollection() { $productCollection = $this->getData('item_collection'); if (is_null($productCollection)) { // get products to skip $skipProducts = array(); if ($collection = $this->getCreateOrderModel()->getCustomerCompareList()) { $collection = $collection->getItemCollection()->useProductItem(true)->setStoreId($this->getStoreId())->setCustomerId($this->getCustomerId())->load(); foreach ($collection as $_item) { $skipProducts[] = $_item->getProductId(); } } // prepare products collection and apply visitors log to it $productCollection = AO::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('small_image'); AO::getResourceSingleton('reports/event')->applyLogToCollection($productCollection, Mage_Reports_Model_Event::EVENT_PRODUCT_COMPARE, $this->getCustomerId(), 0, $skipProducts); $productCollection->load(); $this->setData('item_collection', $productCollection); } return $productCollection; }
/** * Get products collection and apply recent events log to it * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ protected function _getRecentProductsCollection() { // get products collection and apply status and visibility filter $collection = $this->_addProductAttributesAndPrices(AO::getModel('catalog/product')->getCollection())->addAttributeToSelect(AO::getSingleton('catalog/config')->getProductAttributes())->addUrlRewrite()->setPageSize($this->getPageSize())->setCurPage(1); AO::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); AO::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); // apply events log to collection with required parameters $skip = $this->_getProductsToSkip(); $subtype = 0; if (AO::getSingleton('customer/session')->isLoggedIn()) { $subjectId = AO::getSingleton('customer/session')->getCustomer()->getId(); } else { $subjectId = AO::getSingleton('log/visitor')->getId(); $subtype = 1; } AO::getResourceSingleton('reports/event')->applyLogToCollection($collection, $this->_eventTypeId, $subjectId, $subtype, $skip); foreach ($collection as $product) { $product->setDoNotUseCategoryId(true); } return $collection; }
protected function _prepareData() { $product = AO::registry('product'); /* @var $product Mage_Catalog_Model_Product */ $this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSort('position', 'asc')->addStoreFilter(); AO::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, AO::getSingleton('checkout/session')->getQuoteId()); $this->_addProductAttributesAndPrices($this->_itemCollection); // AO::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); AO::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); if ($this->getItemLimit('upsell') > 0) { $this->_itemCollection->setPageSize($this->getItemLimit('upsell')); } $this->_itemCollection->load(); /** * Updating collection with desired items */ AO::dispatchEvent('catalog_product_upsell', array('product' => $product, 'collection' => $this->_itemCollection, 'limit' => $this->getItemLimit())); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }
public function addCustomerData($filter = null) { $customerEntity = AO::getResourceSingleton('customer/customer'); $attrFirstname = $customerEntity->getAttribute('firstname'); $attrFirstnameId = $attrFirstname->getAttributeId(); $attrFirstnameTableName = $attrFirstname->getBackend()->getTable(); $attrLastname = $customerEntity->getAttribute('lastname'); $attrLastnameId = $attrLastname->getAttributeId(); $attrLastnameTableName = $attrLastname->getBackend()->getTable(); $attrEmail = $customerEntity->getAttribute('email'); $attrEmailTableName = $attrEmail->getBackend()->getTable(); $this->getSelect()->joinInner(array('cust_email' => $attrEmailTableName), 'cust_email.entity_id=main_table.customer_id', array('email' => 'cust_email.email'))->joinInner(array('cust_fname' => $attrFirstnameTableName), 'cust_fname.entity_id=main_table.customer_id and cust_fname.attribute_id=' . $attrFirstnameId, array('firstname' => 'cust_fname.value'))->joinInner(array('cust_lname' => $attrLastnameTableName), 'cust_lname.entity_id=main_table.customer_id and cust_lname.attribute_id=' . $attrLastnameId, array('lastname' => 'cust_lname.value', 'customer_name' => new Zend_Db_Expr('CONCAT(cust_fname.value, " ", cust_lname.value)'))); $this->_joinedFields['customer_name'] = 'CONCAT(cust_fname.value, " ", cust_lname.value)'; $this->_joinedFields['email'] = 'cust_email.email'; if ($filter) { if (isset($filter['customer_name'])) { $this->getSelect()->where($this->_joinedFields['customer_name'] . ' LIKE "%' . $filter['customer_name'] . '%"'); } if (isset($filter['email'])) { $this->getSelect()->where($this->_joinedFields['email'] . ' LIKE "%' . $filter['email'] . '%"'); } } return $this; }
public function refreshIndex($product) { /** * Ids of all categories where product is assigned (not related with store) */ $categoryIds = $product->getCategoryIds(); /** * Clear previos index data related with product */ $this->_getWriteAdapter()->delete($this->getTable('catalog/category_product_index'), $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId())); if (!empty($categoryIds)) { $categoriesSelect = $this->_getWriteAdapter()->select()->from($this->getTable('catalog/category'))->where('entity_id IN (?)', $categoryIds); $categoriesInfo = $this->_getWriteAdapter()->fetchAll($categoriesSelect); $indexCategoryIds = array(); foreach ($categoriesInfo as $categoryInfo) { $ids = explode('/', $categoryInfo['path']); $ids[] = $categoryInfo['entity_id']; $indexCategoryIds = array_merge($indexCategoryIds, $ids); } $indexCategoryIds = array_unique($indexCategoryIds); $indexProductIds = array($product->getId()); AO::getResourceSingleton('catalog/category')->refreshProductIndex($indexCategoryIds, $indexProductIds); } /** * Refresh enabled products index (visibility state) */ $this->refreshEnabledIndex(null, $product); return $this; }
/** * Get resource instance * * @return Mage_Core_Model_Mysql4_Abstract */ protected function _getResource() { if (empty($this->_resourceName)) { AO::throwException(AO::helper('core')->__('Resource is not set')); } return AO::getResourceSingleton($this->_resourceName); }
public function load() { if (!($entityType = $this->getVar('entity_type')) || !AO::getResourceSingleton($entityType) instanceof Mage_Eav_Model_Entity_Interface) { $this->addException(AO::helper('eav')->__('Invalid entity specified'), Varien_Convert_Exception::FATAL); } try { $collection = $this->_getCollectionForLoad($entityType); if (isset($this->_joinAttr) && is_array($this->_joinAttr)) { foreach ($this->_joinAttr as $val) { // print_r($val); $collection->joinAttribute($val['alias'], $val['attribute'], $val['bind'], null, strtolower($val['joinType']), $val['storeId']); } } $filterQuery = $this->getFilter(); if (is_array($filterQuery)) { foreach ($filterQuery as $val) { $collection->addFieldToFilter(array($val)); } } $joinFields = $this->_joinField; if (isset($joinFields) && is_array($joinFields)) { foreach ($joinFields as $field) { // print_r($field); $collection->joinField($field['alias'], $field['attribute'], $field['field'], $field['bind'], $field['cond'], $field['joinType']); } } /** * Load collection ids */ $entityIds = $collection->getAllIds(); $message = AO::helper('eav')->__("Loaded %d records", count($entityIds)); $this->addException($message); } catch (Varien_Convert_Exception $e) { throw $e; } catch (Exception $e) { $message = AO::helper('eav')->__('Problem loading the collection, aborting. Error: %s', $e->getMessage()); $this->addException($message, Varien_Convert_Exception::FATAL); } /** * Set collection ids */ $this->setData($entityIds); return $this; }
/** * Return true if catalog category flat data rebuilt * * @return boolean */ public function isRebuilt() { return AO::getResourceSingleton('catalog/category_flat')->isRebuilt(); }
/** * Order summary info for each customer * such as orders_count, orders_avg_amount, orders_total_amount */ public function addSumAvgTotals($storeId = 0) { /** * Join subtotal attribute */ $order = AO::getResourceSingleton('sales/order'); /* @var $order Mage_Sales_Model_Entity_Order */ if ($storeId == 0) { /** * Join store_to_base_rate attribute */ $attr = $order->getAttribute('base_to_global_rate'); /* @var $attr Mage_Eav_Model_Entity_Attribute_Abstract */ $attrId = $attr->getAttributeId(); $baseToGlobalRateTableName = $attr->getBackend()->getTable(); $baseToGlobalRateFieldName = $attr->getBackend()->isStatic() ? 'base_to_global_rate' : 'value'; $this->getSelect()->joinLeft(array('_b2gr_' . $baseToGlobalRateTableName => $baseToGlobalRateTableName), "_b2gr_{$baseToGlobalRateTableName}.entity_id={$this->_customerIdTableName}.entity_id AND " . "_b2gr_{$baseToGlobalRateTableName}.attribute_id={$attrId}", array()); /** * calculate average and total amount */ $expr = "({$this->_customerIdTableName}.base_subtotal-IFNULL({$this->_customerIdTableName}.base_subtotal_canceled,0)-IFNULL({$this->_customerIdTableName}.base_subtotal_refunded,0))*_b2gr_{$baseToGlobalRateTableName}.{$baseToGlobalRateFieldName}"; } else { /** * calculate average and total amount */ $expr = "{$this->_customerIdTableName}.base_subtotal-IFNULL({$this->_customerIdTableName}.base_subtotal_canceled,0)-IFNULL({$this->_customerIdTableName}.base_subtotal_refunded,0)"; } $this->getSelect()->from('', array("orders_avg_amount" => "AVG({$expr})"))->from('', array("orders_sum_amount" => "SUM({$expr})")); return $this; }
/** * Save category products * * @param Mage_Catalog_Model_Category $category * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category */ protected function _saveCategoryProducts($category) { $category->setIsChangedProductList(false); /** * new category-product relationships */ $products = $category->getPostedProducts(); if (is_null($products)) { return $this; } $catId = $category->getId(); $prodTable = $this->getTable('catalog/product'); /** * old category-product relationships */ $oldProducts = $category->getProductsPosition(); $insert = array_diff_key($products, $oldProducts); $delete = array_diff_key($oldProducts, $products); /** * Find product ids which are presented in both arrays */ $update = array_intersect_key($products, $oldProducts); /** * Use for update just products with changed position */ $update = array_diff_assoc($update, $oldProducts); $write = $this->getWriteConnection(); $updateProducts = array(); if (!empty($delete)) { $deleteIds = array_keys($delete); $write->delete($this->_categoryProductTable, $write->quoteInto('product_id in(?)', $deleteIds) . $write->quoteInto(' AND category_id=?', $catId)); /** * Delete association rewrites */ AO::getResourceSingleton('catalog/url')->deleteCategoryProductRewrites($catId, $deleteIds); $select = $write->select()->from($prodTable, array('entity_id', 'category_ids'))->where('entity_id IN (?)', $deleteIds); $prods = $write->fetchPairs($select); foreach ($prods as $k => $v) { $a = !empty($v) ? explode(',', $v) : array(); $key = array_search($catId, $a); if ($key !== false) { unset($a[$key]); } $updateProducts[$k] = "when " . (int) $k . " then '" . implode(',', array_unique($a)) . "'"; } } if (!empty($insert)) { $insertSql = array(); foreach ($insert as $k => $v) { $insertSql[] = '(' . (int) $catId . ',' . (int) $k . ',' . (int) $v . ')'; } $write->query("insert into {$this->_categoryProductTable}\n (category_id, product_id, position) values " . join(',', $insertSql)); $select = $write->select()->from($prodTable, array('entity_id', 'category_ids'))->where('entity_id IN (?)', array_keys($insert)); $prods = $write->fetchPairs($select); foreach ($prods as $k => $v) { $a = !empty($v) ? explode(',', $v) : array(); $a[] = (int) $catId; $updateProducts[$k] = "when " . (int) $k . " then '" . implode(',', array_unique($a)) . "'"; } } if (!empty($updateProducts)) { $write->update($prodTable, array('category_ids' => new Zend_Db_Expr('case entity_id ' . join(' ', $updateProducts) . ' end')), $write->quoteInto('entity_id in (?)', array_keys($updateProducts))); } if (!empty($update)) { $updateProductsPosition = array(); foreach ($update as $k => $v) { if ($v != $oldProducts[$k]) { $updateProductsPosition[$k] = 'when ' . (int) $k . ' then ' . (int) $v; } } if (!empty($updateProductsPosition)) { $write->update($this->_categoryProductTable, array('position' => new Zend_Db_Expr('case product_id ' . join(' ', $updateProductsPosition) . ' end')), $write->quoteInto('product_id in (?)', array_keys($updateProductsPosition)) . ' and ' . $write->quoteInto('category_id=?', $catId)); } } if (!empty($insert) || !empty($update) || !empty($delete)) { $category->setIsChangedProductList(true); $categoryIds = explode('/', $category->getPath()); $this->refreshProductIndex($categoryIds); } return $this; }
/** * Retrieve parent ids array by requered child * * @param int $childId * @return array */ public function getParentIdsByChild($childId) { return AO::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($childId); }
/** * Check exists customer (light check) * * @param int $customerId * @return bool */ public function checkCustomerId($customerId) { return AO::getResourceSingleton('customer/customer')->checkCustomerId($customerId); }
protected function _prepareCollection() { $collection = AO::getResourceSingleton('newsletter/template_collection')->useOnlyActual(); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Get catalog product resource model * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product */ protected function _getProductResource() { return AO::getResourceSingleton('catalog/product'); }
protected function _prepareCollection() { $collection = AO::getResourceSingleton('core/email_template_collection'); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * When applying a catalog price rule, make related quotes recollect on demand * * @param object $observer */ public function markQuotesRecollectOnCatalogRules($observer) { AO::getResourceSingleton('sales/quote')->markQuotesRecollectOnCatalogRules(); }