예제 #1
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getItems()
 {
     Profiler::start(__METHOD__);
     $items = [];
     /** @var \Magento\Catalog\Model\Product $product */
     foreach ($this->collection as $product) {
         $item = ['sku' => $product->getSku(), 'name' => $product->getName(), 'url' => $product->getProductUrl(), 'description' => null, 'image' => null, 'price' => null, 'rating' => null];
         if ($this->config->isShowShortDescription()) {
             $item['description'] = html_entity_decode(strip_tags($product->getDataUsingMethod('description')));
         }
         $image = false;
         if ($product->getImage() && $product->getImage() != 'no_selection') {
             $image = $product->getImage();
         } elseif ($product->getSmallImage() && $product->getSmallImage() != 'no_selection') {
             $image = $product->getSmallImage();
         }
         if ($this->config->isShowImage() && $image) {
             $item['image'] = $this->imageHelper->init($product, false)->setImageFile($image)->resize(65 * 2, 80 * 2)->getUrl();
         }
         if ($this->config->isShowPrice()) {
             $item['price'] = $this->catalogHelper->getTaxPrice($product, $product->getFinalPrice());
             $item['price'] = $this->pricingHelper->currency($item['price'], false, false);
         }
         if ($this->config->isShowRating()) {
             $item['rating'] = $this->reviewRenderer->getReviewsSummaryHtml($product, ReviewRendererInterface::SHORT_VIEW);
         }
         $items[] = $item;
     }
     Profiler::stop(__METHOD__);
     return $items;
 }
 /**
  * Basket items.
  *
  * @return mixed
  */
 public function getBasketItems()
 {
     $params = $this->getRequest()->getParams();
     if (!isset($params['quote_id']) || !isset($params['code'])) {
         $this->helper->log('Basket no quote id or code is set');
         return false;
     }
     $quoteId = $params['quote_id'];
     $quoteModel = $this->quoteFactory->create()->loadByIdWithoutStore($quoteId);
     //check for any quote for this email, don't want to render further
     if (!$quoteModel->getId()) {
         $this->helper->log('no quote found for ' . $quoteId);
         return false;
     }
     if (!$quoteModel->getIsActive()) {
         $this->helper->log('Cart is not active : ' . $quoteId);
         return false;
     }
     $this->quote = $quoteModel;
     //Start environment emulation of the specified store
     $storeId = $quoteModel->getStoreId();
     $appEmulation = $this->emulationFactory->create();
     $appEmulation->startEnvironmentEmulation($storeId);
     $quoteItems = $quoteModel->getAllItems();
     $itemsData = [];
     foreach ($quoteItems as $quoteItem) {
         //skip configurable products
         if ($quoteItem->getParentItemId() != null) {
             continue;
         }
         $_product = $quoteItem->getProduct();
         $inStock = $_product->isInStock() ? 'In Stock' : 'Out of stock';
         $total = $this->priceHelper->currency($quoteItem->getPrice());
         $productUrl = $_product->getProductUrl();
         $grandTotal = $this->priceHelper->currency($this->getGrandTotal());
         $itemsData[] = ['grandTotal' => $grandTotal, 'total' => $total, 'inStock' => $inStock, 'productUrl' => $productUrl, 'product' => $_product, 'qty' => $quoteItem->getQty()];
     }
     return $itemsData;
 }
예제 #3
0
 /**
  * Return object value by key
  *
  * @param object $object
  * @param string $key
  * @param string $dataKey
  * @param string $value
  * @param int    $storeId
  * @return float|string
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function checkForConvert($object, $key, $dataKey, $value, $storeId)
 {
     if ($key == 'product' || $key == 'category') {
         if ($key == 'product') {
             $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $dataKey);
         } else {
             $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Category::ENTITY, $dataKey);
         }
         if ($storeId) {
             $attribute->setStoreId($storeId);
         }
         if ($attribute->getId() > 0) {
             try {
                 $valueId = $object->getDataUsingMethod($dataKey);
                 $value = $attribute->getFrontend()->getValue($object);
             } catch (\Exception $e) {
                 //possible that some extension is removed, but we have it attribute with source in database
                 $value = '';
             }
             if ($value == 'No' && $valueId == '') {
                 $value = '';
             }
             switch ($dataKey) {
                 case 'price':
                     $value = $this->pricingHelper->currency($value, true, false);
                     break;
                 case 'special_price':
                     $value = $this->pricingHelper->currency($value, true, false);
                     break;
             }
         } else {
             switch ($dataKey) {
                 case 'final_price':
                     $value = $this->pricingHelper->currency($value, true, false);
                     break;
             }
         }
     }
     if (is_array($value)) {
         if (isset($value['label'])) {
             $value = $value['label'];
         } else {
             $value = '';
         }
     }
     return $value;
 }
예제 #4
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 = [];
     $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()) : [];
     if ($bundleOptionsIds) {
         /** @var \Magento\Bundle\Model\ResourceModel\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 = ['label' => $bundleOption->getTitle(), 'value' => []];
                     $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->pricingHelper->currency($this->getSelectionFinalPrice($item, $bundleSelection));
                         }
                     }
                     if ($option['value']) {
                         $options[] = $option;
                     }
                 }
             }
         }
     }
     return $options;
 }
예제 #5
0
 /**
  * Get price configuration
  *
  * @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
  * @return array
  */
 protected function _getPriceConfiguration($option)
 {
     $optionPrice = $this->pricingHelper->currency($option->getPrice(true), false, false);
     $data = ['prices' => ['oldPrice' => ['amount' => $this->pricingHelper->currency($option->getRegularPrice(), false, false), 'adjustments' => []], 'basePrice' => ['amount' => $this->_catalogData->getTaxPrice($option->getProduct(), $optionPrice, false, null, null, null, null, null, false)], 'finalPrice' => ['amount' => $this->_catalogData->getTaxPrice($option->getProduct(), $optionPrice, true, null, null, null, null, null, false)]], 'type' => $option->getPriceType(), 'name' => $option->getTitle()];
     return $data;
 }
예제 #6
0
 public function testCurrency()
 {
     $price = 10.0;
     $priceHtml = '<span class="price">$10.00</span>';
     $this->assertEquals($priceHtml, $this->helper->currency($price));
 }