/** * Js configuration array for autocomplete * * @return array */ public function getJsConfig() { $config = ["*" => ['Magento_Ui/js/core/app' => ['components' => ['autocompleteInjection' => ['component' => 'Mirasvit_SearchAutocomplete/js/injection', 'config' => []], 'autocomplete' => ['component' => 'Mirasvit_SearchAutocomplete/js/autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['query' => $this->searchHelper->getEscapedQueryText(), 'priceFormat' => $this->localeFormat->getPriceFormat()]], 'autocompleteProvider' => ['component' => 'Mirasvit_SearchAutocomplete/js/provider', 'config' => ['url' => $this->getUrl('searchautocomplete/ajax/suggest', ['_secure' => $this->getRequest()->isSecure()]), 'delay' => $this->config->getDelay(), 'minSearchLength' => $this->config->getMinChars()]], 'autocompleteNavigation' => ['component' => 'Mirasvit_SearchAutocomplete/js/navigation', 'autocomplete' => 'autocomplete']]]]]; if ($this->config->isShowPopularSearches()) { $config['*']['Magento_Ui/js/core/app']['components']['autocompletePopular'] = ['component' => 'Mirasvit_SearchAutocomplete/js/popular', 'autocomplete' => 'autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['enabled' => $this->config->isShowPopularSearches(), 'queries' => $this->config->getPopularSearches()]]; } else { $config['*']['Magento_Ui/js/core/app']['components']['autocompleteRecent'] = ['component' => 'Mirasvit_SearchAutocomplete/js/recent', 'autocomplete' => 'autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['limit' => 5]]; } return $config; }
/** * Append virtual rule and sorting product data. * * @param CategoryDataProvider $dataProvider Data provider. * @param \Closure $proceed Original method. * * @return array */ public function aroundGetData(CategoryDataProvider $dataProvider, \Closure $proceed) { $data = $proceed(); $currentCategory = $dataProvider->getCurrentCategory(); if ($currentCategory->getId() === null || $currentCategory->getLevel() < 2) { $data[$currentCategory->getId()]['use_default']['is_virtual_category'] = true; } $data[$currentCategory->getId()]['sorted_products'] = $this->getProductSavedPositions($currentCategory); $data[$currentCategory->getId()]['product_sorter_load_url'] = $this->getProductSorterLoadUrl($currentCategory); $data[$currentCategory->getId()]['price_format'] = $this->localeFormat->getPriceFormat(); return $data; }
/** * {@inheritdoc} */ public function getConfig() { $quoteId = $this->checkoutSession->getQuote()->getId(); $output['formKey'] = $this->formKey->getFormKey(); $output['customerData'] = $this->getCustomerData(); $output['quoteData'] = $this->getQuoteData(); $output['quoteItemData'] = $this->getQuoteItemData(); $output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn(); $output['selectedShippingMethod'] = $this->getSelectedShippingMethod(); $output['storeCode'] = $this->getStoreCode(); $output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed(); $output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired(); $output['registerUrl'] = $this->getRegisterUrl(); $output['checkoutUrl'] = $this->getCheckoutUrl(); $output['pageNotFoundUrl'] = $this->pageNotFoundUrl(); $output['forgotPasswordUrl'] = $this->getForgotPasswordUrl(); $output['staticBaseUrl'] = $this->getStaticBaseUrl(); $output['priceFormat'] = $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getQuoteCurrencyCode()); $output['basePriceFormat'] = $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getBaseCurrencyCode()); $output['postCodes'] = $this->postCodesConfig->getPostCodes(); $output['imageData'] = $this->imageProvider->getImages($quoteId); $output['defaultCountryId'] = $this->directoryHelper->getDefaultCountry(); $output['totalsData'] = $this->getTotalsData(); $output['shippingPolicy'] = ['isEnabled' => $this->scopeConfig->isSetFlag('shipping/shipping_policy/enable_shipping_policy', ScopeInterface::SCOPE_STORE), 'shippingPolicyContent' => nl2br($this->scopeConfig->getValue('shipping/shipping_policy/shipping_policy_content', ScopeInterface::SCOPE_STORE))]; $output['activeCarriers'] = $this->getActiveCarriers(); $output['originCountryCode'] = $this->getOriginCountryCode(); $output['paymentMethods'] = $this->getPaymentMethods(); $output['autocomplete'] = $this->isAutocompleteEnabled(); return $output; }
/** * Get JSON encoded configuration array which can be used for JS dynamic * price calculation depending on product options * * @return string */ public function getJsonConfig() { $config = array(); if (!$this->hasOptions()) { return $this->_jsonEncoder->encode($config); } $customerId = $this->getCustomerId(); /* @var $product \Magento\Catalog\Model\Product */ $product = $this->getProduct(); $defaultTax = $this->taxCalculationService->getDefaultCalculatedRate($product->getTaxClassId(), $customerId); $currentTax = $this->taxCalculationService->getCalculatedRate($product->getTaxClassId(), $customerId); $tierPrices = array(); $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList(); foreach ($tierPricesList as $tierPrice) { $tierPrices[] = $this->_coreData->currency($tierPrice['price']->getValue(), false, false); } $config = array('productId' => $product->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat(), 'includeTax' => $this->_taxData->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => $this->_taxData->displayPriceIncludingTax(), 'showBothPrices' => $this->_taxData->displayBothPrices(), 'productPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getValue(), false, false), 'productOldPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false, false), 'inclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), false, false), 'exclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(), false, false), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => '_clone', 'oldPlusDisposition' => 0, 'plusDisposition' => 0, 'plusDispositionTax' => 0, 'oldMinusDisposition' => 0, 'minusDisposition' => 0, 'tierPrices' => $tierPrices); $responseObject = new \Magento\Framework\Object(); $this->_eventManager->dispatch('catalog_product_view_config', array('response_object' => $responseObject)); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $option => $value) { $config[$option] = $value; } } return $this->_jsonEncoder->encode($config); }
/** * Get formed config data from calculated options data * * @param Product $product * @param array $options * @return array */ private function getConfigData(Product $product, array $options) { $isFixedPrice = $this->getProduct()->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED; $productAmount = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->getPriceWithoutOption(); $baseProductAmount = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->getAmount(); $config = ['options' => $options, 'selected' => $this->selectedOptions, 'bundleId' => $product->getId(), 'priceFormat' => $this->localeFormat->getPriceFormat(), 'prices' => ['oldPrice' => ['amount' => $isFixedPrice ? $baseProductAmount->getValue() : 0], 'basePrice' => ['amount' => $isFixedPrice ? $productAmount->getBaseAmount() : 0], 'finalPrice' => ['amount' => $isFixedPrice ? $productAmount->getValue() : 0]], 'priceType' => $product->getPriceType(), 'isFixedPrice' => $isFixedPrice]; return $config; }
/** * Get prices javascript format json * * @param null|int|string|Store $store * @return string */ public function getPriceFormat($store = null) { $this->_localeResolver->emulate($store); $priceFormat = $this->_localeFormat->getPriceFormat(); $this->_localeResolver->revert(); if ($store) { $priceFormat['pattern'] = $this->_storeManager->getStore($store)->getCurrentCurrency()->getOutputFormat(); } return $this->jsonHelper->jsonEncode($priceFormat); }
/** * Retrieve Field Format for slider display * * @return array */ protected function getFieldFormat() { $format = $this->localeFormat->getPriceFormat(); $attribute = $this->getFilter()->getAttributeModel(); $format['pattern'] = (string) $attribute->getDisplayPattern(); $format['precision'] = (int) $attribute->getDisplayPrecision(); $format['requiredPrecision'] = (int) $attribute->getDisplayPrecision(); $format['integerRequired'] = (int) $attribute->getDisplayPrecision() > 0; return $format; }
/** * {@inheritdoc} */ public function getConfig() { $configuration = []; $configuration['giftMessage'] = []; $orderLevelGiftMessageConfiguration = (bool) $this->scopeConfiguration->getValue(GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $itemLevelGiftMessageConfiguration = (bool) $this->scopeConfiguration->getValue(GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($orderLevelGiftMessageConfiguration) { $orderMessages = $this->getOrderLevelGiftMessages(); $configuration['isOrderLevelGiftOptionsEnabled'] = (bool) $this->isQuoteVirtual() ? false : true; $configuration['giftMessage']['orderLevel'] = $orderMessages === null ? true : $orderMessages->getData(); } $itemMessages = $this->getItemLevelGiftMessages(); $configuration['isItemLevelGiftOptionsEnabled'] = $itemLevelGiftMessageConfiguration; $configuration['giftMessage']['itemLevel'] = $itemMessages === null ? true : $itemMessages; $configuration['priceFormat'] = $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getQuoteCurrencyCode()); $configuration['storeCode'] = $this->getStoreCode(); $configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn(); $configuration['formKey'] = $this->formKey->getFormKey(); $store = $this->storeManager->getStore(); $configuration['baseUrl'] = $store->isFrontUrlSecure() ? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true) : $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, false); return $configuration; }
/** * Get JSON encoded configuration array which can be used for JS dynamic * price calculation depending on product options * * @return string */ public function getJsonConfig() { /* @var $product \Magento\Catalog\Model\Product */ $product = $this->getProduct(); if (!$this->hasOptions()) { $config = ['productId' => $product->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat()]; return $this->_jsonEncoder->encode($config); } $tierPrices = []; $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList(); foreach ($tierPricesList as $tierPrice) { $tierPrices[] = $this->priceCurrency->convert($tierPrice['price']->getValue()); } $config = ['productId' => $product->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat(), 'prices' => ['oldPrice' => ['amount' => $this->priceCurrency->convert($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue()), 'adjustments' => []], 'basePrice' => ['amount' => $this->priceCurrency->convert($product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount()), 'adjustments' => []], 'finalPrice' => ['amount' => $this->priceCurrency->convert($product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()), 'adjustments' => []]], 'idSuffix' => '_clone', 'tierPrices' => $tierPrices]; $responseObject = new \Magento\Framework\DataObject(); $this->_eventManager->dispatch('catalog_product_view_config', ['response_object' => $responseObject]); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $option => $value) { $config[$option] = $value; } } return $this->_jsonEncoder->encode($config); }
/** * Returns JSON encoded config to be used in JS scripts * * @return string * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getJsonConfig() { /** @var \Magento\Bundle\Model\Option[] $optionsArray */ $optionsArray = $this->getOptions(); $options = array(); $selected = array(); $currentProduct = $this->getProduct(); if ($preConfiguredFlag = $currentProduct->hasPreconfiguredValues()) { $preConfiguredValues = $currentProduct->getPreconfiguredValues(); $defaultValues = array(); } $position = 0; foreach ($optionsArray as $optionItem) { /* @var $optionItem \Magento\Bundle\Model\Option */ if (!$optionItem->getSelections()) { continue; } $optionId = $optionItem->getId(); $option = array('selections' => array(), 'title' => $optionItem->getTitle(), 'isMulti' => in_array($optionItem->getType(), array('multi', 'checkbox')), 'position' => $position++); $selectionCount = count($optionItem->getSelections()); foreach ($optionItem->getSelections() as $selectionItem) { /* @var $selectionItem \Magento\Catalog\Model\Product */ $selectionId = $selectionItem->getSelectionId(); $qty = !($selectionItem->getSelectionQty() * 1) ? '1' : $selectionItem->getSelectionQty() * 1; // recalculate currency $tierPrices = $selectionItem->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE)->getTierPriceList(); foreach ($tierPrices as &$tierPriceInfo) { /** @var \Magento\Framework\Pricing\Amount\Base $price */ $price = $tierPriceInfo['price']; $priceBaseAmount = $price->getBaseAmount(); $priceValue = $price->getValue(); $bundleProductPrice = $this->_productPrice->create(); $priceBaseAmount = $bundleProductPrice->getLowestPrice($currentProduct, $priceBaseAmount); $priceValue = $bundleProductPrice->getLowestPrice($currentProduct, $priceValue); $tierPriceInfo['price'] = $this->priceCurrency->convert($this->_taxData->displayPriceIncludingTax() ? $priceValue : $priceBaseAmount); $tierPriceInfo['exclTaxPrice'] = $this->priceCurrency->convert($priceBaseAmount); $tierPriceInfo['inclTaxPrice'] = $this->priceCurrency->convert($priceValue); } // break the reference with the last element $canApplyMAP = false; $bundleOptionPriceAmount = $currentProduct->getPriceInfo()->getPrice('bundle_option')->getOptionSelectionAmount($selectionItem); $priceInclTax = $bundleOptionPriceAmount->getValue(); $priceExclTax = $bundleOptionPriceAmount->getBaseAmount(); $selection = array('qty' => $qty, 'customQty' => $selectionItem->getSelectionCanChangeQty(), 'inclTaxPrice' => $this->priceCurrency->convert($priceInclTax), 'exclTaxPrice' => $this->priceCurrency->convert($priceExclTax), 'priceType' => $selectionItem->getSelectionPriceType(), 'tierPrice' => $tierPrices, 'name' => $selectionItem->getName(), 'plusDisposition' => 0, 'minusDisposition' => 0, 'canApplyMAP' => $canApplyMAP); $selection['price'] = $this->_taxData->displayPriceIncludingTax() ? $selection['inclTaxPrice'] : $selection['exclTaxPrice']; $responseObject = new \Magento\Framework\Object(); $args = array('response_object' => $responseObject, 'selection' => $selectionItem); $this->_eventManager->dispatch('bundle_product_view_config', $args); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $index => $value) { $selection[$index] = $value; } } $option['selections'][$selectionId] = $selection; if (($selectionItem->getIsDefault() || $selectionCount == 1 && $optionItem->getRequired()) && $selectionItem->isSalable()) { $selected[$optionId][] = $selectionId; } } $options[$optionId] = $option; // Add attribute default value (if set) if ($preConfiguredFlag) { $configValue = $preConfiguredValues->getData('bundle_option/' . $optionId); if ($configValue) { $defaultValues[$optionId] = $configValue; } } } $isFixedPrice = $this->getProduct()->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED; $productAmount = $currentProduct->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->getAmount(); $baseProductAmount = $currentProduct->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->getAmount(); $config = array('options' => $options, 'selected' => $selected, 'bundleId' => $currentProduct->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat(), 'basePrice' => $this->priceCurrency->convert($baseProductAmount->getValue()), 'finalBasePriceInclTax' => $isFixedPrice ? $this->priceCurrency->convert($productAmount->getValue()) : 0, 'finalBasePriceExclTax' => $isFixedPrice ? $this->priceCurrency->convert($productAmount->getBaseAmount()) : 0, 'priceType' => $currentProduct->getPriceType(), 'specialPrice' => $currentProduct->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\SpecialPrice::PRICE_CODE)->getValue(), 'includeTax' => $this->_taxData->priceIncludesTax() ? 'true' : 'false', 'isFixedPrice' => $isFixedPrice); $config['finalPrice'] = $this->_taxData->displayPriceIncludingTax() ? $config['finalBasePriceInclTax'] : $config['finalBasePriceExclTax']; if ($preConfiguredFlag && !empty($defaultValues)) { $config['defaultValues'] = $defaultValues; } return $this->jsonEncoder->encode($config); }
/** * Retrieve price format configuration. * * @return array */ protected function getPriceFormat() { return $this->localeFormat->getPriceFormat(); }
/** * {@inheritdoc} */ public function getConfig() { return ['formKey' => $this->formKey->getFormKey(), 'customerData' => $this->getCustomerData(), 'quoteData' => $this->getQuoteData(), 'quoteItemData' => $this->getQuoteItemData(), 'isCustomerLoggedIn' => $this->isCustomerLoggedIn(), 'selectedShippingMethod' => $this->getSelectedShippingMethod(), 'storeCode' => $this->getStoreCode(), 'isGuestCheckoutAllowed' => $this->isGuestCheckoutAllowed(), 'isCustomerLoginRequired' => $this->isCustomerLoginRequired(), 'registerUrl' => $this->getRegisterUrl(), 'customerAddressCount' => $this->getCustomerAddressCount(), 'forgotPasswordUrl' => $this->getForgotPasswordUrl(), 'staticBaseUrl' => $this->getStaticBaseUrl(), 'priceFormat' => $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getQuoteCurrencyCode()), 'basePriceFormat' => $this->localeFormat->getPriceFormat(null, $this->currencyManager->getDefaultCurrency())]; }
/** * {@inheritdoc} */ public function getConfig() { $quoteId = $this->checkoutSession->getQuote()->getId(); return ['formKey' => $this->formKey->getFormKey(), 'customerData' => $this->getCustomerData(), 'quoteData' => $this->getQuoteData(), 'quoteItemData' => $this->getQuoteItemData(), 'isCustomerLoggedIn' => $this->isCustomerLoggedIn(), 'selectedShippingMethod' => $this->getSelectedShippingMethod(), 'storeCode' => $this->getStoreCode(), 'isGuestCheckoutAllowed' => $this->isGuestCheckoutAllowed(), 'isCustomerLoginRequired' => $this->isCustomerLoginRequired(), 'registerUrl' => $this->getRegisterUrl(), 'customerAddressCount' => $this->getCustomerAddressCount(), 'forgotPasswordUrl' => $this->getForgotPasswordUrl(), 'staticBaseUrl' => $this->getStaticBaseUrl(), 'priceFormat' => $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getQuoteCurrencyCode()), 'basePriceFormat' => $this->localeFormat->getPriceFormat(null, $this->currencyManager->getDefaultCurrency()), 'postCodes' => $this->postCodesConfig->getPostCodes(), 'imageData' => $this->imageProvider->getImages($quoteId), 'countryData' => $this->getCountryData(), 'totalsData' => $this->getTotalsData(), 'shippingRates' => $this->getDefaultShippingRates(), 'shippingPolicy' => ['isEnabled' => $this->scopeConfig->isSetFlag('shipping/shipping_policy/enable_shipping_policy', ScopeInterface::SCOPE_STORE), 'shippingPolicyContent' => nl2br($this->scopeConfig->getValue('shipping/shipping_policy/shipping_policy_content', ScopeInterface::SCOPE_STORE))], 'activeCarriers' => $this->getActiveCarriers(), 'originCountryCode' => $this->getOriginCountryCode(), 'paymentMethods' => $this->getPaymentMethods()]; }