本文整理汇总了PHP中Magento\Catalog\Helper\Image类的典型用法代码示例。如果您正苦于以下问题:PHP Image类的具体用法?PHP Image怎么用?PHP Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rejoiner,项目名称:magento2-plugin,代码行数:38,代码来源:Base.php
示例2: testGetOptions
/**
* @param array $expected
* @param array $data
* @dataProvider getOptionsDataProvider
*/
public function testGetOptions(array $expected, array $data)
{
if (count($data['allowed_products'])) {
$imageHelper1 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
$imageHelper1->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url');
$imageHelper2 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
$imageHelper2->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url_2');
$this->_imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$data['current_product_mock'], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][0], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][1], 'product_page_image_large', [], $imageHelper2]]);
}
$this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:DataTest.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:Data.php
示例4: testGenerate
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData());
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config);
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:CacheTest.php
示例5: 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;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:Product.php
示例6: 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;
}
开发者ID:nja78,项目名称:magento2,代码行数:25,代码来源:Data.php
示例7: 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;
}
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:17,代码来源:Payment.php
示例8: createModel
/**
* {@inheritdoc}
*/
protected function createModel()
{
$this->currencyMock = $this->getMockBuilder(CurrencyInterface::class)->setMethods(['getCurrency', 'toCurrency'])->getMockForAbstractClass();
$this->currencyMock->expects($this->any())->method('getCurrency')->willReturn($this->currencyMock);
$this->imageHelperMock = $this->getMockBuilder(ImageHelper::class)->setMethods(['init', 'getUrl'])->disableOriginalConstructor()->getMock();
$this->imageHelperMock->expects($this->any())->method('init')->willReturn($this->imageHelperMock);
$this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
$attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class)->setMethods(['getAttributeSetName'])->getMockForAbstractClass();
$this->attributeSetRepositoryMock->expects($this->any())->method('get')->willReturn($attributeSetMock);
return $this->objectManager->getObject(Grouped::class, ['locator' => $this->locatorMock, 'productLinkRepository' => $this->linkRepositoryMock, 'productRepository' => $this->productRepositoryMock, 'localeCurrency' => $this->currencyMock, 'imageHelper' => $this->imageHelperMock, 'attributeSetRepository' => $this->attributeSetRepositoryMock]);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:GroupedTest.php
示例9: 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;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:Cache.php
示例10: 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;
}
开发者ID:jahvi,项目名称:new-order-notification,代码行数:28,代码来源:DisplayNotification.php
示例11: testGetJsonSwatchConfigWithoutVisualImageType
public function testGetJsonSwatchConfigWithoutVisualImageType()
{
$this->configurable->setProduct($this->product);
$this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => [1 => 'testA', 3 => 'testB'], 'use_product_image_for_swatch' => true, 'attribute_code' => 'code']]);
$this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => Swatch::SWATCH_TYPE_VISUAL_IMAGE, 'value' => 'hello']]);
$this->swatchHelper->expects($this->once())->method('loadFirstVariationWithSwatchImage')->with($this->product, ['code' => 3])->willReturn($this->product);
$this->swatchMediaHelper->expects($this->exactly(2))->method('getSwatchAttributeImage')->withConsecutive(['swatch_image', 'hello'], ['swatch_thumb', 'hello'])->willReturn('/path');
$this->product->expects($this->exactly(4))->method('getData')->withConsecutive(['swatch_image'], ['image'], ['swatch_image'], ['image'])->will($this->onConsecutiveCalls(null, null, null, null));
$this->imageHelper->expects($this->never())->method('init');
$this->imageHelper->expects($this->never())->method('resize');
$this->jsonEncoder->expects($this->once())->method('encode');
$this->configurable->getJsonSwatchConfig();
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:13,代码来源:ConfigurableTest.php
示例12: testGetGalleryImages
public function testGetGalleryImages()
{
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
$productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock();
$productTypeMock->expects($this->once())->method('getStoreFilter')->with($productMock)->willReturn($storeMock);
$productMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
$productMock->expects($this->once())->method('getMediaGalleryImages')->willReturn($this->getImagesCollection());
$this->registry->expects($this->once())->method('registry')->with('product')->willReturn($productMock);
$this->imageHelper->expects($this->exactly(3))->method('init')->willReturnMap([[$productMock, 'product_page_image_small', [], $this->imageHelper], [$productMock, 'product_page_image_medium', [], $this->imageHelper], [$productMock, 'product_page_image_large', [], $this->imageHelper]])->willReturnSelf();
$this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with('test_file')->willReturnSelf();
$this->imageHelper->expects($this->at(0))->method('getUrl')->willReturn('product_page_image_small_url');
$this->imageHelper->expects($this->at(1))->method('getUrl')->willReturn('product_page_image_medium_url');
$this->imageHelper->expects($this->at(2))->method('getUrl')->willReturn('product_page_image_large_url');
$this->imageHelper->expects($this->exactly(2))->method('constrainOnly')->with(true)->willReturnSelf();
$this->imageHelper->expects($this->exactly(2))->method('keepAspectRatio')->with(true)->willReturnSelf();
$this->imageHelper->expects($this->exactly(2))->method('keepFrame')->with(false)->willReturnSelf();
$images = $this->model->getGalleryImages();
$this->assertInstanceOf('Magento\\Framework\\Data\\Collection', $images);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:GalleryTest.php
示例13: testGenerate
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$data = $this->getTestData();
$this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
$themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
$themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:25,代码来源:CacheTest.php
示例14: testGetProductMediaGallery
/**
* @dataProvider dataForMediaGallery
*/
public function testGetProductMediaGallery($mediaGallery, $image)
{
$this->productMock->expects($this->once())->method('getMediaAttributeValues')->willReturn($mediaGallery);
$this->imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$this->productMock, 'product_page_image_large', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_medium', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_small', [], $this->imageHelperMock]]);
$this->imageHelperMock->expects($this->any())->method('setImageFile')->with($image)->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('constrainOnly')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('keepAspectRatio')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('keepFrame')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('getUrl')->willReturn('http://full_path_to_image/magento1.png');
$mediaObject = $this->getMock('\\Magento\\Framework\\DataObject', [], [], '', false);
$iterator = new \ArrayIterator([$mediaObject]);
$mediaCollectionMock = $this->getMock('\\Magento\\Framework\\Data\\Collection', [], [], '', false);
$mediaCollectionMock->expects($this->any())->method('getIterator')->willReturn($iterator);
$mediaObject->method('getData')->withConsecutive(['value_id'], ['file'])->willReturnOnConsecutiveCalls(0, $image);
$this->productMock->method('getMediaGalleryImages')->willReturn($mediaCollectionMock);
$this->swatchHelperObject->getProductMediaGallery($this->productMock);
}
开发者ID:vv-team,项目名称:foodo,代码行数:20,代码来源:DataTest.php
示例15: 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;
}
开发者ID:boxalino,项目名称:plugin-magento2,代码行数:30,代码来源:Autocomplete.php
示例16: testGetOptions
/**
* @param array $expected
* @param array $data
* @dataProvider getOptionsDataProvider
*/
public function testGetOptions(array $expected, array $data)
{
$this->_imageHelperMock->expects($this->at(0))->method('init')->will($this->returnValue('http://example.com/base_img_url'));
for ($i = 1; $i <= count($data['allowed_products']); $i++) {
$this->_imageHelperMock->expects($this->at($i))->method('init')->will($this->returnValue('http://example.com/base_img_url_' . $i));
}
$this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:DataTest.php
示例17: testGetRssData
public function testGetRssData()
{
$category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->setMethods(['__sleep', '__wakeup', 'load', 'getId', 'getUrl', 'getName'])->disableOriginalConstructor()->getMock();
$category->expects($this->once())->method('getName')->will($this->returnValue('Category Name'));
$category->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/category-name.html'));
$this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category));
$product = $this->getMockBuilder('\\Magento\\catalog\\Model\\Product')->setMethods(['__sleep', '__wakeup', 'getName', 'getAllowedInRss', 'getProductUrl', 'getDescription', 'getAllowedPriceInRss'])->disableOriginalConstructor()->getMock();
$product->expects($this->once())->method('getName')->will($this->returnValue('Product Name'));
$product->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true));
$product->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue('http://magento.com/product.html'));
$product->expects($this->once())->method('getDescription')->will($this->returnValue('Product Description'));
$product->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue(true));
$this->rssModel->expects($this->once())->method('getProductCollection')->will($this->returnValue([$product]));
$this->imageHelper->expects($this->once())->method('init')->with($product, 'thumbnail')->will($this->returnSelf());
$this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link'));
$data = $this->block->getRssData();
$this->assertEquals($this->rssFeed['link'], $data['link']);
$this->assertEquals($this->rssFeed['title'], $data['title']);
$this->assertEquals($this->rssFeed['description'], $data['description']);
$this->assertEquals($this->rssFeed['entries'][0]['title'], $data['entries'][0]['title']);
$this->assertEquals($this->rssFeed['entries'][0]['link'], $data['entries'][0]['link']);
$this->assertContains('<a href="http://magento.com/product.html">', $data['entries'][0]['description']);
$this->assertContains('<img src="image_link" border="0" align="left" height="75" width="75">', $data['entries'][0]['description']);
$this->assertContains('<td style="text-decoration:none;">Product Description </td>', $data['entries'][0]['description']);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:CategoryTest.php
示例18: 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;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:39,代码来源:Wishlist.php
示例19: 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;
}
开发者ID:tingyeeh,项目名称:magento2,代码行数:33,代码来源:Category.php
示例20: 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;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:30,代码来源:NewProducts.php
注:本文中的Magento\Catalog\Helper\Image类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论