當前位置: 首頁>>代碼示例>>PHP>>正文


PHP StoreManagerInterface::getWebsites方法代碼示例

本文整理匯總了PHP中Magento\Store\Model\StoreManagerInterface::getWebsites方法的典型用法代碼示例。如果您正苦於以下問題:PHP StoreManagerInterface::getWebsites方法的具體用法?PHP StoreManagerInterface::getWebsites怎麽用?PHP StoreManagerInterface::getWebsites使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Store\Model\StoreManagerInterface的用法示例。


在下文中一共展示了StoreManagerInterface::getWebsites方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: dispatch

 /**
  * Set new customer group to all his quotes
  *
  * @param Observer $observer
  * @return void
  */
 public function dispatch(Observer $observer)
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $observer->getEvent()->getCustomerDataObject();
     /** @var \Magento\Customer\Api\Data\CustomerInterface $origCustomer */
     $origCustomer = $observer->getEvent()->getOrigCustomerDataObject();
     if ($customer->getGroupId() !== $origCustomer->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() ? [$this->storeManager->getWebsite($customer->getWebsiteId())] : $this->storeManager->getWebsites();
         foreach ($websites as $website) {
             try {
                 $quote = $this->quoteRepository->getForCustomer($customer->getId());
                 $quote->setWebsite($website);
                 $quote->setCustomerGroupId($customer->getGroupId());
                 $quote->collectTotals();
                 $this->quoteRepository->save($quote);
             } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             }
         }
     }
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:31,代碼來源:CustomerQuote.php

示例2: 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:aiesh,項目名稱:magento2,代碼行數:31,代碼來源:CustomerQuote.php

示例3: getWebsiteIds

 protected function getWebsiteIds()
 {
     if (null == $this->websiteIds) {
         $websitesList = $this->storeManager->getWebsites(true);
         $this->websiteIds = array_keys($websitesList);
     }
     return $this->websiteIds;
 }
開發者ID:rogyar,項目名稱:m2-sampledata-generator,代碼行數:8,代碼來源:ProductSaveObserver.php

示例4: _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:pradeep-wagento,項目名稱:magento2,代碼行數:14,代碼來源:StoreResolver.php

示例5: execute

 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('format') === null) {
         $this->writeSection($output, 'Magento Websites');
     }
     foreach ($this->storeManager->getWebsites() as $website) {
         $table[$website->getId()] = array($website->getId(), $website->getCode());
     }
     ksort($table);
     $this->getHelper('table')->setHeaders(array('id', 'code'))->renderByFormat($output, $table, $input->getOption('format'));
 }
開發者ID:brentwpeterson,項目名稱:n98-magerun2,代碼行數:16,代碼來源:ListCommand.php

示例6: getScopeTree

 /**
  * Gets store tree in a format easily walked over
  * for config path value comparison
  *
  * @return array
  */
 public function getScopeTree()
 {
     $tree = array('websites' => array());
     $websites = $this->storeManager->getWebsites();
     /* @var $website Website */
     foreach ($websites as $website) {
         $tree['websites'][$website->getId()] = array('stores' => array());
         /* @var $store Store */
         foreach ($website->getStores() as $store) {
             $tree['websites'][$website->getId()]['stores'][] = $store->getId();
         }
     }
     return $tree;
 }
開發者ID:erikhansen,項目名稱:magento2-configscopehints,代碼行數:20,代碼來源:Data.php

示例7: getData

 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if ($this->storeManager->isSingleStoreMode()) {
         $websites = $this->storeManager->getWebsites();
         $singleStoreWebsite = array_shift($websites);
         $this->addFilter($this->filterBuilder->setField('store_website_id')->setValue($singleStoreWebsite->getId())->create());
         $this->addFilter($this->filterBuilder->setField('store_group_id')->setConditionType('null')->create());
     }
     $data = parent::getData();
     foreach ($data['items'] as &$item) {
         $item += ['default' => __('Global')];
     }
     return $data;
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:19,代碼來源:DataProvider.php

示例8: toOptionArray

 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $this->_options = [];
         foreach ($this->_storeManager->getWebsites() as $website) {
             $id = $website->getId();
             $name = $website->getName();
             if ($id != 0) {
                 $this->_options[] = ['value' => $id, 'label' => $name];
             }
         }
     }
     return $this->_options;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:17,代碼來源:Website.php

示例9: _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:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:AbstractEav.php

示例10: getEntityStore

 /**
  * Retrieve the entities for the given scope
  *
  * @param  string $scope Scope
  * @return \Magento\Store\Api\Data\WebsiteInterface[]|\Magento\Store\Api\Data\StoreInterface[]
  */
 private function getEntityStore($scope)
 {
     if (isset($this->entityStore[$scope])) {
         return $this->entityStore[$scope];
     }
     switch ($scope) {
         case self::SCOPE_STORES:
             $this->entityStore[$scope] = $this->storeManager->getStores(true, true);
             break;
         case self::SCOPE_WEBSITES:
             $this->entityStore[$scope] = $this->storeManager->getWebsites(true, true);
             break;
         default:
             throw new ScopeConvertException(sprintf('Unknown scope "%s"', $scope));
     }
     return $this->entityStore[$scope];
 }
開發者ID:semaio,項目名稱:magento2-configimportexport,代碼行數:23,代碼來源:ScopeConverter.php

示例11: getWebsiteOptionHash

 /**
  * Get websites as id => name associative array
  *
  * @param bool $withDefault
  * @param string $attribute
  * @return array
  */
 public function getWebsiteOptionHash($withDefault = false, $attribute = 'name')
 {
     $options = [];
     foreach ($this->_storeManager->getWebsites((bool) $withDefault && $this->_isAdminScopeAllowed) as $website) {
         $options[$website->getId()] = $website->getDataUsingMethod($attribute);
     }
     return $options;
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:15,代碼來源:Store.php

示例12: loadStore

 /**
  * Loading and caching of default website, store and store view
  *
  * @return bool
  */
 protected function loadStore()
 {
     $isLoaded = true;
     if (!$this->website) {
         $isLoaded = false;
         $websites = $this->storeManager->getWebsites();
         foreach ($websites as $website) {
             if ($website->getIsDefault()) {
                 $this->website = $website;
                 $this->group = $website->getDefaultGroup();
                 $this->store = $website->getDefaultStore();
                 $isLoaded = true;
                 break;
             }
         }
     }
     return $isLoaded;
 }
開發者ID:ktplKunj,項目名稱:TestMagento,代碼行數:23,代碼來源:StoreManager.php

示例13: execute

 /**
  * @return Page
  */
 public function execute()
 {
     if (!$this->getSelectedStore()) {
         // If we are not under a store view, then redirect to the first
         // found one. Nosto is configured per store.
         foreach ($this->_storeManager->getWebsites() as $website) {
             $storeId = $website->getDefaultGroup()->getDefaultStoreId();
             if (!empty($storeId)) {
                 return $this->resultRedirectFactory->create()->setPath('*/*/index', ['store' => $storeId]);
             }
         }
     }
     /** @var Page $result */
     $result = $this->_resultPageFactory->create();
     $result->setActiveMenu(self::ADMIN_RESOURCE);
     $result->getConfig()->getTitle()->prepend(__('Nosto - Account Settings'));
     return $result;
 }
開發者ID:Nosto,項目名稱:nosto-magento2,代碼行數:21,代碼來源:Index.php

示例14: applyAllRules

 /**
  * @param Product|null $product
  * @throws \Exception
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function applyAllRules(Product $product = null)
 {
     $write = $this->getWriteAdapter();
     $fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
     $toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
     $productId = $product ? $product->getId() : null;
     /**
      * 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($website->getId(), $productId);
         $dayPrices = [];
         $stopFlags = [];
         $prevKey = null;
         while ($ruleData = $productsStmt->fetch()) {
             $ruleProductId = $ruleData['product_id'];
             $productKey = $ruleProductId . '_' . $ruleData['website_id'] . '_' . $ruleData['customer_group_id'];
             if ($prevKey && $prevKey != $productKey) {
                 $stopFlags = [];
                 if (count($dayPrices) > $this->batchCount) {
                     $this->saveRuleProductPrices($dayPrices);
                     $dayPrices = [];
                 }
             }
             /**
              * 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] = ['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;
         }
         $this->saveRuleProductPrices($dayPrices);
     }
     $write->delete($this->getTable('catalogrule_group_website'), []);
     $timestamp = $this->dateTime->gmtTimestamp();
     $select = $write->select()->distinct(true)->from($this->getTable('catalogrule_product'), ['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);
     return $this;
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:65,代碼來源:IndexBuilder.php

示例15: checkWebsites

 /**
  * @param ResultCollection $results
  * @param $checkGroupClass
  * @param $check
  */
 private function checkWebsites(ResultCollection $results, $checkGroupClass, $check)
 {
     if (!($websites = $this->storeManager->getWebsites())) {
         $this->_markCheckWarning($results, 'websites', $checkGroupClass);
     }
     foreach ($websites as $website) {
         $check->check($results, $website);
     }
 }
開發者ID:brentwpeterson,項目名稱:n98-magerun2,代碼行數:14,代碼來源:CheckCommand.php


注:本文中的Magento\Store\Model\StoreManagerInterface::getWebsites方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。