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


PHP StoreManagerInterface::getStore方法代碼示例

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


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

示例1: execute

 /**
  * Display search result
  *
  * @return void
  */
 public function execute()
 {
     $this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
     /* @var $query \Magento\Search\Model\Query */
     $query = $this->_queryFactory->get();
     $query->setStoreId($this->_storeManager->getStore()->getId());
     if ($query->getQueryText() != '') {
         if ($this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) {
             $query->setId(0)->setIsActive(1)->setIsProcessed(1);
         } else {
             if ($query->getId()) {
                 $query->setPopularity($query->getPopularity() + 1);
             } else {
                 $query->setPopularity(1);
             }
             if ($query->getRedirect()) {
                 $query->save();
                 $this->getResponse()->setRedirect($query->getRedirect());
                 return;
             } else {
                 $query->prepare();
             }
         }
         $this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->checkNotes();
         $this->_view->loadLayout();
         $this->_view->renderLayout();
         if (!$this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) {
             $query->save();
         }
     } else {
         $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
     }
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:38,代碼來源:Index.php

示例2: performAfterLoad

 /**
  * Perform operations after collection load
  *
  * @param string $tableName
  * @param string|null $linkField
  * @return void
  */
 protected function performAfterLoad($tableName, $linkField)
 {
     $linkedIds = $this->getColumnValues($linkField);
     if (count($linkedIds)) {
         $connection = $this->getConnection();
         $select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)])->where('cms_entity_store.' . $linkField . ' IN (?)', $linkedIds);
         $result = $connection->fetchAll($select);
         if ($result) {
             $storesData = [];
             foreach ($result as $storeData) {
                 $storesData[$storeData[$linkField]][] = $storeData['store_id'];
             }
             foreach ($this as $item) {
                 $linkedId = $item->getData($linkField);
                 if (!isset($storesData[$linkedId])) {
                     continue;
                 }
                 $storeIdKey = array_search(Store::DEFAULT_STORE_ID, $storesData[$linkedId], true);
                 if ($storeIdKey !== false) {
                     $stores = $this->storeManager->getStores(false, true);
                     $storeId = current($stores)->getId();
                     $storeCode = key($stores);
                 } else {
                     $storeId = current($storesData[$linkedId]);
                     $storeCode = $this->storeManager->getStore($storeId)->getCode();
                 }
                 $item->setData('_first_store_id', $storeId);
                 $item->setData('store_code', $storeCode);
                 $item->setData('store_id', $storesData[$linkedId]);
             }
         }
     }
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:40,代碼來源:AbstractCollection.php

示例3: getCatalogPrice

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getCatalogPrice(\Magento\Catalog\Model\Product $product, \Magento\Store\Api\Data\StoreInterface $store = null, $inclTax = false)
 {
     // Workaround to avoid loading stock status by admin's website
     if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
         $currentStore = $this->storeManager->getStore();
         $this->storeManager->setCurrentStore($store->getId());
     }
     $subProducts = $product->getTypeInstance()->getAssociatedProducts($product);
     if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
         $this->storeManager->setCurrentStore($currentStore->getId());
     }
     if (!$subProducts) {
         return null;
     }
     $minPrice = null;
     foreach ($subProducts as $subProduct) {
         $subProduct->setWebsiteId($product->getWebsiteId())->setCustomerGroupId($product->getCustomerGroupId());
         if ($subProduct->isSalable()) {
             if ($this->commonPriceModel->getCatalogPrice($subProduct) < $minPrice || $minPrice === null) {
                 $minPrice = $this->commonPriceModel->getCatalogPrice($subProduct);
                 $product->setTaxClassId($subProduct->getTaxClassId());
             }
         }
     }
     return $minPrice;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:30,代碼來源:CatalogPrice.php

示例4: getStores

 /**
  * Retrieve stores configured in system.
  *
  * @return \Magento\Framework\Data\Collection\AbstractDb
  */
 public function getStores()
 {
     if (!$this->_stores) {
         $this->_stores = $this->_storeManager->getStore()->getResourceCollection()->load();
     }
     return $this->_stores;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:12,代碼來源:Data.php

示例5: aroundDispatch

 /**
  * @param \Magento\Framework\App\ActionInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @throws \Magento\Framework\Exception\State\InitException
  */
 public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_storeManager->getStore()->isActive()) {
         throw new \Magento\Framework\Exception\State\InitException(__('Current store is not active.'));
     }
     return $proceed($request);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:16,代碼來源:StoreCheck.php

示例6: execute

 /**
  * Execute method.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $order = $observer->getEvent()->getOrder();
     $email = $order->getCustomerEmail();
     $website = $this->storeManager->getWebsite($order->getWebsiteId());
     $storeName = $this->storeManager->getStore($order->getStoreId())->getName();
     //if api is not enabled
     if (!$this->helper->isEnabled($website)) {
         return $this;
     }
     //automation enrolment for order
     if ($order->getCustomerIsGuest()) {
         // guest to automation mapped
         $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER';
         $automationType = \Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_GUEST_ORDER;
     } else {
         // customer to automation mapped
         $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER';
         $automationType = \Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_ORDER;
     }
     $programId = $this->helper->getAutomationIdByType($programType, $order->getWebsiteId());
     //the program is not mapped
     if (!$programId) {
         return $this;
     }
     try {
         $this->automationFactory->create()->setEmail($email)->setAutomationType($automationType)->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)->setTypeId($order->getId())->setWebsiteId($website->getId())->setStoreName($storeName)->setProgramId($programId)->save();
     } catch (\Exception $e) {
         $this->helper->debug((string) $e, []);
     }
     return $this;
 }
開發者ID:dotmailer,項目名稱:dotmailer-magento2-extension,代碼行數:39,代碼來源:PlaceCreateAutomationStatus.php

示例7: _beforeSave

 /**
  * Prepare data before save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _beforeSave($object)
 {
     if (!$object->getData($this->getAttribute()->getAttributeCode())) {
         $object->setData($this->getAttribute()->getAttributeCode(), $this->_storeManager->getStore()->getId());
     }
     return $this;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:13,代碼來源:Store.php

示例8: addFilter

 /**
  * {@inheritdoc}
  */
 public function addFilter(Collection $collection, $field, $condition = null)
 {
     if (isset($condition['eq']) && $condition['eq']) {
         /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection  */
         $collection->addStoreFilter($this->storeManager->getStore($condition['eq']));
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:10,代碼來源:AddStoreFieldToCollection.php

示例9: setMethod

 /**
  * {@inheritdoc}
  */
 public function setMethod($cartId, $carrierCode, $methodCode)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
     if (0 == $quote->getItemsCount()) {
         throw new InputException('Shipping method is not applicable for empty cart');
     }
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping method is not applicable.');
     }
     $shippingAddress = $quote->getShippingAddress();
     if (!$shippingAddress->getCountryId()) {
         throw new StateException('Shipping address is not set');
     }
     $billingAddress = $quote->getBillingAddress();
     if (!$billingAddress->getCountryId()) {
         throw new StateException('Billing address is not set');
     }
     $shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
     if (!$shippingAddress->requestShippingRates()) {
         throw new NoSuchEntityException('Carrier with such method not found: ' . $carrierCode . ', ' . $methodCode);
     }
     try {
         $quote->collectTotals()->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Cannot set shipping method. ' . $e->getMessage());
     }
     return true;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:32,代碼來源:WriteService.php

示例10: __invoke

 /**
  * Retrieves the current Store ID from Magento and adds it to the record
  *
  * @param  array $record
  * @return array
  */
 public function __invoke(array $record)
 {
     // get the store_id and add it to the record
     $store = $this->storeManager->getStore();
     $record['extra']['store_id'] = $store->getId();
     return $record;
 }
開發者ID:classyllama,項目名稱:ClassyLlama_AvaTax,代碼行數:13,代碼來源:AvaTaxProcessor.php

示例11: getStore

 /**
  * Get store object
  *
  * @return \Magento\Store\Model\Store
  */
 public function getStore()
 {
     if ($this->getShipment()) {
         return $this->getShipment()->getStore();
     }
     return $this->_storeManager->getStore();
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:12,代碼來源:Comment.php

示例12: _getConfigUrl

 /**
  * Get url for config settings where base url option can be changed
  *
  * @return string
  */
 protected function _getConfigUrl()
 {
     $output = '';
     $defaultUnsecure = $this->_config->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
     $defaultSecure = $this->_config->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default');
     if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER || $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER) {
         $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web']);
     } else {
         /** @var $dataCollection \Magento\Config\Model\Resource\Config\Data\Collection */
         $dataCollection = $this->_configValueFactory->create()->getCollection();
         $dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER);
         /** @var $data \Magento\Framework\App\Config\ValueInterface */
         foreach ($dataCollection as $data) {
             if ($data->getScope() == 'stores') {
                 $code = $this->_storeManager->getStore($data->getScopeId())->getCode();
                 $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web', 'store' => $code]);
                 break;
             } elseif ($data->getScope() == 'websites') {
                 $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode();
                 $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web', 'website' => $code]);
                 break;
             }
         }
     }
     return $output;
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:31,代碼來源:Baseurl.php

示例13: exportModules

 public function exportModules($data)
 {
     $moduleTables = $this->getModuleTables();
     $configs = [];
     if (!empty($data['modules'])) {
         $store = $this->_storeManager->getStore($data['store_id']);
         foreach ($data['modules'] as $k => $v) {
             if (isset($moduleTables[$v])) {
                 $tables = $moduleTables[$v];
             }
             $systemFileDir = $this->_moduleDir->getDir($v, Dir::MODULE_ETC_DIR) . DIRECTORY_SEPARATOR . 'adminhtml' . DIRECTORY_SEPARATOR . 'system.xml';
             if (file_exists($systemFileDir)) {
                 $systemConfigs = $this->parser->load($systemFileDir)->xmlToArray();
                 if ($systemConfigs['config']['_value']['system']['section']) {
                     foreach ($systemConfigs['config']['_value']['system']['section'] as $_section) {
                         $groups = [];
                         if (isset($_section['_value']['group'])) {
                             $groups = $_section['_value']['group'];
                         } elseif (isset($_section['group'])) {
                             $groups = $_section['group'];
                         }
                         $_sectionId = '';
                         if (isset($_section['_attribute']['id'])) {
                             $_sectionId = $_section['_attribute']['id'];
                         } elseif (isset($systemConfigs['config']['_value']['system']['section']['_attribute']['id'])) {
                             $_sectionId = $systemConfigs['config']['_value']['system']['section']['_attribute']['id'];
                         }
                         if (empty($groups)) {
                             continue;
                         }
                         foreach ($groups as $_group) {
                             if (!isset($_group['_value']['field'])) {
                                 continue;
                             }
                             foreach ($_group['_value']['field'] as $_field) {
                                 if (isset($_sectionId) && isset($_group['_attribute']['id']) && isset($_field['_attribute']['id'])) {
                                     $key = $_sectionId . '/' . $_group['_attribute']['id'] . '/' . $_field['_attribute']['id'];
                                     $result = $this->_scopeConfig->getValue($key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
                                     if ($result == '') {
                                         continue;
                                     }
                                     $configs[$v]['system_configs'][] = ['key' => $key, 'value' => $result];
                                 }
                             }
                         }
                     }
                 }
             }
             if (isset($moduleTables[$v]) && is_array($moduleTables[$v])) {
                 foreach ($moduleTables[$v] as $key => $tableName) {
                     $connection = $this->_resource->getConnection();
                     $select = 'SELECT * FROM ' . $this->_resource->getTableName($tableName);
                     $rows = $connection->fetchAll($select);
                     $configs[$v]['tables'][$tableName] = $rows;
                 }
             }
         }
     }
     return $configs;
 }
開發者ID:dragonsword007008,項目名稱:magento2,代碼行數:60,代碼來源:Export.php

示例14: execute

 /**
  * If it's configured to capture on shipment - do this.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $dataObject = $observer->getEvent()->getDataObject();
     if ($dataObject->getCustomerId() && $dataObject->getStatusId() == \Magento\Review\Model\Review::STATUS_APPROVED) {
         $customerId = $dataObject->getCustomerId();
         $this->helper->setConnectorContactToReImport($customerId);
         //save review info in the table
         $this->registerReview($dataObject);
         $store = $this->storeManager->getStore($dataObject->getStoreId());
         $storeName = $store->getName();
         $website = $this->storeManager->getStore($store)->getWebsite();
         $customer = $this->customerFactory->create()->load($customerId);
         //if api is not enabled
         if (!$this->helper->isEnabled($website)) {
             return $this;
         }
         $programId = $this->helper->getWebsiteConfig('connector_automation/visitor_automation/review_automation');
         if ($programId) {
             $automation = $this->automationFactory->create();
             $automation->setEmail($customer->getEmail())->setAutomationType(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_REVIEW)->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)->setTypeId($dataObject->getReviewId())->setWebsiteId($website->getId())->setStoreName($storeName)->setProgramId($programId);
             $automation->save();
         }
     }
     return $this;
 }
開發者ID:dotmailer,項目名稱:dotmailer-magento2-extension,代碼行數:32,代碼來源:ReviewSaveAutomation.php

示例15: prepareItem

 /**
  * Get data
  *
  * @param array $item
  * @return string
  */
 protected function prepareItem(array $item)
 {
     if ($item['store_id'] == \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
         return __('All Store Views');
     }
     return $this->storeManager->getStore($item['store_id'])->getName();
 }
開發者ID:dragonsword007008,項目名稱:magento2,代碼行數:13,代碼來源:StoreView.php


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