/** * Retrieve client instance * * @param string $metadataTableName * @return Enterprise_Mview_Model_Client */ protected function _getClient($metadataTableName) { /** @var $client Enterprise_Mview_Model_Client */ $client = $this->_factory->getModel('enterprise_mview/client', array(array('factory' => $this->_factory))); $client->init($metadataTableName); return $client; }
/** * Save value * * @return Enterprise_UrlRewrite_Model_System_Config_Backend_MatcherPriority */ public function save() { if ($this->getOldValue() !== $this->getValue()) { $matchers = explode('-', $this->getValue()); $priority = 0; /** @var $configModel Mage_Core_Model_Config */ $configModel = $this->_factory->getSingleton('core/config'); foreach ($matchers as $matcher) { $priority += 10; $path = sprintf(Enterprise_UrlRewrite_Model_Url_Rewrite::REWRITE_MATCHERS_PRIORITY_PATH, $matcher); $configModel->saveConfig($path, $priority); } } return $this; }
/** * Get url by rewrite row * * @param array $rewriteRow * @param string $baseUrl * @param int $storeId * @return string * @throws Exception */ protected function _getUrlByRewriteRow($rewriteRow, $baseUrl, $storeId) { switch ($rewriteRow['entity_type']) { case Enterprise_Catalog_Model_Product::URL_REWRITE_ENTITY_TYPE: $url = $baseUrl . $this->_factory->getHelper('enterprise_catalog')->getProductRequestPath($rewriteRow['request_path'], $storeId, $rewriteRow['category_id']); break; case Enterprise_Catalog_Model_Category::URL_REWRITE_ENTITY_TYPE: $url = $baseUrl . $this->_factory->getHelper('enterprise_catalog')->getCategoryRequestPath($rewriteRow['request_path'], $storeId); break; default: throw new Exception('Unknown entity type ' . $rewriteRow['entity_type']); break; } return $url; }
/** * Retrieve product Ids * * @param Enterprise_TargetRule_Model_Index $object * @return array */ public function getProductIds($object) { $adapter = $this->_getReadAdapter(); $select = $adapter->select()->from($this->getMainTable(), 'customer_segment_id')->where('type_id = :type_id')->where('entity_id = :entity_id')->where('store_id = :store_id')->where('customer_group_id = :customer_group_id'); $rotationMode = $this->_factory->getHelper('enterprise_targetrule')->getRotationMode($object->getType()); $segmentsIds = array_merge(array(0), $this->_getSegmentsIdsFromCurrentCustomer()); $bind = array(':type_id' => $object->getType(), ':entity_id' => $object->getProduct()->getEntityId(), ':store_id' => $object->getStoreId(), ':customer_group_id' => $object->getCustomerGroupId()); $segmentsList = $adapter->fetchAll($select, $bind); $foundSegmentIndexes = array(); foreach ($segmentsList as $segment) { $foundSegmentIndexes[] = $segment['customer_segment_id']; } $productIds = array(); foreach ($segmentsIds as $segmentId) { if (in_array($segmentId, $foundSegmentIndexes)) { $productIds = array_merge($productIds, $this->getTypeIndex($object->getType())->loadProductIdsBySegmentId($object, $segmentId)); } else { $matchedProductIds = $this->_matchProductIdsBySegmentId($object, $segmentId); $productIds = array_merge($matchedProductIds, $productIds); $this->getTypeIndex($object->getType())->saveResultForCustomerSegments($object, $segmentId, $matchedProductIds); $this->saveFlag($object, $segmentId); } } $productIds = array_diff(array_unique($productIds), $object->getExcludeProductIds()); if ($rotationMode == Enterprise_TargetRule_Model_Rule::ROTATION_SHUFFLE) { shuffle($productIds); } return $productIds; }
/** * Try to login user in admin * * @param string $username * @param string $password * @param Mage_Core_Controller_Request_Http $request * @return Mage_Admin_Model_User|null */ public function login($username, $password, $request = null) { if (empty($username) || empty($password)) { return; } try { /** @var $user Mage_Admin_Model_User */ $user = $this->_factory->getModel('admin/user'); $user->login($username, $password); if ($user->getId()) { $this->renewSession(); if (Mage::getSingleton('adminhtml/url')->useSecretKey()) { Mage::getSingleton('adminhtml/url')->renewSecretUrls(); } $this->setIsFirstPageAfterLogin(true); $this->setUser($user); $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); $alternativeUrl = $this->_getRequestUri($request); $redirectUrl = $this->_urlPolicy->getRedirectUrl($user, $request, $alternativeUrl); if ($redirectUrl) { Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user)); $this->_response->clearHeaders()->setRedirect($redirectUrl)->sendHeadersAndExit(); } } else { Mage::throwException(Mage::helper('adminhtml')->__('Invalid User Name or Password.')); } } catch (Mage_Core_Exception $e) { Mage::dispatchEvent('admin_session_user_login_failed', array('user_name' => $username, 'exception' => $e)); if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $request->setParam('messageSent', true); } } return $user; }
/** * Exclude catalogsearch_fulltext indexer * * @deprecated since version 1.13.2 * @param Varien_Event_Observer $observer */ public function addExcludeProcess(Varien_Event_Observer $observer) { $helper = $this->_factory->getHelper('enterprise_catalogsearch'); if (!$helper->isFulltextOn()) { $observer->getEvent()->getCollection()->addExcludeProcessByCode('catalogsearch_fulltext'); } }
/** * Check if tax calculation type and price display settings are compatible * * invalid settings if * Tax Calculation Method Based On 'Total' or 'Row' * and at least one Display Settings has 'Including and Excluding Tax' value * * @param mixed $store * @return bool */ public function checkDisplaySettings($store) { if ($this->_factory->getHelper('tax')->getCalculationAgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { return true; } return !$this->displayCartWrappingBothPrices($store) && !$this->displayCartCardBothPrices($store) && !$this->displaySalesWrappingBothPrices($store) && !$this->displaySalesCardBothPrices($store); }
/** * ACL validation before html generation * * @return string */ protected function _toHtml() { if ($this->_factory->getSingleton('admin/session')->isAllowed('system/config/tax')) { return parent::_toHtml(); } return ''; }
/** * Prepare affected product */ protected function _prepareAffectedProduct() { /** @var $modelCondition Mage_Catalog_Model_Product_Condition */ $modelCondition = $this->_factory->getModel('catalog/product_condition'); $productCondition = $modelCondition->setTable($this->_resource->getTable('catalogrule/affected_product'))->setPkFieldName('product_id'); $this->_app->dispatchEvent('catalogrule_after_apply', array('product' => $this->_getProduct(), 'product_condition' => $productCondition)); $this->_connection->delete($this->_resource->getTable('catalogrule/affected_product')); }
/** * Inserts rule data into catalogrule/rule_product table * * @param Mage_CatalogRule_Model_Rule $rule * @param array $websiteIds * @param array $productIds */ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $websiteIds, array $productIds = array()) { /** @var $write Varien_Db_Adapter_Interface */ $write = $this->_getWriteAdapter(); $customerGroupIds = $rule->getCustomerGroupIds(); $fromTime = (int) strtotime($rule->getFromDate()); $toTime = (int) strtotime($rule->getToDate()); $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0; $sortOrder = (int) $rule->getSortOrder(); $actionOperator = $rule->getSimpleAction(); $actionAmount = (double) $rule->getDiscountAmount(); $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; $subActionAmount = (double) $rule->getSubDiscountAmount(); $actionStop = (int) $rule->getStopRulesProcessing(); /** @var $helper Mage_Catalog_Helper_Product_Flat */ $helper = $this->_factory->getHelper('catalog/product_flat'); if ($helper->isEnabled() && $helper->isBuiltAllStores()) { /** @var $store Mage_Core_Model_Store */ foreach ($this->_app->getStores(false) as $store) { if (in_array($store->getWebsiteId(), $websiteIds)) { /** @var $selectByStore Varien_Db_Select */ $selectByStore = $rule->getProductFlatSelect($store->getId())->joinLeft(array('cg' => $this->getTable('customer/customer_group')), $write->quoteInto('cg.customer_group_id IN (?)', $customerGroupIds), array('cg.customer_group_id'))->reset(Varien_Db_Select::COLUMNS)->columns(array(new Zend_Db_Expr($store->getWebsiteId()), 'cg.customer_group_id', 'p.entity_id', new Zend_Db_Expr($rule->getId()), new Zend_Db_Expr($fromTime), new Zend_Db_Expr($toTime), new Zend_Db_Expr("'" . $actionOperator . "'"), new Zend_Db_Expr($actionAmount), new Zend_Db_Expr($actionStop), new Zend_Db_Expr($sortOrder), new Zend_Db_Expr("'" . $subActionOperator . "'"), new Zend_Db_Expr($subActionAmount))); if (count($productIds) > 0) { $selectByStore->where('p.entity_id IN (?)', array_keys($productIds)); } $selects = $write->selectsByRange('entity_id', $selectByStore, self::RANGE_PRODUCT_STEP); foreach ($selects as $select) { $write->query($write->insertFromSelect($select, $this->getTable('catalogrule/rule_product'), array('website_id', 'customer_group_id', 'product_id', 'rule_id', 'from_time', 'to_time', 'action_operator', 'action_amount', 'action_stop', 'sort_order', 'sub_simple_action', 'sub_discount_amount'), Varien_Db_Adapter_Interface::INSERT_IGNORE)); } } } } else { if (count($productIds) == 0) { Varien_Profiler::start('__MATCH_PRODUCTS__'); $productIds = $rule->getMatchingProductIds(); Varien_Profiler::stop('__MATCH_PRODUCTS__'); } $rows = array(); foreach ($productIds as $productId => $validationByWebsite) { foreach ($websiteIds as $websiteId) { foreach ($customerGroupIds as $customerGroupId) { if (empty($validationByWebsite[$websiteId])) { continue; } $rows[] = array('rule_id' => $rule->getId(), 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount); if (count($rows) == 1000) { $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); $rows = array(); } } } } if (!empty($rows)) { $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); } } }
/** * Restore locale of the initial store * * @param string $initialLocaleCode * @param string $initialArea * * @return Mage_Core_Model_App_Emulation */ protected function _restoreInitialLocale($initialLocaleCode, $initialArea = Mage_Core_Model_App_Area::AREA_ADMINHTML) { $currentLocaleCode = $this->_app->getLocale()->getLocaleCode(); if ($currentLocaleCode != $initialLocaleCode) { $this->_app->getLocale()->setLocaleCode($initialLocaleCode); $this->_factory->getSingleton('core/translate')->setLocale($initialLocaleCode)->init($initialArea, true); } return $this; }
/** * Load url rewrite entity by request_path * * @param array $paths * @return Enterprise_UrlRewrite_Model_Url_Rewrite */ public function loadByRequestPath($paths) { $this->setId(null); $rewriteRows = $this->_getResource()->getRewrites($paths); $matchers = $this->_factory->getSingleton('enterprise_urlrewrite/system_config_source_matcherPriority')->getRewriteMatchers(); foreach ($matchers as $matcherIndex) { $matcher = $this->_factory->getSingleton($this->_factory->getConfig()->getNode(sprintf(self::REWRITE_MATCHERS_MODEL_PATH, $matcherIndex), 'default')); foreach ($rewriteRows as $row) { if ($matcher->match($row, $paths['request'])) { $this->setData($row); break 2; } } } $this->_afterLoad(); $this->setOrigData(); $this->_hasDataChanges = false; return $this; }
/** * Listener for before product delete event. Deletes product custom redirects. * Needed because of http://bugs.mysql.com/bug.php?id=11472 * @param Varien_Event_Observer $observer */ public function deleteProductCustomRedirects(Varien_Event_Observer $observer) { if ((string) $this->_app->getConfig()->getNode(Enterprise_UrlRewrite_Model_Index_Observer::XML_PATH_REDIRECT_URL_SUFFIX_UPDATE_ON_SAVE)) { return; } /** @var Mage_Catalog_Model_Product $product */ $product = $observer->getProduct(); /** @var Enterprise_UrlRewrite_Model_Resource_Redirect $redirects */ $redirects = $this->_factory->getResourceModel('enterprise_urlrewrite/redirect'); $redirects->deleteByProductIds(array($product->getId())); }
/** * Constructor * Arguments: * request - Zend_Controller_Request_Http * config - Mage_Core_Model_Config * factory - Mage_Core_Model_Factory * routers - array * * @param array $args */ public function __construct(array $args) { $this->_factory = !empty($args['factory']) ? $args['factory'] : Mage::getModel('core/factory'); $this->_app = !empty($args['app']) ? $args['app'] : Mage::app(); $this->_config = !empty($args['config']) ? $args['config'] : Mage::getConfig(); $this->_request = !empty($args['request']) ? $args['request'] : Mage::app()->getFrontController()->getRequest(); $this->_rewrite = !empty($args['rewrite']) ? $args['rewrite'] : $this->_factory->getModel('core/url_rewrite'); if (!empty($args['routers'])) { $this->_routers = $args['routers']; } }
/** * Get all FPTs * * @return array */ public function getAllWeee() { $allWeee = array(); $store = $this->getTotal()->getAddress()->getQuote()->getStore(); $helper = $this->_factory->getHelper('weee'); if (!$helper->includeInSubtotal($store)) { foreach ($this->getTotal()->getAddress()->getCachedItemsAll() as $item) { foreach ($helper->getApplied($item) as $tax) { $weeeDiscount = isset($tax['weee_discount']) ? $tax['weee_discount'] : 0; $title = $tax['title']; $amount = isset($tax['row_amount']) ? $tax['row_amount'] : 0; if (array_key_exists($title, $allWeee)) { $allWeee[$title] = $allWeee[$title] + $amount - $weeeDiscount; } else { $allWeee[$title] = $amount - $weeeDiscount; } } } } return $allWeee; }
protected function _reindex() { $factory = new Mage_Core_Model_Factory(); $processes = array(); $indexer = $factory->getSingleton($factory->getIndexClassAlias()); $collection = $indexer->getProcessesCollection(); foreach ($collection as $process) { if ($process->getIndexer()->isVisible() === false) { continue; } $processes[] = $process; } foreach ($processes as $process) { /* @var $process Mage_Index_Model_Process */ try { $this->_log("Reindexing " . $process->getIndexerCode()); $process->reindexEverything(); } catch (Exception $e) { Mage::logException($e); } } }
/** * Fetch rewrite matchers names sorted by priority * * @return mixed * * @throws Mage_Core_Exception */ public function getRewriteMatchers() { if (!empty($this->_matchersOrder)) { return $this->_matchersOrder; } $nodes = $this->_factory->getConfig()->getNode(Enterprise_UrlRewrite_Model_Url_Rewrite::REWRITE_MATCHERS_PATH); foreach ($nodes->children() as $node) { $priority = (int) $node->priority; if (isset($this->_matchersOrder[$priority])) { throw new Mage_Core_Exception($this->_factory->getHelper('enterprise_urlrewrite')->__('URL matcher "%s" has same priority as "%s".', $node->getName(), $this->_matchersOrder[$priority])); } $this->_matchersOrder[$priority] = $node->getName(); } ksort($this->_matchersOrder); return $this->_matchersOrder; }
/** * Retrieve product request path * * @param string $requestPath * @param int $storeId * @param int $categoryId * @return string */ public function getProductRequestPath($requestPath, $storeId, $categoryId = null) { if (empty($requestPath)) { return ''; } /** @var $helper Mage_Catalog_Helper_Product */ $helper = $this->_factory->getHelper('catalog/product'); $urlSuffix = $helper->getProductUrlSuffix($storeId); if ($urlSuffix) { $requestPath .= '.' . $urlSuffix; } if (!is_null($categoryId)) { /** @var $category Mage_Catalog_Model_Category */ $category = Mage::getModel('catalog/category')->load($categoryId)->setStoreId($storeId); $categoryUrlKey = $category->getRequestPath(); $requestPath = ltrim($categoryUrlKey . '/' . $requestPath, '/'); } return $requestPath; }
/** * Get Regions for specific Countries * @param string $storeId * @return array|null */ protected function _getRegions($storeId) { $countryIds = array(); $countryCollection = $this->getCountryCollection()->loadByStore($storeId); foreach ($countryCollection as $country) { $countryIds[] = $country->getCountryId(); } /** @var $regionModel Mage_Directory_Model_Region */ $regionModel = $this->_factory->getModel('directory/region'); /** @var $collection Mage_Directory_Model_Resource_Region_Collection */ $collection = $regionModel->getResourceCollection()->addCountryFilter($countryIds)->load(); $regions = array('config' => array('show_all_regions' => $this->getShowNonRequiredState(), 'regions_required' => $this->getCountriesWithStatesRequired())); foreach ($collection as $region) { if (!$region->getRegionId()) { continue; } $regions[$region->getCountryId()][$region->getRegionId()] = array('code' => $region->getCode(), 'name' => $this->__($region->getName())); } return $regions; }
/** * Execute category refresh action which refresh url_rewrite index * * @param Mage_Catalog_Model_Category $category */ protected function _executeCategoryRefreshRowAction(Mage_Catalog_Model_Category $category) { /** @var $client Enterprise_Mview_Model_Client */ $client = $this->_factory->getModel('enterprise_mview/client')->init('enterprise_url_rewrite_category'); $client->execute('enterprise_catalog/index_action_url_rewrite_category_refresh_row', array('category_id' => $category->getId())); }
/** * Retrieves helper class based on its name * * @param string $name * @return Mage_Core_Helper_Abstract */ public function helper($name) { return $this->_factory->getHelper($name); }
/** * Get config model * * @return Mage_Core_Model_Config_Data */ protected function _getConfig() { return $this->_factory->getModel('core/config_data'); }
/** * Apply rule to product * * @param int|Mage_Catalog_Model_Product $product * @param array|null $websiteIds * * @return void */ public function applyToProduct($product, $websiteIds = null) { if (is_numeric($product)) { $product = $this->_factory->getModel('catalog/product')->load($product); } if (is_null($websiteIds)) { $websiteIds = $this->getWebsiteIds(); } $this->getResource()->applyToProduct($this, $product, $websiteIds); $this->getResource()->applyAllRules($product); $this->_invalidateCache(); }
/** * Retrieve client instance * * @return Enterprise_Mview_Model_Client */ protected function _getClient() { return $this->_factory->getSingleton('enterprise_mview/client'); }