/** * 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'); //magebrew: get Cost attribute $costAttribute = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'cost'); $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'); //magebrew: Cost column select for Flat catalog $costColumn = $this->_connection->getIfNullSql('p.cost', 0); } 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())->joinLeft(array('pc' => $this->_resource->getTable(array('catalog/product', $costAttribute->getBackendType()))), 'pc.entity_id = rp.product_id AND pc.store_id = 0 AND pc.attribute_id = ' . $costAttribute->getId(), array()); $priceColumn = $this->_connection->getIfNullSql($this->_connection->getIfNullSql('pg.value', 'pgd.value'), $this->_connection->getIfNullSql('p.value', 'pd.value')); //magebrew: Cost column select for Eav catalog $costColumn = $this->_connection->getIfNullSql('pc.value', 0); } $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, 'cost' => $costColumn, 'rule_product_id' => 'rp.rule_product_id', 'from_time' => 'rp.from_time', 'to_time' => 'rp.to_time')); return $select; }
/** * Send customer email * * @return bool */ public function send() { if (is_null($this->_website) || is_null($this->_customer)) { return false; } if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) { return false; } if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) { return false; } $store = $this->_website->getDefaultStore(); $storeId = $store->getId(); if ($this->_type == 'price' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId)) { return false; } elseif ($this->_type == 'stock' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId)) { return false; } // set design parameters, required for email (remember current) $currentDesign = Mage::getDesign()->setAllGetOld(array('store' => $storeId, 'area' => 'frontend', 'package' => Mage::getStoreConfig('design/package/name', $storeId))); Mage::app()->getLocale()->emulate($storeId); $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); if ($this->_type == 'price') { $this->_getPriceBlock()->setStore($store)->reset(); foreach ($this->_priceProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getPriceBlock()->addProduct($product); } $block = $this->_getPriceBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId); } elseif ($this->_type == 'stock') { $this->_getStockBlock()->setStore($store)->reset(); foreach ($this->_stockProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getStockBlock()->addProduct($product); } $block = $this->_getStockBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId); } else { Mage::app()->getLocale()->revert(); return false; } Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional($templateId, Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId), $this->_customer->getEmail(), $this->_customer->getName(), array('customerName' => $this->_customer->getName(), 'alertGrid' => $block)); $translate->setTranslateInline(true); // revert current design Mage::getDesign()->setAllGetOld($currentDesign); Mage::app()->getLocale()->revert(); return true; }
/** * Send customer email * * @return bool */ public function send() { if (is_null($this->_website) || is_null($this->_customer)) { return false; } if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) { return false; } if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) { return false; } $store = $this->_website->getDefaultStore(); $storeId = $store->getId(); if ($this->_type == 'price' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId)) { return false; } elseif ($this->_type == 'stock' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId)) { return false; } if ($this->_type != 'price' && $this->_type != 'stock') { return false; } $appEmulation = Mage::getSingleton('core/app_emulation'); $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); if ($this->_type == 'price') { $this->_getPriceBlock()->setStore($store)->reset(); foreach ($this->_priceProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getPriceBlock()->addProduct($product); } $block = $this->_getPriceBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId); } else { $this->_getStockBlock()->setStore($store)->reset(); foreach ($this->_stockProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getStockBlock()->addProduct($product); } $block = $this->_getStockBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId); } $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional($templateId, Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId), $this->_customer->getEmail(), $this->_customer->getName(), array('customerName' => $this->_customer->getName(), 'alertGrid' => $block)); return true; }
/** * Method add website fieldset to the form. * @param Mage_Core_Model_Website $website */ private function _addWebsiteFieldset($website, $form) { $prefixWeb = 'website-' . $website->getCode(); /* make fieldset */ $layoutFieldset = $form->addFieldset($prefixWeb . '_fieldset', array('legend' => Mage::helper('mturbo')->__($website->getName() . ' settings'), 'class' => 'fieldset')); /* add extra user control */ $layoutFieldset->addType('html_element', Artio_MTurbo_Helper_Data::FORM_HTML); $layoutFieldset->addType('widget_button', Artio_MTurbo_Helper_Data::FORM_WIDGET_BUTTON); /* indicator whether website is enabled */ $layoutFieldset->addField($prefixWeb . '-enabled', 'select', array('name' => $prefixWeb . '-enabled', 'label' => Mage::helper('mturbo')->__('Enable website') . ':', 'value' => '1', 'options' => array(0 => Mage::helper('mturbo')->__('No'), 1 => Mage::helper('mturbo')->__('Yes')))); /* add field for turbopath */ $layoutFieldset->addField($prefixWeb . '-base_dir', 'text', array('name' => $prefixWeb . '-base_dir', 'value' => Mage::getBaseDir(), 'label' => Mage::helper('mturbo')->__('Base directory') . ':')); /* add field for server name */ $layoutFieldset->addField($prefixWeb . '-server_name', 'text', array('name' => $prefixWeb . '-server_name', 'value' => Mage::helper('mturbo/website')->getServerName($website->getDefaultStore()->getCode()), 'label' => Mage::helper('mturbo')->__('Server name') . ':')); /* every store has one select determines whether enabled is */ foreach ($website->getStores() as $store) { if ($store->getIsActive()) { $layoutFieldset->addField($prefixWeb . '-store-' . $store->getCode(), 'select', array('name' => $prefixWeb . '-store-' . $store->getCode(), 'label' => $store->getGroup()->getName() . '<br />' . $store->getName(), 'value' => '1', 'options' => array(0 => Mage::helper('mturbo')->__('No'), 1 => Mage::helper('mturbo')->__('Yes')))); } } }
/** * Apply special price * * @param float $finalPrice * @param array $priceData * @param Mage_Core_Model_Website $website * @return float */ public function _calculateSpecialPrice($finalPrice, array $priceData, Mage_Core_Model_Website $website) { $store = $website->getDefaultStore(); $specialPrice = $priceData['special_price']; if (!is_null($specialPrice) && $specialPrice != false) { if (Mage::app()->getLocale()->isStoreDateInInterval($store, $priceData['special_from_date'], $priceData['special_to_date'])) { $specialPrice = $finalPrice * $specialPrice / 100; $finalPrice = min($finalPrice, $specialPrice); } } return $finalPrice; }
public function testGetDefaultStore() { $defaultStore = $this->_model->getDefaultStore(); $this->assertInstanceOf('Mage_Core_Model_Store', $defaultStore); $this->assertEquals(1, $defaultStore->getId()); }
/** * Walk Product Collection for Relation Parent products * * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Mage_Core_Model_Store|Mage_Core_Model_Website $store * @param array $attributes * @param array $prices * @return Mage_CatalogIndex_Model_Indexer */ public function _walkCollectionRelation($collection, $store, $attributes = array(), $prices = array()) { if ($store instanceof Mage_Core_Model_Website) { $storeObject = $store->getDefaultStore(); } elseif ($store instanceof Mage_Core_Model_Store) { $storeObject = $store; } $statusCond = array('in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()); $productCount = $collection->getSize(); $iterateCount = $productCount / self::STEP_SIZE; for ($i = 0; $i < $iterateCount; $i++) { $stepData = $collection->getAllIds(self::STEP_SIZE, $i * self::STEP_SIZE); foreach ($this->_getPriorifiedProductTypes() as $type) { $retriever = $this->getRetreiver($type); if (!$retriever->getTypeInstance()->isComposite()) { continue; } $parentIds = $retriever->getTypeInstance()->getParentIdsByChild($stepData); if ($parentIds) { $parentCollection = $this->_getProductCollection($storeObject, $parentIds); $parentCollection->addAttributeToFilter('status', $statusCond); $parentCollection->addFieldToFilter('type_id', $type); $this->_walkCollection($parentCollection, $storeObject, $attributes, $prices); $this->_afterPlainReindex($store, $parentIds); } } } return $this; }