/** * @return array */ public function getCartItems() { if (!isset(self::$quoteItemsData)) { self::$quoteItemsData = []; $displayPriceWithTax = $this->rejoinerHelper->getTrackPriceWithTax(); if ($quote = $this->getQuote()) { $categories = []; /** @var \Magento\Quote\Model\Quote $quote */ /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($quote->getAllItems() as $item) { $categories = array_merge($categories, $item->getProduct()->getCategoryIds()); } /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */ $categoryCollection = $this->categoryCollectionFactory->create(); $categoriesArray = $categoryCollection->addAttributeToSelect('name')->addFieldToFilter('entity_id', ['in' => $categories])->load()->getItems(); $imageWidth = $this->rejoinerHelper->getImageWidth(); $imageHeight = $this->rejoinerHelper->getImageHeight(); foreach ($quote->getAllVisibleItems() as $item) { $product = $item->getProduct(); $productCategories = $this->rejoinerHelper->getProductCategories($product, $categoriesArray); $imageUrl = $this->imageHelper->init($product, 'category_page_grid')->resize($imageWidth, $imageHeight)->getUrl(); if ($displayPriceWithTax) { $productPrice = $item->getPriceInclTax(); $rowTotal = $item->getRowTotalInclTax(); } else { $productPrice = $item->getPrice(); $rowTotal = $item->getRowTotal(); } $newItem = ['name' => $item->getName(), 'image_url' => $imageUrl, 'price' => (string) $this->rejoinerHelper->convertPriceToCents($productPrice), 'product_id' => (string) $item->getSku(), 'item_qty' => (string) $item->getQty(), 'qty_price' => (string) $this->rejoinerHelper->convertPriceToCents($rowTotal), 'product_url' => (string) $product->getProductUrl(), 'category' => $productCategories]; self::$quoteItemsData[] = $newItem; } } } return self::$quoteItemsData; }
/** * @param $products * @return array */ public function getListValues($ids) { $values = []; $searchCriteria = $this->_criteriaBuilder->addFilter('entity_id', $ids, 'in')->create(); $products = $this->_productRepository->getList($searchCriteria); foreach ($products->getItems() as $product) { $image = $this->_imageHelper->init($product, 'product_page_image_small')->getUrl(); $price = $product->getFinalPrice(); if ($price == 0 && $product->getTypeId() == 'grouped') { $children = $product->getTypeInstance()->getAssociatedProducts($product); foreach ($children as $child) { if ($child->getPrice() < $price || $price == 0) { $price = $child->getPrice(); } } } $value = array(); $value['escape_name'] = $this->escapeHtml($product->getName()); $value['name'] = $product->getName(); $value['url'] = $product->getProductUrl(); $value['price'] = $this->_priceCurrency->format($price, false); $value['image'] = $image; $values[] = $value; } return $values; }
/** * Retrieve collection of gallery images * * @param \Magento\Catalog\Api\Data\ProductInterface $product * @return \Magento\Catalog\Model\Product\Image[]|null */ public function getGalleryImages(\Magento\Catalog\Api\Data\ProductInterface $product) { $images = $product->getMediaGalleryImages(); if ($images instanceof \Magento\Framework\Data\Collection) { foreach ($images as $image) { /** @var $image \Magento\Catalog\Model\Product\Image */ $image->setData('small_image_url', $this->imageHelper->init($product, 'product_page_image_small')->setImageFile($image->getFile())->getUrl()); $image->setData('medium_image_url', $this->imageHelper->init($product, 'product_page_image_medium')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl()); $image->setData('large_image_url', $this->imageHelper->init($product, 'product_page_image_large')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl()); } } return $images; }
/** * {@inheritdoc} */ public function getRssData() { $storeModel = $this->storeManager->getStore($this->getStoreId()); $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'new_products']); $title = __('New Products from %1', $storeModel->getFrontendName()); $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang]; foreach ($this->rssModel->getProductsCollection($this->getStoreId()) as $item) { /** @var $item \Magento\Catalog\Model\Product */ $item->setAllowedInRss(true); $item->setAllowedPriceInRss(true); $this->_eventManager->dispatch('rss_catalog_new_xml_callback', ['row' => $item->getData(), 'product' => $item]); if (!$item->getAllowedInRss()) { continue; } $allowedPriceInRss = $item->getAllowedPriceInRss(); $description = ' <table><tr> <td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td> <td style="text-decoration:none;">%s %s</td> </tr></table> '; $description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'thumbnail')->resize(75, 75), $item->getDescription(), $allowedPriceInRss ? $this->renderPriceHtml($item) : ''); $data['entries'][] = ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description]; } return $data; }
/** * Get RSS feed items * * @return array */ public function getRssData() { $wishlist = $this->getWishlist(); if ($wishlist->getId()) { $data = $this->getHeader(); /** @var $wishlistItem \Magento\Wishlist\Model\Item */ foreach ($wishlist->getItemCollection() as $wishlistItem) { /* @var $product \Magento\Catalog\Model\Product */ $product = $wishlistItem->getProduct(); $productUrl = $this->wishlistBlock->getProductUrl($product, ['_rss' => true]); $product->setAllowedInRss(true); $product->setAllowedPriceInRss(true); $product->setProductUrl($productUrl); $args = ['product' => $product]; $this->eventManager->dispatch('rss_wishlist_xml_callback', $args); if (!$product->getAllowedInRss()) { continue; } $description = '<table><tr><td><a href="' . $productUrl . '"><img src="' . $this->imageHelper->init($product, 'rss_thumbnail')->getUrl() . '" border="0" align="left" height="75" width="75"></a></td>' . '<td style="text-decoration:none;">' . $this->outputHelper->productAttribute($product, $product->getShortDescription(), 'short_description') . '<p>'; if ($product->getAllowedPriceInRss()) { $description .= $this->getProductPriceHtml($product); } $description .= '</p>'; if (trim($product->getDescription()) != '') { $description .= '<p>' . __('Comment:') . ' ' . $this->outputHelper->productAttribute($product, $product->getDescription(), 'description') . '<p>'; } $description .= '</td></tr></table>'; $data['entries'][] = ['title' => $product->getName(), 'link' => $productUrl, 'description' => $description]; } } else { $data = ['title' => __('We cannot retrieve the Wish List.'), 'description' => __('We cannot retrieve the Wish List.'), 'link' => $this->urlBuilder->getUrl(), 'charset' => 'UTF-8']; } return $data; }
/** * {@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; }
/** * {@inheritdoc} */ public function getRssData() { try { $category = $this->categoryRepository->get($this->getRequest()->getParam('cid')); } catch (NoSuchEntityException $e) { return ['title' => 'Category Not Found', 'description' => 'Category Not Found', 'link' => $this->getUrl(''), 'charset' => 'UTF-8']; } $category->setIsAnchor(true); $newUrl = $category->getUrl(); $title = $category->getName(); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8']; /** @var $product \Magento\Catalog\Model\Product */ foreach ($this->rssModel->getProductCollection($category, $this->getStoreId()) as $product) { $product->setAllowedInRss(true); $product->setAllowedPriceInRss(true); $this->_eventManager->dispatch('rss_catalog_category_xml_callback', ['product' => $product]); if (!$product->getAllowedInRss()) { continue; } $description = ' <table><tr> <td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td> <td style="text-decoration:none;">%s %s</td> </tr></table> '; $description = sprintf($description, $product->getProductUrl(), $this->imageHelper->init($product, 'rss_thumbnail')->getUrl(), $product->getDescription(), $product->getAllowedPriceInRss() ? $this->renderPriceHtml($product) : ''); $data['entries'][] = ['title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $description]; } return $data; }
/** * Get Options for Configurable Product Options * * @param \Magento\Catalog\Model\Product $currentProduct * @param array $allowedProducts * @return array */ public function getOptions($currentProduct, $allowedProducts) { $options = []; $baseImageUrl = (string) $this->imageHelper->init($currentProduct, 'image'); foreach ($allowedProducts as $product) { $productId = $product->getId(); $image = (string) $this->imageHelper->init($product, 'image'); foreach ($this->getAllowAttributes($currentProduct) as $attribute) { $productAttribute = $attribute->getProductAttribute(); $productAttributeId = $productAttribute->getId(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); $options[$productAttributeId][$attributeValue][] = $productId; $imageUrl = !$product->getImage() || $product->getImage() === 'no_selection' ? $baseImageUrl : (string) $image; $options['images'][$productAttributeId][$attributeValue][$productId] = $imageUrl; } } return $options; }
/** * Return array with data of items of order * * @param $order * * @return array */ protected function getItems($order) { $items = []; foreach ($order->getAllVisibleItems() as $item) { $product = $item->getProduct(); $image = $this->_helperImage->init($product, 'image'); $items[] = ["id" => $item->getSku(), "title" => $product->getName(), "description" => $product->getName(), "picture_url" => $image->getUrl(), "category_id" => $this->_scopeConfig->getValue('payment/mercadopago/category_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), "quantity" => (int) number_format($item->getQtyOrdered(), 0, '.', ''), "unit_price" => (double) number_format($item->getPrice(), 2, '.', '')]; } return $items; }
/** * Resize product images and save results to image cache * * @param Product $product * @return $this */ public function generate(Product $product) { $galleryImages = $product->getMediaGalleryImages(); if ($galleryImages) { foreach ($galleryImages as $image) { foreach ($this->getData() as $params) { $this->imageHelper->init($product, $params['type'], $image->getFile())->resize($params['width'], $params['height'])->save(); } } } return $this; }
/** * Trigger pusher event with latest order information * * @param \Magento\Framework\Event\Observer $observer * @return \Jahvi\NewOrderNotification\Observer\DisplayNotification */ public function execute(Observer $observer) { if ($this->globalConfig->getValue('checkout/newordernotification/enabled')) { $appId = $this->globalConfig->getValue('checkout/newordernotification/app_id'); $appKey = $this->globalConfig->getValue('checkout/newordernotification/app_key'); $appSecret = $this->globalConfig->getValue('checkout/newordernotification/app_secret'); $pusher = new \Pusher($appKey, $appSecret, $appId, ['encrypted' => true]); // Get latest order $orderId = $observer->getEvent()->getOrderIds()[0]; $order = $this->orderFactory->create()->load($orderId); // Get last product in order data $product = $order->getAllVisibleItems()[0]->getProduct(); $shippingCity = $order->getShippingAddress()->getCity(); $productImage = $this->imageHelper->init($product, 'product_thumbnail_image'); // Get shipping city and country $shippingCountryCode = $order->getShippingAddress()->getCountryId(); $shippingCountry = $this->countryFactory->create()->loadByCode($shippingCountryCode); // Trigger pusher event with collected data $pusher->trigger('non_channel', 'new_order', ['product_name' => $product->getName(), 'product_image' => $productImage->getUrl(), 'product_url' => $product->getProductUrl(), 'shipping_city' => $shippingCity, 'shipping_country' => $shippingCountry->getName()]); } return $this; }
/** * Get wishlist items * * @return array */ protected function getItems() { $this->view->loadLayout(); $collection = $this->wishlistHelper->getWishlistItemCollection(); $collection->clear()->setPageSize(self::SIDEBAR_ITEMS_NUMBER)->setInStockFilter(true)->setOrder('added_at'); $items = []; /** @var \Magento\Wishlist\Model\Item $wishlistItem */ foreach ($collection as $wishlistItem) { $product = $wishlistItem->getProduct(); $this->imageHelper->init($product, 'wishlist_sidebar_block'); $items[] = ['image' => ['src' => $this->imageHelper->getUrl(), 'alt' => $this->imageHelper->getLabel(), 'width' => $this->imageHelper->getWidth(), 'height' => $this->imageHelper->getHeight()], 'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem), 'product_name' => $product->getName(), 'product_price' => $this->block->getProductPriceHtml($product, \Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_PRICE_CODE, \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST, ['item' => $wishlistItem]), 'product_is_saleable_and_visible' => $product->isSaleable() && $product->isVisibleInSiteVisibility(), 'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product), 'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem, true), 'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem, true)]; } return $items; }
/** * getItems method * * @return array */ public function getItems() { $result = []; $query = $this->queryFactory->get()->getQueryText(); $productIds = $this->searchProductsFullText($query); // Check if products are found if ($productIds) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create(); $products = $this->productRepository->getList($searchCriteria); foreach ($products->getItems() as $product) { $image = $this->imageHelper->init($product, 'product_page_image_small')->getUrl(); $resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false), 'special_price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => $image, 'url' => $product->getProductUrl()]); $result[] = $resultItem; } } return $result; }
/** * @return string */ protected function _toHtml() { //store id is store view id $storeId = $this->_getStoreId(); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); //customer group id $customerGroupId = $this->_getCustomerGroupId(); /** @var $product \Magento\Catalog\Model\Product */ $product = $this->_productFactory->create(); $product->setStoreId($storeId); $specials = $product->getResourceCollection()->addPriceDataFieldFilter('%s < %s', array('final_price', 'price'))->addPriceData($customerGroupId, $websiteId)->addAttributeToSelect(array('name', 'short_description', 'description', 'price', 'thumbnail', 'special_price', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'), 'left')->addAttributeToSort('name', 'asc'); $newUrl = $this->_urlBuilder->getUrl('rss/catalog/special/store_id/' . $storeId); $title = __('%1 - Special Products', $this->_storeManager->getStore()->getFrontendName()); $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); /** @var $rssObj \Magento\Rss\Model\Rss */ $rssObj = $this->_rssFactory->create(); $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang)); $results = array(); /* using resource iterator to load the data one by one instead of loading all at the same time. loading all data at the same time can cause the big memory allocation. */ $this->_resourceIterator->walk($specials->getSelect(), array(array($this, 'addSpecialXmlCallback')), array('rssObj' => $rssObj, 'results' => &$results)); if (sizeof($results) > 0) { foreach ($results as $result) { // render a row for RSS feed $product->setData($result); $html = sprintf('<table><tr>' . '<td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;">%s', $product->getProductUrl(), $this->_imageHelper->init($product, 'thumbnail')->resize(75, 75), $this->_outputHelper->productAttribute($product, $product->getDescription(), 'description')); // add price data if needed if ($product->getAllowedPriceInRss()) { if ($this->_catalogData->canApplyMsrp($product)) { $html .= '<br/><a href="' . $product->getProductUrl() . '">' . __('Click for price') . '</a>'; } else { $special = ''; if ($result['use_special']) { $special = '<br />' . __('Special Expires On: %1', $this->formatDate($result['special_to_date'], \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM)); } $html .= sprintf('<p>%s %s%s</p>', __('Price: %1', $this->_priceCurrency->convertAndFormat($result['price'])), __('Special Price: %1', $this->_priceCurrency->convertAndFormat($result['final_price'])), $special); } } $html .= '</td></tr></table>'; $rssObj->_addEntry(array('title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $html)); } } return $rssObj->createRssXml(); }
/** * @return $this * @throws CoreException */ public function send() { if ($this->isExceedLimit()) { throw new \Magento\Framework\Exception\LocalizedException(__('You\'ve met your limit of %1 sends in an hour.', $this->getMaxSendsToFriend())); } $this->inlineTranslation->suspend(); $message = nl2br(htmlspecialchars($this->getSender()->getMessage())); $sender = ['name' => $this->_escaper->escapeHtml($this->getSender()->getName()), 'email' => $this->_escaper->escapeHtml($this->getSender()->getEmail())]; foreach ($this->getRecipients()->getEmails() as $k => $email) { $name = $this->getRecipients()->getNames($k); $this->_transportBuilder->setTemplateIdentifier($this->_sendfriendData->getEmailTemplate())->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setFrom($sender)->setTemplateVars(['name' => $name, 'email' => $email, 'product_name' => $this->getProduct()->getName(), 'product_url' => $this->getProduct()->getUrlInStore(), 'message' => $message, 'sender_name' => $sender['name'], 'sender_email' => $sender['email'], 'product_image' => $this->_catalogImage->init($this->getProduct(), 'sendfriend_small_image')->getUrl()])->addTo($email, $name); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); $this->_incrementSentCount(); return $this; }
/** * Prepare variations * * @return void * @throws \Zend_Currency_Exception */ protected function prepareVariations() { $variations = $this->getVariations(); $productMatrix = []; $attributes = []; $productIds = []; if ($variations) { $usedProductAttributes = $this->getUsedAttributes(); $productByUsedAttributes = $this->getAssociatedProducts(); $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); $configurableAttributes = $this->getAttributes(); foreach ($variations as $variation) { $attributeValues = []; foreach ($usedProductAttributes as $attribute) { $attributeValues[$attribute->getAttributeCode()] = $variation[$attribute->getId()]['value']; } $key = implode('-', $attributeValues); if (isset($productByUsedAttributes[$key])) { $product = $productByUsedAttributes[$key]; $price = $product->getPrice(); $variationOptions = []; foreach ($usedProductAttributes as $attribute) { if (!isset($attributes[$attribute->getAttributeId()])) { $attributes[$attribute->getAttributeId()] = ['code' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel(), 'id' => $attribute->getAttributeId(), 'position' => $configurableAttributes[$attribute->getAttributeId()]['position'], 'chosen' => []]; foreach ($attribute->getOptions() as $option) { if (!empty($option->getValue())) { $attributes[$attribute->getAttributeId()]['options'][$option->getValue()] = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $option->getValue(), 'label' => $option->getLabel(), 'value' => $option->getValue()]; } } } $optionId = $variation[$attribute->getId()]['value']; $variationOption = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $optionId, 'label' => $variation[$attribute->getId()]['label'], 'value' => $optionId]; $variationOptions[] = $variationOption; $attributes[$attribute->getAttributeId()]['chosen'][$optionId] = $variationOption; } $productMatrix[] = ['id' => $product->getId(), 'product_link' => '<a href="' . $this->urlBuilder->getUrl('catalog/product/edit', ['id' => $product->getId()]) . '" target="_blank">' . $product->getName() . '</a>', 'sku' => $product->getSku(), 'name' => $product->getName(), 'qty' => $this->getProductStockQty($product), 'price' => $currency->toCurrency(sprintf("%f", $price), ['display' => false]), 'price_string' => $currency->toCurrency(sprintf("%f", $price)), 'price_currency' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(), 'configurable_attribute' => $this->getJsonConfigurableAttributes($variationOptions), 'weight' => $product->getWeight(), 'status' => $product->getStatus(), 'variationKey' => $this->getVariationKey($variationOptions), 'canEdit' => 0, 'newProduct' => 0, 'attributes' => $this->getTextAttributes($variationOptions), 'thumbnail_image' => $this->imageHelper->init($product, 'product_thumbnail_image')->getUrl()]; $productIds[] = $product->getId(); } } } $this->productMatrix = $productMatrix; $this->productIds = $productIds; $this->productAttributes = array_values($attributes); }
/** * Preparing data and adding to rss object * * @param array $args * @return void */ public function addNewItemXmlCallback($args) { /** @var $product \Magento\Catalog\Model\Product */ $product = $args['product']; $product->setAllowedInRss(true); $product->setAllowedPriceInRss(true); $this->_eventManager->dispatch('rss_catalog_category_xml_callback', $args); if (!$product->getAllowedInRss()) { return; } $description = '<table><tr>' . '<td><a href="' . $product->getProductUrl() . '"><img src="' . $this->_imageHelper->init($product, 'thumbnail')->resize(75, 75) . '" border="0" align="left" height="75" width="75"></a></td>' . '<td style="text-decoration:none;">' . $product->getDescription(); if ($product->getAllowedPriceInRss()) { $description .= $this->renderPriceHtml($product, true); } $description .= '</td></tr></table>'; /** @var $rssObj \Magento\Rss\Model\Rss */ $rssObj = $args['rssObj']; $data = array('title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $description); $rssObj->_addEntry($data); }
/** * @param string $imageId * @param string $imageFile * @param string $baseFile * @param string $newFile * @param string $destination * @param boolean $setImageFile * @param boolean $isCached * @param boolean $isBaseFilePlaceholder * @param array $resizedImageInfo * @dataProvider getResizedImageInfoDataProvider */ public function testGetResizedImageInfo($imageId, $imageFile, $baseFile, $newFile, $destination, $setImageFile, $isCached, $isBaseFilePlaceholder, $resizedImageInfo) { $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productMock->expects($this->any())->method('getData')->with($destination)->willReturn($imageFile); $this->image->expects($this->any())->method('setBaseFile')->with($imageFile)->willReturnSelf(); $this->image->expects($this->once())->method('getBaseFile')->willReturn($baseFile); $this->image->expects($this->any())->method('getDestinationSubdir')->willReturn($destination); $this->image->expects($this->any())->method('isCached')->willReturn($isCached); $this->image->expects($this->any())->method('resize')->willReturnSelf(); $this->image->expects($this->any())->method('saveFile')->willReturnSelf(); $this->image->expects($this->once())->method('getResizedImageInfo')->willReturn($resizedImageInfo); $this->image->expects($this->any())->method('isBaseFilePlaceholder')->willReturn($isBaseFilePlaceholder); $this->image->expects($this->any())->method('getNewFile')->willReturn($newFile); $this->prepareAttributes([], $imageId); $this->helper->init($productMock, $imageId); if ($setImageFile) { $this->helper->setImageFile($imageFile); } $result = $this->helper->getResizedImageInfo(); $this->assertEquals($resizedImageInfo, $result); }
/** * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @return void * TODO: move to class */ protected function prepareVariations() { $variations = $this->getVariations(); $productMatrix = []; $attributes = []; if ($variations) { $usedProductAttributes = $this->getUsedAttributes(); $productByUsedAttributes = $this->getAssociatedProducts(); $configurableAttributes = $this->getAttributes(); foreach ($variations as $variation) { $attributeValues = []; foreach ($usedProductAttributes as $attribute) { $attributeValues[$attribute->getAttributeCode()] = $variation[$attribute->getId()]['value']; } $key = implode('-', $attributeValues); if (isset($productByUsedAttributes[$key])) { $product = $productByUsedAttributes[$key]; $price = $product->getPrice(); $variationOptions = []; foreach ($usedProductAttributes as $attribute) { if (!isset($attributes[$attribute->getAttributeId()])) { $attributes[$attribute->getAttributeId()] = ['code' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel(), 'id' => $attribute->getAttributeId(), 'position' => $configurableAttributes[$attribute->getAttributeId()]['position'], 'chosen' => []]; foreach ($attribute->getOptions() as $option) { if (!empty($option->getValue())) { $attributes[$attribute->getAttributeId()]['options'][] = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $option->getValue(), 'label' => $option->getLabel(), 'value' => $option->getValue()]; } } } $optionId = $variation[$attribute->getId()]['value']; $variationOption = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $optionId, 'label' => $variation[$attribute->getId()]['label'], 'value' => $optionId]; $variationOptions[] = $variationOption; $attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption; } $productMatrix[] = ['productId' => $product->getId(), 'images' => ['preview' => $this->image->init($product, 'product_thumbnail_image')->getUrl()], 'sku' => $product->getSku(), 'name' => $product->getName(), 'quantity' => $this->getProductStockQty($product), 'price' => $price, 'options' => $variationOptions, 'weight' => $product->getWeight(), 'status' => $product->getStatus()]; } } } $this->productMatrix = $productMatrix; $this->productAttributes = array_values($attributes); }
/** * Process image data * * @param Product $product * @param array $imageData * @param string $file * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function processImageData(Product $product, array $imageData, $file) { $this->imageHelper->init($product, $imageData['id'], $imageData); $this->imageHelper->setImageFile($file); if (isset($imageData['aspect_ratio'])) { $this->imageHelper->keepAspectRatio($imageData['aspect_ratio']); } if (isset($imageData['frame'])) { $this->imageHelper->keepFrame($imageData['frame']); } if (isset($imageData['transparency'])) { $this->imageHelper->keepTransparency($imageData['transparency']); } if (isset($imageData['constrain'])) { $this->imageHelper->constrainOnly($imageData['constrain']); } if (isset($imageData['background'])) { $this->imageHelper->backgroundColor($imageData['background']); } $this->imageHelper->save(); return $this; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $modelId = $product->getId(); if ($modelId) { $storeId = $this->locator->getStore()->getId(); /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); $data[$product->getId()]['links'][self::LINK_TYPE] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== self::LINK_TYPE) { continue; } /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId); $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; } $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId; } return $data; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $productId = $product->getId(); if (!$productId) { return $data; } foreach ($this->getDataScopes() as $dataScope) { $data[$productId]['links'][$dataScope] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== $dataScope) { continue; } /** @var \Magento\Catalog\Model\Product $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId()); $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; } } $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId; $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId(); return $data; }
/** * @param \Magento\Catalog\Model\Product $item * @return array */ protected function getEntryData(\Magento\Catalog\Model\Product $item) { $description = ' <table><tr> <td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td> <td style="text-decoration:none;">%s %s</td> </tr></table> '; $specialPrice = ''; if ($item->getAllowedPriceInRss()) { if ($this->msrpHelper->canApplyMsrp($item)) { $specialPrice = '<br/><a href="' . $item->getProductUrl() . '">' . __('Click for price') . '</a>'; } else { $special = ''; if ($item->getUseSpecial()) { $special = '<br />' . __('Special Expires On: %1', $this->formatDate($item->getSpecialToDate(), \IntlDateFormatter::MEDIUM)); } $specialPrice = sprintf('<p>%s %s%s</p>', __('Price: %1', $this->priceCurrency->convertAndFormat($item->getPrice())), __('Special Price: %1', $this->priceCurrency->convertAndFormat($item->getFinalPrice())), $special); } } $description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'rss_thumbnail')->getUrl(), $this->outputHelper->productAttribute($item, $item->getDescription(), 'description'), $specialPrice); return ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description]; }
/** * Initialize image by specified type * * @param string $imageType * @return \Magento\Catalog\Helper\Image */ protected function _init($imageType = 'image') { return $this->_helper->init(self::$_product, $imageType); }
/** * Product thumbnail image url getter * * @param \Magento\Catalog\Model\Product $product * @return string */ public function getThumbnailUrl($product) { return (string) $this->imageHelper->init($product, 'thumbnail')->resize($this->getThumbnailSize()); }
/** * {@inheritdoc} */ protected function doGetItemData() { $imageHelper = $this->imageHelper->init($this->getProductForThumbnail(), 'mini_cart_product_thumbnail'); return ['options' => $this->getOptionList(), 'qty' => $this->item->getQty() * 1, 'item_id' => $this->item->getId(), 'configure_url' => $this->getConfigureUrl(), 'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(), 'product_name' => $this->item->getProduct()->getName(), 'product_url' => $this->getProductUrl(), 'product_has_url' => $this->hasProductUrl(), 'product_price' => $this->checkoutHelper->formatPrice($this->item->getCalculationPrice()), 'product_image' => ['src' => $imageHelper->getUrl(), 'alt' => $imageHelper->getLabel(), 'width' => $imageHelper->getWidth(), 'height' => $imageHelper->getHeight()], 'canApplyMsrp' => $this->msrpHelper->isShowBeforeOrderConfirm($this->item->getProduct()) && $this->msrpHelper->isMinimalPriceLessMsrp($this->item->getProduct())]; }
/** * Fill data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); return ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; }
/** * Get product thumbnail image * * @return \Magento\Catalog\Model\Product\Image */ public function getProductThumbnail() { return $this->_imageHelper->init($this->getProductForThumbnail(), 'thumbnail'); }
/** * Prepare data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { return ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; }
/** * Return product image url * * @return string */ public function getUrl() { $this->_helperImage->init($this->_product, $this->getType())->keepFrame($this->isWhiteBorders())->resize($this->getWidth(), $this->getHeight()); return (string) $this->_helperImage; }