/** * 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; }
/** * 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'); } }
/** * Return boolean determining if FPT/ Catalog Price settings is conflicting or not. * * @return boolean */ public function isDefaultStoreWithConflictingFptTaxConfigurationSettings() { $weeeTaxHelper = $this->_factory->getHelper('weee'); $defaultStoreId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; //check default store first return $weeeTaxHelper->validateCatalogPricesAndFptConfiguration($defaultStoreId); }
/** * 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); }
/** * 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; }
/** * 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); } } }
/** * Get category request path * * @param Mage_Catalog_Model_Category $category * @return string * @deprecated since 1.13.0.2 */ protected function _getCategoryRequestPath(Mage_Catalog_Model_Category $category) { /** * Initialize request_path value */ $category->getUrl(); /** @var $helper Enterprise_Catalog_Helper_Data */ $helper = $this->_factory->getHelper('enterprise_catalog'); return $helper->getCategoryRequestPath($category->getRequestPath(), $category->getStoreId()); }
/** * 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; }
/** * 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; }
/** * Prepare temporary data * * @param Mage_Core_Model_Website $website * @return Varien_Db_Select */ protected function _prepareTemporarySelect(Mage_Core_Model_Website $website) { /** @var $catalogFlatHelper Mage_Catalog_Helper_Product_Flat */ $catalogFlatHelper = $this->_factory->getHelper('catalog/product_flat'); /** @var $eavConfig Mage_Eav_Model_Config */ $eavConfig = $this->_factory->getSingleton('eav/config'); $priceAttribute = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'price'); $select = $this->_connection->select()->from(array('rp' => $this->_resource->getTable('catalogrule/rule_product')), array())->joinInner(array('r' => $this->_resource->getTable('catalogrule/rule')), 'r.rule_id = rp.rule_id', array())->where('rp.website_id = ?', $website->getId())->order(array('rp.product_id', 'rp.customer_group_id', 'rp.sort_order', 'rp.rule_product_id'))->joinLeft(array('pg' => $this->_resource->getTable('catalog/product_attribute_group_price')), 'pg.entity_id = rp.product_id AND pg.customer_group_id = rp.customer_group_id' . ' AND pg.website_id = rp.website_id', array())->joinLeft(array('pgd' => $this->_resource->getTable('catalog/product_attribute_group_price')), 'pgd.entity_id = rp.product_id AND pgd.customer_group_id = rp.customer_group_id' . ' AND pgd.website_id = 0', array()); $storeId = $website->getDefaultStore()->getId(); if ($catalogFlatHelper->isEnabled() && $storeId && $catalogFlatHelper->isBuilt($storeId)) { $select->joinInner(array('p' => $this->_resource->getTable('catalog/product_flat') . '_' . $storeId), 'p.entity_id = rp.product_id', array()); $priceColumn = $this->_connection->getIfNullSql($this->_connection->getIfNullSql('pg.value', 'pgd.value'), 'p.price'); } else { $select->joinInner(array('pd' => $this->_resource->getTable(array('catalog/product', $priceAttribute->getBackendType()))), 'pd.entity_id = rp.product_id AND pd.store_id = 0 AND pd.attribute_id = ' . $priceAttribute->getId(), array())->joinLeft(array('p' => $this->_resource->getTable(array('catalog/product', $priceAttribute->getBackendType()))), 'p.entity_id = rp.product_id AND p.store_id = ' . $storeId . ' AND p.attribute_id = pd.attribute_id', array()); $priceColumn = $this->_connection->getIfNullSql($this->_connection->getIfNullSql('pg.value', 'pgd.value'), $this->_connection->getIfNullSql('p.value', 'pd.value')); } $select->columns(array('grouped_id' => $this->_connection->getConcatSql(array('rp.product_id', 'rp.customer_group_id'), '-'), 'product_id' => 'rp.product_id', 'customer_group_id' => 'rp.customer_group_id', 'from_date' => 'r.from_date', 'to_date' => 'r.to_date', 'action_amount' => 'rp.action_amount', 'action_operator' => 'rp.action_operator', 'action_stop' => 'rp.action_stop', 'sort_order' => 'rp.sort_order', 'price' => $priceColumn, 'rule_product_id' => 'rp.rule_product_id', 'from_time' => 'rp.from_time', 'to_time' => 'rp.to_time')); return $select; }
/** * 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; }
/** * Retrieve regions data json * * @param int|null $storeId * @return array() */ public function getRegionJsonByStore($storeId = null) { Varien_Profiler::start('TEST: ' . __METHOD__); if (!$this->_regionJson) { $store = $this->_app->getStore($storeId); $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE' . (string) $store->getId(); if ($this->_app->useCache('config')) { $json = $this->_app->loadCache($cacheKey); } if (empty($json)) { $regions = $this->_getRegions($storeId); $helper = $this->_factory->getHelper('core'); $json = $helper->jsonEncode($regions); if ($this->_app->useCache('config')) { $this->_app->saveCache($json, $cacheKey, array('config')); } } $this->_regionJson = $json; } Varien_Profiler::stop('TEST: ' . __METHOD__); return $this->_regionJson; }
/** * Retrieves helper class based on its name * * @param string $name * @return Mage_Core_Helper_Abstract */ public function helper($name) { return $this->_factory->getHelper($name); }