Esempio n. 1
0
 public function testLoad()
 {
     /* Test loading by id */
     $this->assertEquals(1, $this->_model->getId());
     $this->assertEquals('base', $this->_model->getCode());
     $this->assertEquals('Main Website', $this->_model->getName());
     /* Test loading by code */
     $this->_model->load('admin');
     $this->assertEquals(0, $this->_model->getId());
     $this->assertEquals('admin', $this->_model->getCode());
     $this->assertEquals('Admin', $this->_model->getName());
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
 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());
     }
 }
 /**
  * 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;
 }
 /**
  *  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()]);
     }
 }
 /**
  * export quotes to website
  *
  * @param Mage_Core_Model_Website $website
  */
 protected function _exportQuoteForWebsite(Mage_Core_Model_Website $website)
 {
     try {
         //reset quotes
         $this->_quotes = array();
         $this->_quoteIds = array();
         $websiteId = $website->getId();
         $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
         $collection = $this->_getQuoteToImport($website, $limit);
         $ids = $collection->getColumnValues('quote_id');
         $quotes = Mage::getModel('sales/quote')->getCollection()->addFieldToFilter('entity_id', array('in' => $ids));
         foreach ($quotes as $quote) {
             $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
             $this->_quotes[$websiteId][] = $connectorQuote;
             $this->_quoteIds[] = $quote->getId();
             $this->_count++;
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Esempio n. 8
0
 /**
  * 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);
 }
Esempio n. 9
0
 /**
  * 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;
 }
 /**
  * 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()));
 }
Esempio n. 11
0
 /**
  * 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')));
 }
 /**
  * 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;
 }
Esempio n. 13
0
 /**
  * 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());
 }
Esempio n. 14
0
 /**
  * Process core config data
  *
  * @param Mage_Core_Model_Website   $stagingWebsite
  * @param string $originalBaseUrl
  * @param string $baseUrl
  * @param string $mode
  * @param Varien_Simplexml_Element  $xmlConfig
  */
 protected function _saveUrlsInSystemConfig($stagingWebsite, $originalBaseUrl, $baseUrl, $mode = 'unsecure', $xmlConfig)
 {
     foreach ($xmlConfig->children() as $nodeName => $nodeValue) {
         if ($mode == 'secure' || $mode == 'unsecure') {
             if ($nodeName == 'base_url' || $nodeName == 'base_web_url' || $nodeName == 'base_link_url') {
                 $nodeValue = $baseUrl;
             } elseif ($mode == 'unsecure') {
                 if (strpos($nodeValue, '{{unsecure_base_url}}') !== false) {
                     $nodeValue = str_replace('{{unsecure_base_url}}', $originalBaseUrl, $nodeValue);
                 }
             } elseif ($mode == 'secure') {
                 if (strpos($nodeValue, '{{secure_base_url}}') !== false) {
                     $nodeValue = str_replace('{{secure_base_url}}', $originalBaseUrl, $nodeValue);
                 }
             }
         }
         $config = Mage::getModel('core/config_data');
         $path = 'web/' . $mode . '/' . $nodeName;
         $config->setPath($path);
         $config->setScope('websites');
         $config->setScopeId($stagingWebsite->getId());
         $config->setValue($nodeValue);
         $config->save();
     }
     return $this;
 }
Esempio n. 15
0
 /**
  * @param array $sgConfig
  * @param Mage_Core_Model_Website $website
  * @return Mage_Core_Model_Store_Group
  */
 private function __addUpdateStoreGroup($sgConfig, $website)
 {
     // See if the store group exists otherwise create a store group
     $storeGroup = Mage::getModel('core/store_group')->load($sgConfig['name'], 'name');
     if ($storeGroup->getId()) {
         if ($storeGroup->getWebsiteId() != $website->getId() || $storeGroup->getRootCategoryId() != $sgConfig['root_category_id']) {
             $storeGroup->setWebsiteId($website->getId())->setRootCategoryId($sgConfig['root_category_id'])->save();
             $this->log("Updated store group " . $storeGroup->getName());
         }
     } else {
         $storeGroup = Mage::getModel('core/store_group');
         $storeGroup->setWebsiteId($website->getId())->setName($sgConfig['name'])->setRootCategoryId($sgConfig['root_category_id'])->save();
         $this->log("Created store group " . $storeGroup->getName());
     }
     return $storeGroup;
 }
Esempio n. 16
0
 /**
  * Retrieve salable product statuses
  *
  * @param int|array $products
  * @param Mage_Core_Model_Website $website
  * @return array
  */
 public function getProductsSalableStatus($products, Mage_Core_Model_Website $website)
 {
     $read = $this->_getReadAdapter();
     $productsData = array();
     $select = $read->select()->from(array('e' => $this->getTable('catalog/product')), 'entity_id')->where('e.entity_id IN(?)', $products);
     // add belong to website
     $select->joinLeft(array('pw' => $this->getTable('catalog/product_website')), 'e.entity_id=pw.product_id AND pw.website_id=:website_id', array('pw.website_id'));
     $store = $website->getDefaultStore();
     // add product status
     $status = $this->_getAttribute('status');
     if ($status->isScopeGlobal()) {
         $select->join(array('t_status' => $status->getBackend()->getTable()), 'e.entity_id=t_status.entity_id' . ' AND t_status.attribute_id=:status_attribute_id' . ' AND t_status.store_id=0', array('status' => 't_status.value'));
     } else {
         $statusField = $read->getCheckSql('t2_status.value_id > 0', 't2_status.value', 't1_status.value');
         $statusTable = $status->getBackend()->getTable();
         $select->join(array('t1_status' => $statusTable), 'e.entity_id=t1_status.entity_id' . ' AND t1_status.attribute_id=:status_attribute_id' . ' AND t1_status.store_id=0', array('status' => $statusField))->joinLeft(array('t2_status' => $statusTable), 't1_status.entity_id = t2_status.entity_id' . ' AND t1_status.attribute_id = t2_status.attribute_id' . ' AND t2_status.store_id=:store_id', array());
     }
     $bind = array('status_attribute_id' => $status->getAttributeId(), 'website_id' => $website->getId(), 'store_id' => $store->getId());
     Mage::dispatchEvent('catalog_product_prepare_index_select', array('website' => $website, 'select' => $select, 'bind' => $bind));
     $query = $read->query($select, $bind);
     while ($row = $query->fetch()) {
         $salable = isset($row['salable']) ? $row['salable'] : true;
         $website = $row['website_id'] > 0 ? true : false;
         $status = $row['status'];
         $productsData[$row['entity_id']] = $salable && $status && $website;
     }
     return $productsData;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }