/** * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode()); $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode()); return $proceed($request); }
/** * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @throws \Magento\Framework\App\InitException */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->_storeManager->getStore()->getIsActive()) { throw new \Magento\Framework\App\InitException('Current store is not active.'); } return $proceed($request); }
/** * Minimal price for "regular" user * * @param \Magento\Catalog\Model\Product $product * @param null|\Magento\Store\Model\Store $store Store view * @param bool $inclTax * @return null|float * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false) { // Workaround to avoid loading stock status by admin's website if ($store instanceof \Magento\Store\Model\Store) { $oldStore = $this->storeManager->getStore(); $this->storeManager->setCurrentStore($store); } $subProducts = $product->getTypeInstance()->getAssociatedProducts($product); if ($store instanceof \Magento\Store\Model\Store) { $this->storeManager->setCurrentStore($oldStore); } if (!count($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; }
/** * {@inheritdoc} */ public function setAddress($cartId, $addressData) { /** @var \Magento\Sales\Model\Quote $quote */ $quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId()); if ($quote->isVirtual()) { throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping address is not applicable'); } /** @var \Magento\Sales\Model\Quote\Address $address */ $address = $this->quoteAddressFactory->create(); $this->addressValidator->validate($addressData); if ($addressData->getId()) { $address->load($addressData->getId()); } $address = $this->addressConverter->convertDataObjectToModel($addressData, $address); $address->setSameAsBilling(0); $quote->setShippingAddress($address); $quote->setDataChanges(true); try { $quote->save(); } catch (\Exception $e) { $this->logger->logException($e); throw new InputException('Unable to save address. Please, check input data.'); } return $quote->getShippingAddress()->getId(); }
public function testProcessWithoutStoreCode() { $path = 'rest/V1/customerAccounts/createCustomer'; $result = $this->pathProcessor->process($path); $this->assertEquals('/V1/customerAccounts/createCustomer', $result); $this->assertEquals('default', $this->storeManager->getStore()->getCode()); }
/** * {@inheritdoc} */ public function getAddress($cartId) { $storeId = $this->storeManager->getStore()->getId(); /** @var \Magento\Sales\Model\Quote\Address $address */ $address = $this->quoteLoader->load($cartId, $storeId)->getBillingAddress(); return $this->addressConverter->convertModelToDataObject($address); }
public function testSetNotIntStoreId() { $this->_storeManagerInterface->expects($this->once())->method('getStore'); $store = $this->_model->setStoreId('test'); $storeId = $store->getStoreId(); $this->assertEquals(0, $storeId); }
/** * {@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(); }
/** * Run action * * @return void */ public function run() { $this->_lastRecord = $this->_timestamp($this->_round($this->getLastRecordDate())); foreach ($this->_storeManager->getStores(false) as $store) { $this->_process($store->getId()); } }
/** * Display search result * * @return void */ public function execute() { /* @var $query \Magento\CatalogSearch\Model\Query */ $query = $this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->getQuery(); $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->getLayout()->initMessages(); $this->_view->renderLayout(); if (!$this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) { $query->save(); } } else { $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } }
/** * @param \Magento\Customer\Model\Config\Share $configShare * @param \Magento\Framework\StoreManagerInterface $storeManager * @param string $namespace * @param array $data */ public function __construct(\Magento\Customer\Model\Config\Share $configShare, \Magento\Framework\StoreManagerInterface $storeManager, $namespace = 'customer', array $data = array()) { if ($configShare->isWebsiteScope()) { $namespace .= '_' . $storeManager->getWebsite()->getCode(); } parent::__construct($namespace, $data); }
/** * {@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; }
/** * 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(); } } } }
/** * Get url for config settings where base url option can be changed * * @return string */ protected function _getConfigUrl() { $output = ''; $defaultUnsecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default'); $defaultSecure = $this->_config->getValue(\Magento\Store\Model\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', array('section' => 'web')); } else { /** @var $dataCollection \Magento\Core\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', array('section' => 'web', 'store' => $code)); break; } elseif ($data->getScope() == 'websites') { $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'website' => $code)); break; } } } return $output; }
/** * Prepare data before save * * @param \Magento\Framework\Object $object * @return $this */ protected function _beforeSave($object) { if (!$object->getData($this->getAttribute()->getAttributeCode())) { $object->setData($this->getAttribute()->getAttributeCode(), $this->_storeManager->getStore()->getId()); } return $this; }
/** * Check if URL is internal * * @param string $url * @return bool */ protected function _isInternal($url) { if (strpos($url, 'http') === false) { return false; } $currentStore = $this->_storeManager->getStore(); return strpos($url, $currentStore->getBaseUrl()) === 0 || strpos($url, $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true)) === 0; }
/** * {@inheritdoc} * @throws \Magento\Framework\App\InitException */ public function getScope($scopeId = null) { $scope = $this->_storeManager->getStore($scopeId); if (!$scope instanceof \Magento\Framework\App\ScopeInterface) { throw new \Magento\Framework\App\InitException('Invalid scope object'); } return $scope; }
/** * Return image url * * @param \Magento\Framework\Object $object * @return string|null */ public function getUrl($object) { $url = false; if ($image = $object->getData($this->getAttribute()->getAttributeCode())) { $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . self::IMAGE_PATH_SEGMENT . $image; } return $url; }
/** * Test for getAllOptions method * * @param $cachedDataSrl * @param $cachedDataUnsrl * * @dataProvider testGetAllOptionsDataProvider */ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl) { $this->storeMock->expects($this->once())->method('getCode')->will($this->returnValue('store_code')); $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); $this->cacheConfig->expects($this->once())->method('load')->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))->will($this->returnValue($cachedDataSrl)); $countryOfManufacture = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture', ['storeManager' => $this->storeManagerMock, 'configCacheType' => $this->cacheConfig]); $this->assertEquals($cachedDataUnsrl, $countryOfManufacture->getAllOptions()); }
/** * Get list of required Agreement Ids * * @return int[] */ public function getRequiredAgreementIds() { if (!$this->scopeConfig->isSetFlag(self::PATH_ENABLED, ScopeInterface::SCOPE_STORE)) { return []; } else { return $this->agreementCollectionFactory->create()->addStoreFilter($this->storeManager->getStore()->getId())->addFieldToFilter('is_active', 1)->getAllIds(); } }
/** * @return bool|string */ protected function _getUrl() { $url = false; if ($this->getValue()) { $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/category/' . $this->getValue(); } return $url; }
/** * Returns url to product image * * @param \Magento\Catalog\Model\Product $product * * @return string|false */ public function getUrl($product) { $image = $product->getData($this->getAttribute()->getAttributeCode()); $url = false; if (!empty($image)) { $url = $this->_storeManager->getStore($product->getStore())->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/' . $image; } return $url; }
/** * {@inheritdoc} */ public function get($cartId) { $storeId = $this->storeManager->getStore()->getId(); /** @var \Magento\Sales\Model\Quote $quote */ $quote = $this->quoteLoader->load($cartId, $storeId); $data = [Coupon::COUPON_CODE => $quote->getCouponCode()]; $output = $this->couponBuilder->populateWithArray($data)->create(); return $output; }
/** * Load quote with different methods * * @param string $loadMethod * @param string $loadField * @param int $identifier * @return Quote * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function loadQuote($loadMethod, $loadField, $identifier) { $quote = $this->quoteFactory->create(); $quote->setStoreId($this->storeManager->getStore()->getId())->{$loadMethod}($identifier); if (!$quote->getId() || !$quote->getIsActive()) { throw NoSuchEntityException::singleField($loadField, $identifier); } return $quote; }
/** * Return reports global configuration * * @return string */ public function getGlobalConfig() { $dom = new \DOMDocument(); $dom->load($this->_moduleReader->getModuleDir('etc', 'Magento_Reports') . '/flexConfig.xml'); $baseUrl = $dom->createElement('baseUrl'); $baseUrl->nodeValue = $this->_storeManager->getBaseUrl(); $dom->documentElement->appendChild($baseUrl); return $dom->saveXML(); }
/** * Get cart by id * * @param int $cartId * @return Quote * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($cartId) { $quote = $this->quoteFactory->create(); $quote->setStoreId($this->storeManager->getStore()->getId())->load($cartId); if (!$quote->getId() || !$quote->getIsActive()) { throw NoSuchEntityException::singleField('cartId', $cartId); } return $quote; }
/** * Log out user and redirect him to new admin custom url * * @return void * @SuppressWarnings(PHPMD.ExitExpression) */ public function afterCustomUrlChanged() { if (is_null($this->_coreRegistry->registry('custom_admin_path_redirect'))) { return; } $this->_authSession->destroy(); $route = $this->_backendData->getAreaFrontName(); $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse(); exit(0); }
public function testConvertWithStoreCode() { $amount = 5.6; $storeCode = 2; $convertedAmount = 9.300000000000001; $currency = $this->getCurrentCurrencyMock(); $baseCurrency = $this->getBaseCurrencyMock($amount, $convertedAmount, $currency); $store = $this->getStoreMock($baseCurrency); $this->storeManager->expects($this->once())->method('getStore')->with($storeCode)->will($this->returnValue($store)); $this->assertEquals($convertedAmount, $this->priceCurrency->convert($amount, $storeCode, $currency)); }
/** * Update secure value, set it to store setting if it has no explicit value assigned. * * @return void */ private function updateSecureValue() { if (null === $this->get(self::KEY_SECURE)) { $store = $this->storeManager->getStore(); if (empty($store)) { $this->set(self::KEY_SECURE, true); } else { $this->set(self::KEY_SECURE, $store->isCurrentlySecure()); } } }
/** * Filter collections by stores * * @param mixed $store * @param bool $withAdmin * @return $this */ public function addStoreFilter($store, $withAdmin = true) { if (!is_array($store)) { $store = array($this->_storeManager->getStore($store)->getId()); } if ($withAdmin) { $store[] = 0; } $this->addFieldToFilter('store_id', array('in' => $store)); return $this; }