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

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

作者:ViniciusAugust    项目:magento   
public function testIsSingleStoreModeWhenSingleStoreModeDisabledAndHasSingleStore()
 {
     $this->_configMock->expects($this->once())->method('getValue')->with(\Magento\Store\Model\StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE)->will($this->returnValue(false));
     $this->_storage->expects($this->once())->method('hasSingleStore')->will($this->returnValue(true));
     $this->_factoryMock->expects($this->any())->method('get')->will($this->returnValue($this->_storage));
     $this->assertFalse($this->_model->isSingleStoreMode());
 }

作者:remarket    项目:mgconnecto   
public function __construct(Context $context, array $data = [], StoreManager $sManager, Webtracking $webtracking, Session $session)
 {
     parent::__construct($context, $data);
     $this->_activeStore = $sManager->getStore();
     $this->_webtracking = $webtracking;
     $this->_session = $session;
 }

作者:remarket    项目:mgconnecto   
public function __construct(Session $customerSession, CheckoutSession $CheckoutSession, Registry $registry, Subscriber $subscriber, Group $customerGroupModel, Queue $remarketyQueue, Store $store, ScopeConfigInterface $scopeConfig, StoreManager $sManager)
 {
     parent::__construct($registry, $subscriber, $customerGroupModel, $remarketyQueue, $store, $scopeConfig);
     $this->session = $customerSession;
     $this->_checkoutSession = $CheckoutSession;
     $this->_store = $sManager->getStore();
 }

作者:praxigent    项目:mobi_app_generic_mage   
/**
  * Update/create store (frontname: "Store View").
  *
  * @param int $storeId ID to update existing store or 'null' to create new one
  * @param string $name
  * @param string $code
  * @param int $websiteId
  * @param int $groupId (frontname: "Store")
  * @param int $sortOrder
  * @param bool $isActive
  * @return \Magento\Store\Model\Store
  */
 private function saveStore($storeId = null, $isActive = false, $name = null, $code = null, $websiteId = null, $groupId = null, $sortOrder = null)
 {
     $event = 'store_add';
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_manObj->create(\Magento\Store\Model\Store::class);
     $store->load($storeId);
     /* 'code' is required attr. and should be set for existing store */
     $event = is_null($store->getCode()) ? 'store_add' : 'store_edit';
     $store->setIsActive($isActive);
     if (!is_null($name)) {
         $store->setName($name);
     }
     if (!is_null($code)) {
         $store->setCode($code);
     }
     if (!is_null($websiteId)) {
         $store->setWebsiteId($websiteId);
     }
     if (!is_null($websiteId)) {
         $store->setGroupId($groupId);
     }
     if (!is_null($sortOrder)) {
         $store->setSortOrder($sortOrder);
     }
     $store->save();
     /** @var  \Magento\Store\Model\StoreManager */
     $this->manStore->reinitStores();
     /** @var  \Magento\Framework\Event\ManagerInterface */
     $this->manEvent->dispatch($event, ['store' => $store]);
     return $store;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * Set up
  */
 public function setUp()
 {
     $this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['getCurrencyCode'], [], '', false);
     $this->httpContextMock = $this->getMock('Magento\\Framework\\App\\Http\\Context', [], [], '', false);
     $this->httpRequestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeCookieManager = $this->getMock('Magento\\Store\\Api\\StoreCookieManagerInterface');
     $this->storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->currentStoreMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getDefaultStore', '__wakeup'], [], '', false);
     $this->closureMock = function () {
         return 'ExpectedValue';
     };
     $this->subjectMock = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $this->requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->plugin = (new ObjectManager($this))->getObject('Magento\\Store\\App\\Action\\Plugin\\Context', ['session' => $this->sessionMock, 'httpContext' => $this->httpContextMock, 'httpRequest' => $this->httpRequestMock, 'storeManager' => $this->storeManager, 'storeCookieManager' => $this->storeCookieManager]);
     $this->storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($this->websiteMock));
     $this->storeManager->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeManager->method('getStore')->willReturn($this->currentStoreMock);
     $this->websiteMock->expects($this->once())->method('getDefaultStore')->will($this->returnValue($this->storeMock));
     $this->storeMock->expects($this->once())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_DEFAULT));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('default');
     $this->currentStoreMock->expects($this->once())->method('getCode')->willReturn('custom_store');
     $this->storeCookieManager->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
     $this->currentStoreMock->expects($this->any())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
 }

作者:pradeep-wagent    项目:magento   
/**
  * Create mock object for context
  */
 private function initContextMock()
 {
     $this->store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock();
     $this->storeManager = $this->getMockBuilder(StoreManager::class)->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock();
     $this->storeManager->expects(static::any())->method('getStore')->willReturn($this->store);
     $this->urlBuilder = $this->getMockBuilder('Magento\\Framework\\UrlInterface')->getMockForAbstractClass();
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMockForAbstractClass();
     $this->context = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template\\Context')->disableOriginalConstructor()->getMock();
     $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
     $this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder);
     $this->context->expects($this->any())->method('getStoreManager')->willReturn($this->storeManager);
 }

作者:pradeep-wagent    项目:magento   
public function testDispatchStoreParameterIsArray()
 {
     $this->storeMock->expects($this->once())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_DEFAULT));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('default');
     $this->currentStoreMock->expects($this->once())->method('getCode')->willReturn('custom_store');
     $store = ['_data' => ['code' => 500]];
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue($store));
     $this->storeManager->expects($this->once())->method('getStore')->with('500')->willReturn($this->currentStoreMock);
     $this->httpContextMock->expects($this->at(0))->method('setValue')->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
     /** Make sure that current currency is taken from current store if no value is provided in session */
     $this->httpContextMock->expects($this->at(1))->method('setValue')->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT);
     $result = $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock);
     $this->assertEquals('ExpectedValue', $result);
 }

作者:aies    项目:magento   
/**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         $this->value = $this->resourceRuleFactory->create()->getRulePrice($this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
         $this->value = $this->value ? floatval($this->value) : false;
     }
     return $this->value;
 }

作者:shabbirvividad    项目:magento   
/**
  * Delete Expired Captcha Images
  *
  * @return \Magento\Captcha\Model\Observer
  */
 public function deleteExpiredImages()
 {
     foreach ($this->_storeManager->getWebsites() as $website) {
         $this->_deleteExpiredImagesForWebsite($this->_helper, $website, $website->getDefaultStore());
     }
     $this->_deleteExpiredImagesForWebsite($this->_adminHelper);
     return $this;
 }

作者:pradeep-wagent    项目:magento   
public function testGetRelayUrl()
 {
     $baseUrl = 'http://base.url/';
     $defaultStoreMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $defaultStoreMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)->willReturn($baseUrl);
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn(null);
     $this->storeManagerMock->expects($this->once())->method('getStores')->willReturn([$defaultStoreMock]);
     $this->assertSame('http://base.url/authorizenet/directpost_payment/backendResponse', $this->dataHelper->getRelayUrl());
 }

作者:eonsequeir    项目:HS_Al   
/**
  * Get urls of all the stores in the magento install.
  *
  * @return array
  */
 public function getAllUrls()
 {
     $urls = [];
     $stores = $this->storeManager->getStores(false);
     foreach ($stores as $store) {
         $urls[] = $store->getBaseUrl();
     }
     return $urls;
 }

作者:pradeep-wagent    项目:magento   
public function testGetPreviewImageUrl()
 {
     /** @var $theme \Magento\Theme\Model\Theme|\PHPUnit_Framework_MockObject_MockObject */
     $theme = $this->getMock('Magento\\Theme\\Model\\Theme', ['getPreviewImage', 'isPhysical', '__wakeup'], [], '', false);
     $theme->expects($this->any())->method('getPreviewImage')->will($this->returnValue('image.png'));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://localhost/'));
     $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->assertEquals('http://localhost/theme/preview/image.png', $this->model->getPreviewImageUrl($theme));
 }

作者:pradeep-wagent    项目:magento   
/**
  * @dataProvider getStoreDataProvider
  * @param $websiteId
  * @param $websiteStoreId
  * @param $storeId
  * @param $result
  */
 public function testGetStoreId($websiteId, $websiteStoreId, $storeId, $result)
 {
     if ($websiteId * 1) {
         $this->_model->setWebsiteId($websiteId);
         $website = new \Magento\Framework\DataObject(['store_ids' => [$websiteStoreId]]);
         $this->_storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($website));
     } else {
         $this->_model->setStoreId($storeId);
         $this->_storeManager->expects($this->never())->method('getWebsite');
     }
     $this->assertEquals($result, $this->_model->getStoreId());
 }

作者:Doabilit    项目:magento2de   
/**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         if ($this->product->hasData(self::PRICE_CODE)) {
             $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false;
         } else {
             $this->value = $this->getRuleResource()->getRulePrice($this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
             $this->value = $this->value ? floatval($this->value) : false;
             if ($this->value) {
                 $this->value = $this->priceCurrency->convertAndRound($this->value);
             }
         }
     }
     return $this->value;
 }

作者:whoopl    项目:magento2-testin   
/**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)
 {
     $option->setStoreId($this->storeManager->getStore()->getId());
     $option->setParentId($product->getId());
     $optionId = $option->getOptionId();
     $linksToAdd = [];
     if (!$optionId) {
         $option->setDefaultTitle($option->getTitle());
         if (is_array($option->getProductLinks())) {
             $linksToAdd = $option->getProductLinks();
         }
     } else {
         $optionCollection = $this->type->getOptionsCollection($product);
         /** @var \Magento\Bundle\Model\Option $existingOption */
         $existingOption = $optionCollection->getItemById($option->getOptionId());
         if (!isset($existingOption) || !$existingOption->getOptionId()) {
             throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
         }
         $option->setData(array_merge($existingOption->getData(), $option->getData()));
         $this->updateOptionSelection($product, $option);
     }
     try {
         $this->optionResource->save($option);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save option'), $e);
     }
     /** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
     foreach ($linksToAdd as $linkedProduct) {
         $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
     }
     return $option->getOptionId();
 }

作者:kidaa3    项目:magento2-platforms   
public function testGetSwatchMediaUrl()
 {
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', ['getBaseUrl'], [], '', false);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
     $storeMock->expects($this->once())->method('getBaseUrl')->with('media')->willReturn('http://url/pub/media/');
     $result = $this->mediaHelperObject->getSwatchMediaUrl();
     $this->assertEquals($result, 'http://url/pub/media/attribute/swatch');
 }

作者:tingyee    项目:magento   
public function testAroundDispatchNoStoreCookie()
 {
     $storeCode = null;
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
     $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
     $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }

作者:vv-tea    项目:food   
public function testBeforeDispatchNoStoreCookie()
 {
     $storeCode = null;
     $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
     $this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
     $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
     $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
 }

作者:Doabilit    项目:magento2de   
public function testSendNewAccountEmailWithoutStoreId()
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $website->expects($this->once())->method('getStoreIds')->will($this->returnValue([1, 2, 3, 4]));
     $this->_storeManager->expects($this->once())->method('getWebsite')->with(1)->will($this->returnValue($website));
     $this->_storeManager->expects($this->once())->method('getStore')->with(1)->will($this->returnValue($store));
     $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->_attribute));
     $this->_attribute->expects($this->exactly(3))->method('getIsVisible')->will($this->returnValue(true));
     $methods = ['setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', 'setFrom', 'addTo'];
     foreach ($methods as $method) {
         $this->_transportBuilderMock->expects($this->once())->method($method)->will($this->returnSelf());
     }
     $transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $transportMock->expects($this->once())->method('sendMessage')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($transportMock));
     $this->_model->setData(['website_id' => 1, 'store_id' => 1, 'email' => 'email@example.com', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'middlename' => 'MiddleName', 'prefix' => 'Prefix']);
     $this->_model->sendNewAccountEmail('registered');
 }

作者:dotmaile    项目:dotmailer-magento2-extensio   
/**
  * Execute method.
  */
 public function execute()
 {
     $code = $this->getRequest()->getParam('code', false);
     $userId = $this->getRequest()->getParam('state');
     //load admin user
     $adminUser = $this->adminUser->create()->load($userId);
     //app code and admin user must be present
     if ($code && $adminUser->getId()) {
         $clientId = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID);
         $clientSecret = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID);
         //callback uri if not set custom
         $redirectUri = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true);
         $redirectUri .= 'connector/email/callback';
         $data = 'client_id=' . $clientId . '&client_secret=' . $clientSecret . '&redirect_uri=' . $redirectUri . '&grant_type=authorization_code' . '&code=' . $code;
         //callback url
         $url = $this->config->getTokenUrl();
         //@codingStandardsIgnoreStart
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         curl_setopt($ch, CURLOPT_POST, count($data));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
         $response = json_decode(curl_exec($ch));
         if ($response === false) {
             $this->helper->error('Error Number: ' . curl_errno($ch), []);
         }
         if (isset($response->error)) {
             $this->helper->error('OAUTH failed ' . $response->error, []);
         } elseif (isset($response->refresh_token)) {
             //save the refresh token to the admin user
             $adminUser->setRefreshToken($response->refresh_token)->save();
         }
         //@codingStandardsIgnoreEnd
     }
     //redirect to automation index page
     $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio'));
 }


问题


面经


文章

微信
公众号

扫码关注公众号