/** * @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); }
/** * 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()); } }
/** * {@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(); }
/** * 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; }
/** * 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; }
/** * {@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); }
/** * {@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; }
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 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(); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * 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(); } }
/** * {@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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * Get list of all available countries * * @return array */ public function getAllOptions() { $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { $options = unserialize($cache); } else { $collection = $this->_countryFactory->create()->getResourceCollection()->loadByStore(); $options = $collection->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheKey); } return $options; }
/** * {@inheritdoc} */ public function getAddress($cartId) { $storeId = $this->storeManager->getStore()->getId(); /** @var \Magento\Sales\Model\Quote $quote */ $quote = $this->quoteLoader->load($cartId, $storeId); 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 = $quote->getShippingAddress(); return $this->addressConverter->convertModelToDataObject($address); }
/** * Retrieve list of filterable attributes * * @return array|\Magento\Catalog\Model\Resource\Product\Attribute\Collection */ public function getList() { $setIds = $this->layer->getProductCollection()->getSetIds(); if (!$setIds) { return array(); } /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */ $collection = $this->collectionFactory->create(); $collection->setItemObjectClass('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->setAttributeSetFilter($setIds)->addStoreLabel($this->storeManager->getStore()->getId())->setOrder('position', 'ASC'); $collection = $this->_prepareAttributeCollection($collection); $collection->load(); return $collection; }
/** * Before save * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if ($object->getId()) { return $this; } if (!$object->hasStoreId()) { $object->setStoreId($this->_storeManager->getStore()->getId()); } if (!$object->hasData('created_in')) { $object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName()); } return $this; }
/** * 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 */ public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false) { if ($store instanceof \Magento\Store\Model\Store) { $oldStore = $this->storeManager->getStore(); $this->storeManager->setCurrentStore($store); } $this->coreRegistry->unregister('rule_data'); $this->coreRegistry->register('rule_data', new \Magento\Framework\Object(array('store_id' => $product->getStoreId(), 'website_id' => $product->getWebsiteId(), 'customer_group_id' => $product->getCustomerGroupId()))); $minPrice = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax); if ($store instanceof \Magento\Store\Model\Store) { $this->storeManager->setCurrentStore($oldStore); } return $minPrice; }
/** * {@inheritdoc} */ public function create(CategoryDataObject $category) { try { $categoryModel = $this->categoryMapper->toModel($category); $parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId(); $parentCategory = $this->categoryFactory->create()->load($parentId); $categoryModel->setPath($parentCategory->getPath()); $this->validateCategory($categoryModel); $categoryModel->save(); } catch (\Exception $e) { throw new CouldNotSaveException('Could not save category: %1', [$e->getMessage()], $e); } return $categoryModel->getId(); }
/** * Prepare Content HTML * * @return string */ protected function _toHtml() { $blockId = $this->getBlockId(); $html = ''; if ($blockId) { $storeId = $this->_storeManager->getStore()->getId(); /** @var \Magento\Cms\Model\Block $block */ $block = $this->_blockFactory->create(); $block->setStoreId($storeId)->load($blockId); if ($block->getIsActive()) { $html = $this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($block->getContent()); } } return $html; }
/** * Set data for response of frontend saveOrder action * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function addAdditionalFieldsToResponseFrontend(\Magento\Framework\Event\Observer $observer) { /* @var $order \Magento\Sales\Model\Order */ $order = $this->_coreRegistry->registry('directpost_order'); if ($order && $order->getId()) { $payment = $order->getPayment(); if ($payment && $payment->getMethod() == $this->_payment->getCode()) { /** @var \Magento\Checkout\Controller\Action $controller */ $controller = $observer->getEvent()->getData('controller_action'); $request = $controller->getRequest(); $response = $controller->getResponse(); $result = $this->_coreData->jsonDecode($response->getBody('default')); if (empty($result['error'])) { $payment = $order->getPayment(); //if success, then set order to session and add new fields $this->_session->addCheckoutOrderIncrementId($order->getIncrementId()); $this->_session->setLastOrderIncrementId($order->getIncrementId()); $requestToAuthorizenet = $payment->getMethodInstance()->generateRequestFromOrder($order); $requestToAuthorizenet->setControllerActionName($request->getControllerName()); $requestToAuthorizenet->setIsSecure((string) $this->_storeManager->getStore()->isCurrentlySecure()); $result['directpost'] = array('fields' => $requestToAuthorizenet->getData()); $response->clearHeader('Location'); $response->representJson($this->_coreData->jsonEncode($result)); } } } return $this; }