/** * Export subscriber per website. * @param Mage_Core_Model_Website $website * * @return int */ public function exportSubscribersPerWebsite(Mage_Core_Model_Website $website) { $updated = 0; $fileHelper = Mage::helper('ddg/file'); $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT); $subscribers = Mage::getModel('ddg_automation/contact')->getSubscribersToImport($website, $limit); if (count($subscribers)) { $subscribersFilename = strtolower($website->getCode() . '_subscribers_' . date('d_m_Y_Hi') . '.csv'); //get mapped storename $subscriberStorename = Mage::helper('ddg')->getMappedStoreName($website); //file headers $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array('Email', 'emailType', $subscriberStorename)); foreach ($subscribers as $subscriber) { try { $email = $subscriber->getEmail(); $subscriber->setSubscriberImported(1)->save(); $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email); $storeName = Mage::app()->getStore($subscriber->getStoreId())->getName(); // save data for subscribers $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array($email, 'Html', $storeName)); $updated++; } catch (Exception $e) { Mage::logException($e); } } Mage::helper('ddg')->log('Subscriber filename: ' . $subscribersFilename); //register in queue with importer Mage::getModel('ddg_automation/importer')->registerQueue(Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_SUBSCRIBERS, '', Dotdigitalgroup_Email_Model_Importer::MODE_BULK, $website->getId(), $subscribersFilename); } //add updated number for the website $this->_countSubscriber += $updated; return $updated; }
/** * 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; }
/** * filter $collection by the cutoff date. * @param string $cutoffDate * @param Mage_Core_Model_Website $website * @return Varien_Data_Collection_Db */ protected function _getCollection($cutoffDate, Mage_Core_Model_Website $website) { $collection = Mage::getResourceModel('catalog/product_collection'); $collection->addAttributeToSelect('entity_id'); if ($cutoffDate) { $collection->addFieldToFilter('updated_at', array('gteq' => $cutoffDate)); } $collection->addWebsiteFilter(array($website->getId())); return $collection; }
/** * @param Mage_Core_Model_Website $website * @return array */ protected function _getChangedStoresForWebsite($website) { $changedStores = array(); foreach ($website->getStores() as $store) { /** @var Mage_Core_Model_Store $store */ if ($this->_isValueChanged($store, $website)) { $changedStores[Mage::helper('scopehint')->__('Store View: %s', $this->_getFullStoreName($store))] = $this->_getReadableConfigValue($store); } } return $changedStores; }
/** * Initialize currently ran store * * @param string $scopeCode code of default scope (website/store_group/store code) * @param string $scopeType type of default scope (website/group/store) * @return unknown_type */ protected function _initCurrentStore($scopeCode, $scopeType) { Varien_Profiler::start('mage::app::init::stores'); $this->_initStores(); Varien_Profiler::stop('mage::app::init::stores'); if (empty($scopeCode) && !is_null($this->_website)) { $scopeCode = $this->_website->getCode(); $scopeType = 'website'; } switch ($scopeType) { case 'store': $this->_currentStore = $scopeCode; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($scopeCode); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($scopeCode); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($scopeType); $this->_checkGetStore($scopeType); } $this->_useSessionInUrl = $this->getStore()->getConfig(Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID); return $this; }
/** * Initialize currently ran store * * @param string $scopeCode code of default scope (website/store_group/store code) * @param string $scopeType type of default scope (website/group/store) * @return unknown_type */ protected function _initCurrentStore($scopeCode, $scopeType) { Varien_Profiler::start('mage::app::init::stores'); $this->_initStores(); Varien_Profiler::stop('mage::app::init::stores'); if (empty($scopeCode) && !is_null($this->_website)) { $scopeCode = $this->_website->getCode(); $scopeType = 'website'; } switch ($scopeType) { case 'store': $this->_currentStore = $scopeCode; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($scopeCode); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($scopeCode); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($scopeType); $this->_checkGetStore($scopeType); } return $this; }
private function _saveWebsiteConfigItems(array $configs, Mage_Core_Model_Website $website) { try { if (!$website->getId()) { throw new Exception($this->__('Website does not exist')); } if (!empty($configs)) { foreach ($configs as $config) { if (isset($config['encrypted']) && $config['encrypted'] == 1) { $config['value'] = Mage::helper('core')->encrypt($config['value']); } // Save config $this->_checkAndSaveConfig($config['path'], $config['value'], 'websites', $website->getId(), $website->getCode()); } } } catch (Exception $e) { $this->log($e->getMessage()); } }
/** * 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')))); } } }
/** * Process website info * * @param Mage_Core_Model_System_Store $storeModel * @param Mage_Core_Model_Website $website * @param string $section * @param string $curStore * @param string $curWebsite * @param array $options * @return array */ protected function _processWebsite(Mage_Core_Model_System_Store $storeModel, Mage_Core_Model_Website $website, $section, $curStore, $curWebsite, array $options) { $websiteShow = false; foreach ($storeModel->getGroupCollection() as $group) { if ($group->getWebsiteId() != $website->getId()) { continue; } $groupShow = false; foreach ($storeModel->getStoreCollection() as $store) { if ($store->getGroupId() != $group->getId()) { continue; } if (!$websiteShow) { $websiteShow = true; $options['website_' . $website->getCode()] = array('label' => $website->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode())), 'selected' => !$curStore && $curWebsite == $website->getCode(), 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;'); } if (!$groupShow) { $groupShow = true; $options['group_' . $group->getId() . '_open'] = array('is_group' => true, 'is_close' => false, 'label' => $group->getName(), 'style' => 'padding-left:32px;'); } $options['store_' . $store->getCode()] = array('label' => $store->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode(), 'store' => $store->getCode())), 'selected' => $curStore == $store->getCode(), 'style' => ''); } if ($groupShow) { $options['group_' . $group->getId() . '_close'] = array('is_group' => true, 'is_close' => true); } } return $options; }
/** * 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; }
/** * Method add website fieldset to the form. * @param Mage_Core_Model_Website $website */ private function _addWebsiteFieldset($website) { $prefixWeb = 'website-' . $website->getCode(); /* make fieldset */ $layoutFieldset = $this->form->addFieldset($prefixWeb . '_fieldset', array('legend' => $this->getMyHelper()->__($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' => $this->getMyHelper()->__('Enable website') . ':', 'options' => array(0 => $this->getMyHelper()->__('No'), 1 => $this->getMyHelper()->__('Yes')))); /* add field for base dir */ $layoutFieldset->addField($prefixWeb . '-base_dir', 'text', array('name' => $prefixWeb . '-base_dir', 'label' => $this->getMyHelper()->__('Base directory') . ':')); /* add field for server name */ $layoutFieldset->addField($prefixWeb . '-server_name', 'text', array('name' => $prefixWeb . '-server_name', 'label' => $this->getMyHelper()->__('Server name') . ':')); $layoutFieldset->addField($prefixWeb . '_dec1', 'html_element', array('label' => '<h4>' . $this->getMyHelper()->__('Enable/Disable Storeview') . '</h4>', 'code' => '<div style="height:10px;border-bottom:1px solid #808080"></div>')); /* 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(), 'options' => array(0 => $this->getMyHelper()->__('No'), 1 => $this->getMyHelper()->__('Yes')))); } } $layoutFieldset->addField($prefixWeb . '_dec2', 'html_element', array('label' => '<h4>' . $this->getMyHelper()->__('Htaccess settings') . '</h4>', 'code' => '<div style="height:10px;border-bottom:1px solid #808080"></div>')); /* get htaccess state and set color by it */ $htaccess = Mage::getModel('mturbo/htaccess')->setWebsiteCode($website->getCode()); $state = ''; $pathToHtaccess = $htaccess->getPathToBaseHtaccess(); $color = Mage::helper('mturbo/functions')->get_file_state($pathToHtaccess, $state, 'ew') ? 'green' : 'red'; $layoutFieldset->addField($prefixWeb . '_dec3', 'html_element', array('label' => $this->getMyHelper()->__('File .htaccess path'), 'code' => '<span>' . $pathToHtaccess . '</span>')); $edit = $htaccess->isEditedByMTurbo() ? 'yes' : 'no'; $layoutFieldset->addField($prefixWeb . '_dec5', 'html_element', array('label' => $this->getMyHelper()->__('Edited by MTurbo'), 'code' => '<span><b>' . $this->getMyHelper()->__($edit) . '</b></span>')); $layoutFieldset->addField($prefixWeb . '_dec4', 'html_element', array('label' => $this->getMyHelper()->__('File .htaccess state'), 'code' => '<span style="color:' . $color . '">' . $this->getMyHelper()->__($state) . '</span>')); /* button 'rebuild' show only if htaccess is ready */ if ($color == 'green') { $layoutFieldset->addField($prefixWeb . '_htaccess_button', 'widget_button', array('name' => $prefixWeb . '_htaccess_button', 'label' => $this->getMyHelper()->__('Rebuild .htaccess for this website'), 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/htaccessbuild', array('websitecode' => $website->getCode())) . "')")); } $layoutFieldset->addField($prefixWeb . '_urllist_button', 'widget_button', array('name' => $prefixWeb . '_urllist_button', 'label' => $this->getMyHelper()->__('Generate URL list for this website'), 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/generateurllist', array('websitecode' => $website->getCode())) . "')")); }
/** * Initialize application * * @param string|array $code * @param string $type * @param string $etcDir * @return Mage_Core_Model_App */ public function init($code, $type = null, $options = array()) { $this->setErrorHandler(self::DEFAULT_ERROR_HANDLER); date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE); if (is_string($options)) { $options = array('etc_dir' => $options); } if (VPROF) { Varien_Profiler::start('mage::app::init::config'); } $this->_config = AO::getConfig(); $this->_config->init($options); if (VPROF) { Varien_Profiler::stop('mage::app::init::config'); } if (AO::isInstalled($options)) { if (VPROF) { Varien_Profiler::start('mage::app::init::stores'); } $this->_initStores(); if (VPROF) { Varien_Profiler::stop('mage::app::init::stores'); } if (empty($code) && !is_null($this->_website)) { $code = $this->_website->getCode(); $type = 'website'; } switch ($type) { case 'store': $this->_currentStore = $code; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($code); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($code); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($type); $this->_checkGetStore($type); } $this->getRequest()->setPathInfo(); } $this->_initFrontController(); return $this; }
/** * Unset website by id from app cache * * @param null|bool|int|string|Mage_Core_Model_Website $id * @return void */ public function clearWebsiteCache($id = null) { if (is_null($id)) { $id = $this->getStore()->getWebsiteId(); } elseif ($id instanceof Mage_Core_Model_Website) { $id = $id->getId(); } elseif ($id === true) { $id = $this->_website->getId(); } if (!empty($this->_websites[$id])) { $website = $this->_websites[$id]; unset($this->_websites[$website->getWebsiteId()]); unset($this->_websites[$website->getCode()]); } }
/** * 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; } $storeId = $this->_website->getDefaultGroup()->getDefaultStore()->getId(); $storeCode = $this->_website->getDefaultGroup()->getDefaultStore()->getCode(); 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; } Mage::getDesign()->setStore($storeId); Mage::getDesign()->setArea('frontend'); $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); if ($this->_type == 'price') { $this->_getPriceBlock()->setStoreCode($storeCode); 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()->setStoreCode($storeCode); 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 { 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); 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 = Mage::getModel('core/store')->load($this->_customer->getStoreId()); $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); Mage::app()->getTranslator()->init('frontend', true); 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; }
/** * Return serialized list of accepted save cookie website * * @return string */ public function getAcceptedSaveCookiesWebsiteIds() { $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites(); $acceptedSaveCookiesWebsites[$this->_website->getId()] = 1; return json_encode($acceptedSaveCookiesWebsites); }
/** * 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; }
/** * Make sure website is set * * @throws Mage_Core_Exception */ protected function _ensureWebsite() { if (!$this->_website || !$this->_website->getCode()) { Mage::throwException(Mage::helper('enterprise_staging')->__('Website code is not defined.')); } }
/** * Set Website scope * * @param Mage_Core_Model_Website|int $website * @return Mage_Eav_Model_Resource_Attribute_Collection */ public function setWebsite($website) { $this->_website = Mage::app()->getWebsite($website); $this->addBindParam('scope_website_id', $this->_website->getId()); return $this; }
/** * update data fields * * @param $email * @param Mage_Core_Model_Website $website * @param $storeName */ public function updateDataFields($email, Mage_Core_Model_Website $website, $storeName) { $data = array(); if ($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)) { $data[] = array('Key' => $store_name, 'Value' => $storeName); } if ($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)) { $data[] = array('Key' => $website_name, 'Value' => $website->getName()); } if (!empty($data)) { //update data fields $client = $this->getWebsiteApiClient($website); $client->updateContactDatafieldsByEmail($email, $data); } }
/** * Remove old index data * * @param Mage_Core_Model_Website $website */ protected function _removeOldIndexData(Mage_Core_Model_Website $website) { $this->_connection->delete($this->_resource->getTable('catalogrule/rule_product_price'), array('website_id = ?' => $website->getId())); }
public function getGroupCollection(Mage_Core_Model_Website $website) { return $website->getGroups(); }
/** * Remove old index data * * @param Mage_Core_Model_Website $website */ protected function _removeOldIndexData(Mage_Core_Model_Website $website) { $this->_connection->query($this->_connection->deleteFromSelect($this->_connection->select()->from($this->_resource->getTable('catalogrule/rule_product_price'))->where('product_id IN (?)', $this->_productId)->where('website_id = ?', $website->getId()), $this->_resource->getTable('catalogrule/rule_product_price'))); }
public function testCollection() { $collection = $this->_model->getCollection()->joinGroupAndStore()->addIdFilter(1); $this->assertEquals(1, count($collection->getItems())); }
/** * Check if customer is related to segments and update customer-segment relations * * @param int|null|Mage_Customer_Model_Customer $customer * @param Mage_Core_Model_Website $website * @param Enterprise_CustomerSegment_Model_Resource_Segment_Collection $segments * @return Enterprise_CustomerSegment_Model_Customer */ protected function _processSegmentsValidation($customer, $website, $segments) { $websiteId = $website->getId(); if ($customer instanceof Mage_Customer_Model_Customer) { $customerId = $customer->getId(); } else { $customerId = $customer; } $matchedIds = array(); $notMatchedIds = array(); $useVisitorId = !$customer || !$customerId; foreach ($segments as $segment) { if ($useVisitorId) { // Skip segment if it cannot be applied to visitor if ($segment->getApplyTo() == Enterprise_CustomerSegment_Model_Segment::APPLY_TO_REGISTERED) { continue; } $segment->setVisitorId(Mage::getSingleton('log/visitor')->getId()); } else { // Skip segment if it cannot be applied to customer if ($segment->getApplyTo() == Enterprise_CustomerSegment_Model_Segment::APPLY_TO_VISITORS) { continue; } } $isMatched = $segment->validateCustomer($customer, $website); if ($isMatched) { $matchedIds[] = $segment->getId(); } else { $notMatchedIds[] = $segment->getId(); } } if ($customerId) { $this->addCustomerToWebsiteSegments($customerId, $websiteId, $matchedIds); $this->removeCustomerFromWebsiteSegments($customerId, $websiteId, $notMatchedIds); $segmentIds = $this->_customerWebsiteSegments[$websiteId][$customerId]; } else { $this->addVisitorToWebsiteSegments(Mage::getSingleton('customer/session'), $websiteId, $matchedIds); $this->removeVisitorFromWebsiteSegments(Mage::getSingleton('customer/session'), $websiteId, $notMatchedIds); $allSegments = Mage::getSingleton('customer/session')->getCustomerSegmentIds(); $segmentIds = $allSegments[$websiteId]; } Mage::dispatchEvent('enterprise_customersegment_ids_changed', array('segment_ids' => $segmentIds)); return $this; }
/** * Add stock status to prepare index select * * @param Varien_Db_Select $select * @param Mage_Core_Model_Website $website * @return Mage_CatalogInventory_Model_Resource_Stock_Status */ public function addStockStatusToSelect(Varien_Db_Select $select, Mage_Core_Model_Website $website) { $websiteId = $website->getId(); $select->joinLeft(array('stock_status' => $this->getMainTable()), 'e.entity_id = stock_status.product_id AND stock_status.website_id=' . $websiteId, array('salable' => 'stock_status.stock_status')); return $this; }
/** * 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; }
/** * Get resource location * * @param Mage_Core_Model_Website $website * @return string URL */ protected function _getLocation($website) { /* @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */ $apiTypeRoute = Mage::getModel('api2/route_apiType'); $chain = $apiTypeRoute->chain(new Zend_Controller_Router_Route($this->getConfig()->getRouteWithEntityTypeAction($this->getResourceType()))); $params = array('api_type' => $this->getRequest()->getApiType(), 'product_id' => $this->getRequest()->getParam('product_id'), 'website_id' => $website->getId()); $uri = $chain->assemble($params); return '/' . $uri; }
/** * Init Website Store Elements * * @param Varien_Data_Form $form * @param Mage_Core_Model_Website $masterWebsite * @param Mage_Core_Model_Website $stagingWebsite * @return Enterprise_Staging_Block_Manage_Staging_Edit_Tabs_Website */ protected function _initWebsiteStore($form, $masterWebsite, $stagingWebsite = null) { if (empty($masterWebsite)) { return $this; } if ($stagingWebsite) { $fieldset = $form->addFieldset('staging_website_stores', array('legend' => Mage::helper('enterprise_staging')->__('Store Views to Copy'))); } else { $fieldset = $form->addFieldset('staging_website_stores', array('legend' => Mage::helper('enterprise_staging')->__('Select Original Website Store Views to be Copied to Staging Website'))); } if ($stagingWebsite) { $_storeGroups = $stagingWebsite->getGroups(); $_storeGroupsCount = $stagingWebsite->getGroupsCount(); } else { $_storeGroups = $masterWebsite->getGroups(); $_storeGroupsCount = $masterWebsite->getGroupsCount(); } $noStores = true; foreach ($_storeGroups as $group) { if ($group->getStoresCount()) { $noStores = false; $_stores = $group->getStores(); $this->_initStoreGroup($fieldset, $group, $stagingWebsite); foreach ($_stores as $storeView) { $this->_initStoreView($fieldset, $storeView, $stagingWebsite); } } } if ($noStores) { if ($stagingWebsite) { $fieldset->addField('staging_no_stores', 'label', array('label' => Mage::helper('enterprise_staging')->__('There are no store views to be copied.'))); } else { $fieldset->addField('staging_no_stores', 'label', array('label' => Mage::helper('enterprise_staging')->__('There are no store views for copying.'))); } } return $this; }
/** * Validate is valid association for website unassignment from product. * If fails validation, then this method returns false, and * getErrors() will return an array of errors that explain why the * validation failed. * * @param Mage_Core_Model_Website $website * @param Mage_Catalog_Model_Product $product * @return bool */ public function isWebsiteAssignedToProduct(Mage_Core_Model_Website $website, Mage_Catalog_Model_Product $product) { if (false === array_search($website->getId(), $product->getWebsiteIds())) { $this->_addError(sprintf('Product #%d isn\'t assigned to website #%d', $product->getId(), $website->getId())); } return !count($this->getErrors()); }