本文整理汇总了PHP中Magento\Catalog\Helper\Image::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::init方法的具体用法?PHP Image::init怎么用?PHP Image::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Helper\Image
的用法示例。
在下文中一共展示了Image::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCartItems
/**
* @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;
}
示例2: getListValues
/**
* @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;
}
示例3: getGalleryImages
/**
* 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;
}
示例4: getRssData
/**
* {@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;
}
示例5: getRssData
/**
* 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;
}
示例6: getItems
/**
* {@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;
}
示例7: getRssData
/**
* {@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;
}
示例8: getOptions
/**
* 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;
}
示例9: getItems
/**
* 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;
}
示例10: generate
/**
* 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;
}
示例11: execute
/**
* 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;
}
示例12: getItems
/**
* 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;
}
示例13: getItems
/**
* 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;
}
示例14: _toHtml
/**
* @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();
}
示例15: send
/**
* @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;
}