php Magento-Store-Model-StoreManagerInterface类(方法)实例源码

下面列出了php Magento-Store-Model-StoreManagerInterface 类(方法)源码代码实例,从而了解它的用法。

作者:pradeep-wagent    项目:magento   
protected function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('quoteInto')->willReturnCallback(function ($query, $expression) {
         return str_replace('?', $expression, $query);
     });
     $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->resource->method('getTableName')->willReturnCallback(function ($table) {
         return 'prefix_' . $table;
     });
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->website = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\WebsiteInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->website->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->store->expects($this->any())->method('getId')->willReturn(self::STORE_ID);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($this->website);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
     $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory->expects($this->once())->method('create')->willReturn($this->attributeCollection);
     $this->target = $objectManager->getObject('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper', ['resource' => $this->resource, 'storeManager' => $this->storeManager, 'attributeCollectionFactory' => $attributeCollectionFactory]);
     $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMock();
 }

作者:pradeep-wagent    项目:magento   
/**
  * Initialize repository
  */
 public function setUp()
 {
     $this->blockResource = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block')->disableOriginalConstructor()->getMock();
     $this->dataObjectProcessor = $this->getMockBuilder('Magento\\Framework\\Reflection\\DataObjectProcessor')->disableOriginalConstructor()->getMock();
     $blockFactory = $this->getMockBuilder('Magento\\Cms\\Model\\BlockFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $blockDataFactory = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $blockSearchResultFactory = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockSearchResultsInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $collectionFactory = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getId')->willReturn(0);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($store);
     $this->block = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->getMock();
     $this->blockData = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockInterface')->getMock();
     $this->blockSearchResult = $this->getMockBuilder('Magento\\Cms\\Api\\Data\\BlockSearchResultsInterface')->getMock();
     $this->collection = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Block\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getSize', 'setCurPage', 'setPageSize', 'load', 'addOrder'])->getMock();
     $blockFactory->expects($this->any())->method('create')->willReturn($this->block);
     $blockDataFactory->expects($this->any())->method('create')->willReturn($this->blockData);
     $blockSearchResultFactory->expects($this->any())->method('create')->willReturn($this->blockSearchResult);
     $collectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
     /**
      * @var \Magento\Cms\Model\BlockFactory $blockFactory
      * @var \Magento\Cms\Api\Data\BlockInterfaceFactory $blockDataFactory
      * @var \Magento\Cms\Api\Data\BlockSearchResultsInterfaceFactory $blockSearchResultFactory
      * @var \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $collectionFactory
      */
     $this->dataHelper = $this->getMockBuilder('Magento\\Framework\\Api\\DataObjectHelper')->disableOriginalConstructor()->getMock();
     $this->repository = new BlockRepository($this->blockResource, $blockFactory, $blockDataFactory, $collectionFactory, $blockSearchResultFactory, $this->dataHelper, $this->dataObjectProcessor, $this->storeManager);
 }

作者:shabbirvividad    项目:magento   
protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->managerInterfaceMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->resourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->entityFactoryMock2 = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false);
     $this->helperMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Helper', [], [], '', false);
     $entity = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false);
     $entity->expects($this->any())->method('getReadConnection')->will($this->returnValue($adapter));
     $entity->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
     $this->universalFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false);
     $this->universalFactoryMock->expects($this->any())->method('create')->will($this->returnValue($entity));
     $this->storeManagerMock = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnCallback(function ($store) {
         return is_object($store) ? $store : new \Magento\Framework\Object(['id' => 42]);
     }));
     $this->catalogHelperMock = $this->getMock('Magento\\Catalog\\Helper\\Data', [], [], '', false);
     $this->stateMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State', [], [], '', false);
     $this->scopeConfigInterfaceMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->optionFactoryMock = $this->getMock('Magento\\Catalog\\Model\\Product\\OptionFactory', [], [], '', false);
     $this->urlMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Url', [], [], '', false);
     $this->timezoneInterfaceMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->sessionMock = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->dateTimeMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->collection = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Resource\\Product\\Link\\Product\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->managerInterfaceMock, 'eavConfig' => $this->configMock, 'resource' => $this->resourceMock, 'eavEntityFactory' => $this->entityFactoryMock2, 'resourceHelper' => $this->helperMock, 'universalFactory' => $this->universalFactoryMock, 'storeManager' => $this->storeManagerMock, 'catalogData' => $this->catalogHelperMock, 'catalogProductFlatState' => $this->stateMock, 'scopeConfig' => $this->scopeConfigInterfaceMock, 'productOptionFactory' => $this->optionFactoryMock, 'catalogUrl' => $this->urlMock, 'localeDate' => $this->timezoneInterfaceMock, 'customerSession' => $this->sessionMock, 'dateTime' => $this->dateTimeMock]);
 }

作者:nja7    项目:magento   
/**
  * 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());
     }
 }

作者:shabbirvividad    项目:magento   
/**
  * Retrieve store
  *
  * @return \Magento\Store\Model\Store
  */
 public function getStore()
 {
     if ($this->_store === null) {
         $this->_store = $this->_storeManager->getStore();
     }
     return $this->_store;
 }

作者:pradeep-wagent    项目:magento   
/**
  * {@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;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * 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;
 }

作者:hientruong9    项目:magento2_installe   
/**
  * Return current store id
  *
  * @return int
  */
 public function getStoreId()
 {
     if ($this->_storeId === null) {
         $this->setStoreId($this->_storeManager->getStore()->getId());
     }
     return $this->_storeId;
 }

作者:pradeep-wagent    项目:magento   
/**
  * @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);
 }

作者:dotmaile    项目:dotmailer-magento2-extensio   
/**
  * 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;
 }

作者:shabbirvividad    项目:magento   
/**
  * @param bool $isWebsiteScope
  * @param array $websites
  * @param int $quoteId
  * @dataProvider dispatchDataProvider
  */
 public function testDispatch($isWebsiteScope, $websites, $quoteId)
 {
     $this->configMock->expects($this->once())->method('isWebsiteScope')->will($this->returnValue($isWebsiteScope));
     $customerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $customerDataObjectMock->expects($this->any())->method('getGroupId')->will($this->returnValue(1));
     $customerDataObjectMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue(2));
     if ($isWebsiteScope) {
         $websites = $websites[0];
         $this->storeManagerMock->expects($this->once())->method('getWebsite')->with(2)->will($this->returnValue($websites));
     } else {
         $this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
     }
     $origCustomerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $origCustomerDataObjectMock->expects($this->any())->method('getGroupId')->will($this->returnValue(2));
     $this->eventMock->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($customerDataObjectMock));
     $this->eventMock->expects($this->any())->method('getOrigCustomerDataObject')->will($this->returnValue($origCustomerDataObjectMock));
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote $quoteMock */
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['setWebsite', 'setCustomerGroupId', 'collectTotals', '__wakeup'])->disableOriginalConstructor()->getMock();
     $websiteCount = count($websites);
     if ($quoteId) {
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('getForCustomer')->will($this->returnValue($quoteMock));
         $quoteMock->expects($this->exactly($websiteCount))->method('setWebsite');
         $quoteMock->expects($this->exactly($websiteCount))->method('setCustomerGroupId');
         $quoteMock->expects($this->exactly($websiteCount))->method('collectTotals');
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('save')->with($quoteMock);
     } else {
         $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('getForCustomer')->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException());
         $quoteMock->expects($this->never())->method('setCustomerGroupId');
         $quoteMock->expects($this->never())->method('collectTotals');
         $this->quoteRepositoryMock->expects($this->never())->method('save');
     }
     $this->customerQuote->dispatch($this->observerMock);
 }

作者:Doabilit    项目:magento2de   
/**
  * @return void
  */
 public function execute()
 {
     $currentActiveStore = $this->storeManager->getStore();
     $storeCode = $this->_request->getParam(StoreResolver::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie());
     try {
         $store = $this->storeRepository->getActiveStoreByCode($storeCode);
     } catch (StoreIsInactiveException $e) {
         $error = __('Requested store is inactive');
     } catch (NoSuchEntityException $e) {
         $error = __('Requested store is not found');
     }
     if (isset($error)) {
         $this->messageManager->addError($error);
         $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
         return;
     }
     $defaultStoreView = $this->storeManager->getDefaultStoreView();
     if ($defaultStoreView->getId() == $store->getId()) {
         $this->storeCookieManager->deleteStoreCookie($store);
     } else {
         $this->httpContext->setValue(Store::ENTITY, $store->getCode(), $defaultStoreView->getCode());
         $this->storeCookieManager->setStoreCookie($store);
     }
     if ($store->isUseStoreInUrl()) {
         // Change store code in redirect url
         if (strpos($this->_redirect->getRedirectUrl(), $currentActiveStore->getBaseUrl()) !== false) {
             $this->getResponse()->setRedirect(str_replace($currentActiveStore->getBaseUrl(), $store->getBaseUrl(), $this->_redirect->getRedirectUrl()));
         } else {
             $this->getResponse()->setRedirect($store->getBaseUrl());
         }
     } else {
         $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
     }
 }

作者:aies    项目:magento   
/**
  * {@inheritdoc}
  */
 public function set(\Magento\Checkout\Service\V1\Data\Cart\PaymentMethod $method, $cartId)
 {
     $quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
     $payment = $this->paymentMethodBuilder->build($method, $quote);
     if ($quote->isVirtual()) {
         // check if billing address is set
         if (is_null($quote->getBillingAddress()->getCountryId())) {
             throw new InvalidTransitionException('Billing address is not set');
         }
         $quote->getBillingAddress()->setPaymentMethod($payment->getMethod());
     } else {
         // check if shipping address is set
         if (is_null($quote->getShippingAddress()->getCountryId())) {
             throw new InvalidTransitionException('Shipping address is not set');
         }
         $quote->getShippingAddress()->setPaymentMethod($payment->getMethod());
     }
     if (!$quote->isVirtual() && $quote->getShippingAddress()) {
         $quote->getShippingAddress()->setCollectShippingRates(true);
     }
     if (!$this->zeroTotalValidator->isApplicable($payment->getMethodInstance(), $quote)) {
         throw new InvalidTransitionException('The requested Payment Method is not available.');
     }
     $quote->setTotalsCollectedFlag(false)->collectTotals()->save();
     return $quote->getPayment()->getId();
 }

作者:Doabilit    项目:magento2de   
/**
  * Retrieve configuration metadata
  *
  * @return array
  */
 public function getData()
 {
     $scope = $this->request->getParam('scope');
     $scopeId = $this->request->getParam('scope_id');
     $data = [];
     if ($scope) {
         $showFallbackReset = false;
         list($fallbackScope, $fallbackScopeId) = $this->scopeFallbackResolver->getFallbackScope($scope, $scopeId);
         if ($fallbackScope && !$this->storeManager->isSingleStoreMode()) {
             $scope = $fallbackScope;
             $scopeId = $fallbackScopeId;
             $showFallbackReset = true;
         }
         $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
         $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
         foreach ($fieldsData as $fieldData) {
             $element =& $data;
             foreach (explode('/', $fieldData->getFieldConfig()['fieldset']) as $fieldset) {
                 if (!isset($element[$fieldset]['children'])) {
                     $element[$fieldset]['children'] = [];
                 }
                 $element =& $element[$fieldset]['children'];
             }
             $fieldName = $fieldData->getFieldConfig()['field'];
             $element[$fieldName]['arguments']['data']['config']['default'] = $fieldData->getValue();
             $element[$fieldName]['arguments']['data']['config']['showFallbackReset'] = $showFallbackReset;
         }
     }
     return $data;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * {@inheritDoc}
  */
 public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
 {
     /** @var \Magento\Quote\Api\Data\CartItemInterface[] $items */
     if (!count($items)) {
         return false;
     }
     $addressFreeShipping = true;
     $store = $this->storeManager->getStore($quote->getStoreId());
     $this->calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
     /** @var \Magento\Quote\Api\Data\CartItemInterface $item */
     foreach ($items as $item) {
         if ($item->getNoDiscount()) {
             $addressFreeShipping = false;
             $item->setFreeShipping(false);
             continue;
         }
         /** Child item discount we calculate for parent */
         if ($item->getParentItemId()) {
             continue;
         }
         $this->calculator->processFreeShipping($item);
         $itemFreeShipping = (bool) $item->getFreeShipping();
         $addressFreeShipping = $addressFreeShipping && $itemFreeShipping;
         /** Parent free shipping we apply to all children*/
         $this->applyToChildren($item, $itemFreeShipping);
     }
     return $addressFreeShipping;
 }

作者:shabbirvividad    项目:magento   
/**
  * Get store object
  *
  * @return \Magento\Store\Model\Store
  */
 public function getStore()
 {
     if ($this->getCreditmemo()) {
         return $this->getCreditmemo()->getStore();
     }
     return $this->_storeManager->getStore();
 }

作者:Doabilit    项目:magento2de   
/**
  * Prepare component configuration
  *
  * @return void
  */
 public function prepare()
 {
     parent::prepare();
     if ($this->storeManager->isSingleStoreMode()) {
         $this->_data['config']['componentDisabled'] = true;
     }
 }

作者:alinmiro    项目:alin-cado   
public function sendNotification($data)
 {
     if (!$data) {
         return false;
     }
     $this->inlineTranslation->suspend();
     try {
         $postObject = new \Magento\Framework\DataObject();
         $postObject->setData($data);
         $error = false;
         $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
         /* $from = [
                'name' => '',
                'email' => ''
            ];*/
         $email_template = $this->scopeConfig->getValue('cadou/email/template');
         if (empty($email_template)) {
             $email_template = (string) 'cadou_email_template';
             // this code we have mentioned in the email_templates.xml
         }
         $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
         /*$this->messageManager->addSuccess(
               __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
           );*/
         return TRUE;
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage()));
         return FALSE;
     }
 }

作者:shabbirvividad    项目:magento   
/**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
 {
     $existingData = $category->toFlatArray();
     if ($category->getId()) {
         $existingCategory = $this->get($category->getId());
         if (isset($existingData['image']) && is_array($existingData['image'])) {
             $existingData['image_additional_data'] = $existingData['image'];
             unset($existingData['image']);
         }
         $existingData['id'] = $existingCategory->getId();
         $existingData['parent_id'] = $existingCategory->getParentId();
         $existingData['path'] = $existingCategory->getPath();
         $existingData['is_active'] = $existingCategory->getIsActive();
         $existingData['include_in_menu'] = isset($existingData['include_in_menu']) ? (bool) $existingData['include_in_menu'] : false;
         $category->setData($existingData);
     } else {
         $parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId();
         $parentCategory = $this->get($parentId);
         $existingData['include_in_menu'] = isset($existingData['include_in_menu']) ? (bool) $existingData['include_in_menu'] : false;
         /** @var  $category Category */
         $category->setData($existingData);
         $category->setPath($parentCategory->getPath());
     }
     try {
         $this->validateCategory($category);
         $this->categoryResource->save($category);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save category: %1', $e->getMessage()), $e);
     }
     unset($this->instances[$category->getId()]);
     return $category;
 }

作者:nblai    项目:magescotc   
/**
  * Save newsletter subscription preference action
  *
  * @return void|null
  */
 public function executeInternal()
 {
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         return $this->_redirect('customer/account/');
     }
     $customerId = $this->_customerSession->getCustomerId();
     if ($customerId === null) {
         $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
     } else {
         try {
             $customer = $this->customerRepository->getById($customerId);
             $storeId = $this->storeManager->getStore()->getId();
             $customer->setStoreId($storeId);
             $this->customerRepository->save($customer);
             if ((bool) $this->getRequest()->getParam('is_subscribed', false)) {
                 $this->subscriberFactory->create()->subscribeCustomerById($customerId);
                 $this->messageManager->addSuccess(__('We saved the subscription.'));
             } else {
                 $this->subscriberFactory->create()->unsubscribeCustomerById($customerId);
                 $this->messageManager->addSuccess(__('We removed the subscription.'));
             }
         } catch (\Exception $e) {
             $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
         }
     }
     $this->_redirect('customer/account/');
 }


问题


面经


文章

微信
公众号

扫码关注公众号