当前位置: 首页>>代码示例>>PHP>>正文


PHP StoreManagerInterface::getWebsites方法代码示例

本文整理汇总了PHP中Magento\Framework\StoreManagerInterface::getWebsites方法的典型用法代码示例。如果您正苦于以下问题:PHP StoreManagerInterface::getWebsites方法的具体用法?PHP StoreManagerInterface::getWebsites怎么用?PHP StoreManagerInterface::getWebsites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\StoreManagerInterface的用法示例。


在下文中一共展示了StoreManagerInterface::getWebsites方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dispatch

 /**
  * Set new customer group to all his quotes
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function dispatch(\Magento\Framework\Event\Observer $observer)
 {
     /** @var CustomerData $customerDataObject */
     $customerDataObject = $observer->getEvent()->getCustomerDataObject();
     /** @var CustomerData $origCustomerDataObject */
     $origCustomerDataObject = $observer->getEvent()->getOrigCustomerDataObject();
     if ($customerDataObject->getGroupId() !== $origCustomerDataObject->getGroupId()) {
         /**
          * It is needed to process customer's quotes for all websites
          * if customer accounts are shared between all of them
          */
         /** @var $websites \Magento\Store\Model\Website[] */
         $websites = $this->_config->isWebsiteScope() ? array($this->_storeManager->getWebsite($customerDataObject->getWebsiteId())) : $this->_storeManager->getWebsites();
         foreach ($websites as $website) {
             $quote = $this->_quoteFactory->create();
             $quote->setWebsite($website);
             $quote->loadByCustomer($customerDataObject->getId());
             if ($quote->getId()) {
                 $quote->setCustomerGroupId($customerDataObject->getGroupId());
                 $quote->collectTotals();
                 $quote->save();
             }
         }
     }
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:31,代码来源:CustomerQuote.php

示例2: toOptionArray

 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $this->_options = array();
         foreach ($this->_storeManager->getWebsites() as $website) {
             $id = $website->getId();
             $name = $website->getName();
             if ($id != 0) {
                 $this->_options[] = array('value' => $id, 'label' => $name);
             }
         }
     }
     return $this->_options;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:17,代码来源:Website.php

示例3: _initWebsites

 /**
  * Initialize website values
  *
  * @param bool $withDefault
  * @return $this
  */
 protected function _initWebsites($withDefault = false)
 {
     /** @var $website \Magento\Store\Model\Website */
     foreach ($this->_storeManager->getWebsites($withDefault) as $website) {
         $this->_websiteCodeToId[$website->getCode()] = $website->getId();
     }
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:14,代码来源:AbstractEav.php

示例4: getWebsiteOptionHash

 /**
  * Get websites as id => name associative array
  *
  * @param bool $withDefault
  * @param string $attribute
  * @return array
  */
 public function getWebsiteOptionHash($withDefault = false, $attribute = 'name')
 {
     $options = array();
     foreach ($this->_storeManager->getWebsites((bool) $withDefault && $this->_isAdminScopeAllowed) as $website) {
         $options[$website->getId()] = $website->getDataUsingMethod($attribute);
     }
     return $options;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:15,代码来源:Store.php

示例5: _getWebsites

 /**
  * Retrieve website collection array
  *
  * @return array
  */
 protected function _getWebsites()
 {
     if (is_null($this->_websites)) {
         try {
             $this->_websites = $this->_storeManager->getWebsites();
         } catch (\Exception $e) {
             $this->_errors[] = $e->getMessage();
         }
     }
     return $this->_websites;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:16,代码来源:Observer.php

示例6: getSharedWebsiteIds

 /**
  * Returns shared website Ids.
  *
  * @param int $websiteId the ID to use if website scope is on
  * @return int[]
  */
 public function getSharedWebsiteIds($websiteId)
 {
     $ids = array();
     if ($this->isWebsiteScope()) {
         $ids[] = $websiteId;
     } else {
         foreach ($this->_storeManager->getWebsites() as $website) {
             $ids[] = $website->getId();
         }
     }
     return $ids;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:18,代码来源:Share.php

示例7: _checkSingleStoreMode

 /**
  * Set correct scope if isSingleStoreMode = true
  *
  * @param \Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig
  * @param \Magento\Framework\App\Config\ValueInterface $dataObject
  * @return void
  */
 protected function _checkSingleStoreMode(\Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig, $dataObject)
 {
     $isSingleStoreMode = $this->_storeManager->isSingleStoreMode();
     if (!$isSingleStoreMode) {
         return;
     }
     if (!$fieldConfig->showInDefault()) {
         $websites = $this->_storeManager->getWebsites();
         $singleStoreWebsite = array_shift($websites);
         $dataObject->setScope('websites');
         $dataObject->setWebsiteCode($singleStoreWebsite->getCode());
         $dataObject->setScopeCode($singleStoreWebsite->getCode());
         $dataObject->setScopeId($singleStoreWebsite->getId());
     }
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:22,代码来源:Config.php

示例8: _getWebsitesMap

 /**
  * Prepare website map
  *
  * @return array
  */
 protected function _getWebsitesMap()
 {
     $map = array();
     $websites = $this->_storeManager->getWebsites(true);
     foreach ($websites as $website) {
         $map[$website->getId()] = $website->getDefaultStore()->getId();
     }
     return $map;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:14,代码来源:Rule.php

示例9: _getStoreByWebsite

 /**
  * @param \Magento\Framework\StoreManagerInterface $storage
  * @param string $scopeCode
  * @return null|string
  */
 protected function _getStoreByWebsite(\Magento\Framework\StoreManagerInterface $storage, $scopeCode)
 {
     $websites = $storage->getWebsites(true, true);
     if (!isset($websites[$scopeCode])) {
         return null;
     }
     if (!$websites[$scopeCode]->getDefaultGroupId()) {
         return null;
     }
     return $this->_getStoreByGroup($storage, $websites[$scopeCode]->getDefaultGroupId());
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:16,代码来源:StorageFactory.php

示例10: applyAllRulesForDateRange

 /**
  * Generate catalog price rules prices for specified date range
  * If from date is not defined - will be used previous day by UTC
  * If to date is not defined - will be used next day by UTC
  *
  * @param int|string|null $fromDate
  * @param int|string|null $toDate
  * @param int $productId
  * @return $this
  * @throws \Exception
  */
 public function applyAllRulesForDateRange($fromDate = null, $toDate = null, $productId = null)
 {
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $this->_eventManager->dispatch('catalogrule_before_apply', array('resource' => $this));
     $clearOldData = false;
     if ($fromDate === null) {
         $fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
         /**
          * If fromDate not specified we can delete all data oldest than 1 day
          * We have run it for clear table in case when cron was not installed
          * and old data exist in table
          */
         $clearOldData = true;
     }
     if (is_string($fromDate)) {
         $fromDate = strtotime($fromDate);
     }
     if ($toDate === null) {
         $toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
     }
     if (is_string($toDate)) {
         $toDate = strtotime($toDate);
     }
     $product = null;
     if ($productId instanceof Product) {
         $product = $productId;
         $productId = $productId->getId();
     }
     $this->removeCatalogPricesForDateRange($fromDate, $toDate, $productId);
     if ($clearOldData) {
         $this->deleteOldData($fromDate, $productId);
     }
     $dayPrices = array();
     try {
         /**
          * Update products rules prices per each website separately
          * because of max join limit in mysql
          */
         foreach ($this->_storeManager->getWebsites(false) as $website) {
             $productsStmt = $this->_getRuleProductsStmt($fromDate, $toDate, $productId, $website->getId());
             $dayPrices = array();
             $stopFlags = array();
             $prevKey = null;
             while ($ruleData = $productsStmt->fetch()) {
                 $ruleProductId = $ruleData['product_id'];
                 $productKey = $ruleProductId . '_' . $ruleData['website_id'] . '_' . $ruleData['customer_group_id'];
                 if ($prevKey && $prevKey != $productKey) {
                     $stopFlags = array();
                 }
                 /**
                  * Build prices for each day
                  */
                 for ($time = $fromDate; $time <= $toDate; $time += self::SECONDS_IN_DAY) {
                     if (($ruleData['from_time'] == 0 || $time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 || $time <= $ruleData['to_time'])) {
                         $priceKey = $time . '_' . $productKey;
                         if (isset($stopFlags[$priceKey])) {
                             continue;
                         }
                         if (!isset($dayPrices[$priceKey])) {
                             $dayPrices[$priceKey] = array('rule_date' => $time, 'website_id' => $ruleData['website_id'], 'customer_group_id' => $ruleData['customer_group_id'], 'product_id' => $ruleProductId, 'rule_price' => $this->_calcRuleProductPrice($ruleData), 'latest_start_date' => $ruleData['from_time'], 'earliest_end_date' => $ruleData['to_time']);
                         } else {
                             $dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice($ruleData, $dayPrices[$priceKey]);
                             $dayPrices[$priceKey]['latest_start_date'] = max($dayPrices[$priceKey]['latest_start_date'], $ruleData['from_time']);
                             $dayPrices[$priceKey]['earliest_end_date'] = min($dayPrices[$priceKey]['earliest_end_date'], $ruleData['to_time']);
                         }
                         if ($ruleData['action_stop']) {
                             $stopFlags[$priceKey] = true;
                         }
                     }
                 }
                 $prevKey = $productKey;
                 if (count($dayPrices) > 1000) {
                     $this->_saveRuleProductPrices($dayPrices);
                     $dayPrices = array();
                 }
             }
             $this->_saveRuleProductPrices($dayPrices);
         }
         $this->_saveRuleProductPrices($dayPrices);
         $write->delete($this->getTable('catalogrule_group_website'), array());
         $timestamp = $this->_coreDate->gmtTimestamp();
         $select = $write->select()->distinct(true)->from($this->getTable('catalogrule_product'), array('rule_id', 'customer_group_id', 'website_id'))->where("{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)");
         $query = $select->insertFromSelect($this->getTable('catalogrule_group_website'));
         $write->query($query);
         $write->commit();
     } catch (\Exception $e) {
         $this->_logger->logException($e);
         $write->rollback();
//.........这里部分代码省略.........
开发者ID:zhangjiachao,项目名称:magento2,代码行数:101,代码来源:Rule.php

示例11: _initWebsites

 /**
  * Initialize website values.
  *
  * @return $this
  */
 protected function _initWebsites()
 {
     /** @var $website \Magento\Store\Model\Website */
     foreach ($this->_storeManager->getWebsites() as $website) {
         $this->_websiteCodeToId[$website->getCode()] = $website->getId();
         $this->_websiteCodeToStoreIds[$website->getCode()] = array_flip($website->getStoreCodes());
     }
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:14,代码来源:Product.php

示例12: getSharedWebsiteIds

 /**
  * Retrieve shared website ids
  *
  * @return int[]
  */
 public function getSharedWebsiteIds()
 {
     $ids = $this->_getData('shared_website_ids');
     if ($ids === null) {
         $ids = array();
         if ((bool) $this->getSharingConfig()->isWebsiteScope()) {
             $ids[] = $this->getWebsiteId();
         } else {
             foreach ($this->_storeManager->getWebsites() as $website) {
                 $ids[] = $website->getId();
             }
         }
         $this->setData('shared_website_ids', $ids);
     }
     return $ids;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:21,代码来源:Customer.php


注:本文中的Magento\Framework\StoreManagerInterface::getWebsites方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。