Ejemplo n.º 1
0
 public function testCurrency()
 {
     $price = 10.0;
     $priceHtml = '<span class="price">$10.00</span>';
     $this->assertEquals($priceHtml, $this->_helper->currency($price));
     $this->assertEquals($priceHtml, $this->_helper->formatCurrency($price));
 }
Ejemplo n.º 2
0
 /**
  * @param string $amount
  * @param bool $format
  * @param bool $includeContainer
  * @param string $result
  * @dataProvider currencyDataProvider
  */
 public function testCurrency($amount, $format, $includeContainer, $result)
 {
     if ($format) {
         $this->priceCurrency->expects($this->once())->method('convertAndFormat')->with($amount, $includeContainer)->will($this->returnValue($result));
     } else {
         $this->priceCurrency->expects($this->once())->method('convert')->with($amount)->will($this->returnValue($result));
     }
     $this->assertEquals($result, $this->model->currency($amount, $format, $includeContainer));
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * Retrieve credit cards info
  *
  * @return array
  */
 public function getCards()
 {
     $cardsData = $this->getMethod()->getCardsStorage()->getCards();
     $cards = array();
     if (is_array($cardsData)) {
         foreach ($cardsData as $cardInfo) {
             $data = array();
             if ($cardInfo->getProcessedAmount()) {
                 $amount = $this->_coreData->currency($cardInfo->getProcessedAmount(), true, false);
                 $data[__('Processed Amount')] = $amount;
             }
             if ($cardInfo->getBalanceOnCard() && is_numeric($cardInfo->getBalanceOnCard())) {
                 $balance = $this->_coreData->currency($cardInfo->getBalanceOnCard(), true, false);
                 $data[__('Remaining Balance')] = $balance;
             }
             $cardInfo->setMethodInstance($this->getInfo()->getMethodInstance());
             $this->setCardInfoObject($cardInfo);
             $cards[] = array_merge($this->getSpecificInformation(), $data);
             $this->unsCardInfoObject();
             $this->_paymentSpecificInformation = null;
         }
     }
     if ($this->getInfo()->getCcType() && $this->_isCheckoutProgressBlockFlag) {
         $cards[] = $this->getSpecificInformation();
     }
     return $cards;
 }
Ejemplo n.º 5
0
 /**
  * Get price configuration
  *
  * @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
  * @return array
  */
 protected function _getPriceConfiguration($option)
 {
     $data = array();
     $data['price'] = $this->_coreData->currency($option->getPrice(true), false, false);
     $data['oldPrice'] = $this->_coreData->currency($option->getPrice(false), false, false);
     $data['priceValue'] = $option->getPrice(false);
     $data['type'] = $option->getPriceType();
     $data['exclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], false);
     $data['inclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], true);
     return $data;
 }
Ejemplo n.º 6
0
 /**
  * Get links price config
  *
  * @return array
  */
 protected function getLinksConfig()
 {
     $finalPrice = $this->getProduct()->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
     $linksConfig = [];
     foreach ($this->getLinks() as $link) {
         $amount = $finalPrice->getCustomAmount($link->getPrice());
         $price = $this->coreData->currency($link->getPrice(), false, false);
         $linksConfig[$link->getId()] = ['price' => $price, 'oldPrice' => $price, 'inclTaxPrice' => $this->coreData->currency($amount->getValue(), false, false), 'exclTaxPrice' => $this->coreData->currency($amount->getBaseAmount(), false, false)];
     }
     return $linksConfig;
 }
Ejemplo n.º 7
0
 /**
  * Get bundled selections (slections-products collection)
  *
  * Returns array of options objects.
  * Each option object will contain array of selections objects
  *
  * @param ItemInterface $item
  * @return array
  */
 public function getBundleOptions(ItemInterface $item)
 {
     $options = array();
     $product = $item->getProduct();
     /** @var \Magento\Bundle\Model\Product\Type $typeInstance */
     $typeInstance = $product->getTypeInstance();
     // get bundle options
     $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
     $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
     if ($bundleOptionsIds) {
         /** @var \Magento\Bundle\Model\Resource\Option\Collection $optionsCollection */
         $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
         // get and add bundle selections collection
         $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
         $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
         if (!empty($bundleSelectionIds)) {
             $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product);
             $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
             foreach ($bundleOptions as $bundleOption) {
                 if ($bundleOption->getSelections()) {
                     $option = array('label' => $bundleOption->getTitle(), 'value' => array());
                     $bundleSelections = $bundleOption->getSelections();
                     foreach ($bundleSelections as $bundleSelection) {
                         $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
                         if ($qty) {
                             $option['value'][] = $qty . ' x ' . $this->_escaper->escapeHtml($bundleSelection->getName()) . ' ' . $this->_coreData->currency($this->getSelectionFinalPrice($item, $bundleSelection));
                         }
                     }
                     if ($option['value']) {
                         $options[] = $option;
                     }
                 }
             }
         }
     }
     return $options;
 }