Skip to content

Commit

Permalink
Merge pull request #1222 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests

#9082
#9786
  • Loading branch information
Oleksii Korshenko authored Jun 22, 2017
2 parents 82416d7 + 19a2bd7 commit 10c6ffa
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 53 deletions.
19 changes: 16 additions & 3 deletions app/code/Magento/Contact/Model/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
namespace Magento\Contact\Model;

use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Translate\Inline\StateInterface;
use Magento\Store\Model\StoreManagerInterface;

class Mail implements MailInterface
{
Expand All @@ -26,18 +28,29 @@ class Mail implements MailInterface
private $inlineTranslation;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* Initialize dependencies.
*
* @param ConfigInterface $contactsConfig
* @param TransportBuilder $transportBuilder
* @param StateInterface $inlineTranslation
* @param StoreManagerInterface|null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
) {
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?:
ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand All @@ -58,8 +71,8 @@ public function send($replyTo, array $variables)
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => 'adminhtml',
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
'area' => 'frontend',
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
Expand Down
21 changes: 18 additions & 3 deletions app/code/Magento/Contact/Test/Unit/Model/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use Magento\Contact\Model\ConfigInterface;
use Magento\Contact\Model\Mail;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;

class MailTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -32,6 +34,11 @@ class MailTest extends \PHPUnit_Framework_TestCase
*/
private $inlineTranslationMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

/**
* @var Mail
*/
Expand All @@ -50,10 +57,13 @@ protected function setUp()
)->disableOriginalConstructor(
)->getMock();

$this->storeManagerMock = $this->getMock(StoreManagerInterface::class);

$this->mail = new Mail(
$this->configMock,
$this->transportBuilderMock,
$this->inlineTranslationMock
$this->inlineTranslationMock,
$this->storeManagerMock
);
}

Expand All @@ -64,15 +74,20 @@ public function testSendMail()

$transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false);

$store = $this->getMock(StoreInterface::class);
$store->expects($this->once())->method('getId')->willReturn(555);

$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($store);

$this->transportBuilderMock->expects($this->once())
->method('setTemplateIdentifier')
->will($this->returnSelf());

$this->transportBuilderMock->expects($this->once())
->method('setTemplateOptions')
->with([
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
'area' => 'frontend',
'store' => 555,
])
->will($this->returnSelf());

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Contact/etc/email_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="text" module="Magento_Contact" area="adminhtml"/>
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="html" module="Magento_Contact" area="frontend"/>
</config>
19 changes: 0 additions & 19 deletions app/code/Magento/Contact/view/adminhtml/email/submitted_form.html

This file was deleted.

34 changes: 34 additions & 0 deletions app/code/Magento/Contact/view/frontend/email/submitted_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<!--@subject {{trans "Contact Form"}} @-->
<!--@vars {
"var data.comment":"Comment",
"var data.email":"Sender Email",
"var data.name":"Sender Name",
"var data.telephone":"Sender Telephone"
} @-->

{{template config_path="design/email/header_template"}}

<table class="message-details">
<tr>
<td><b>{{trans "Name"}}</b></td>
<td>{{var data.name}}</td>
</tr>
<tr>
<td><b>{{trans "Email"}}</b></td>
<td>{{var data.email}}</td>
</tr>
<tr>
<td><b>{{trans "Phone"}}</b></td>
<td>{{var data.telephone}}</td>
</tr>
</table>
<p><b>{{trans "Message"}}</b></p>
<p>{{var data.comment}}</p>

{{template config_path="design/email/footer_template"}}
48 changes: 42 additions & 6 deletions app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\Store\Model\Store;
use Magento\Framework\App\ObjectManager;

/**
* Sitemap resource product collection model
*
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
Expand Down Expand Up @@ -71,9 +71,20 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb

/**
* @var \Magento\Catalog\Model\Product\Media\Config
* @deprecated unused
*/
protected $_mediaConfig;

/**
* @var \Magento\Catalog\Model\Product
*/
private $productModel;

/**
* @var \Magento\Catalog\Helper\Image
*/
private $catalogImageHelper;

/**
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
* @param \Magento\Sitemap\Helper\Data $sitemapData
Expand All @@ -85,6 +96,8 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
* @param string $connectionName
* @param \Magento\Catalog\Model\Product $productModel
* @param \Magento\Catalog\Helper\Image $catalogImageHelper
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -97,7 +110,9 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Gallery $mediaGalleryResourceModel,
\Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler,
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
$connectionName = null
$connectionName = null,
\Magento\Catalog\Model\Product $productModel = null,
\Magento\Catalog\Helper\Image $catalogImageHelper = null
) {
$this->_productResource = $productResource;
$this->_storeManager = $storeManager;
Expand All @@ -107,6 +122,9 @@ public function __construct(
$this->mediaGalleryReadHandler = $mediaGalleryReadHandler;
$this->_mediaConfig = $mediaConfig;
$this->_sitemapData = $sitemapData;
$this->productModel = $productModel ?: ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
$this->catalogImageHelper = $catalogImageHelper ?: ObjectManager::getInstance()
->get(\Magento\Catalog\Helper\Image::class);
parent::__construct($context, $connectionName);
}

Expand Down Expand Up @@ -339,7 +357,7 @@ protected function _loadProductImages($product, $storeId)
) {
$imagesCollection = [
new \Magento\Framework\DataObject(
['url' => $this->_getMediaConfig()->getBaseMediaUrlAddition() . $product->getImage()]
['url' => $this->getProductImageUrl($product->getImage())]
),
];
}
Expand All @@ -348,7 +366,7 @@ protected function _loadProductImages($product, $storeId)
// Determine thumbnail path
$thumbnail = $product->getThumbnail();
if ($thumbnail && $product->getThumbnail() != self::NOT_SELECTED_IMAGE) {
$thumbnail = $this->_getMediaConfig()->getBaseMediaUrlAddition() . $thumbnail;
$thumbnail = $this->getProductImageUrl($thumbnail);
} else {
$thumbnail = $imagesCollection[0]->getUrl();
}
Expand Down Expand Up @@ -378,11 +396,10 @@ protected function _getAllProductImages($product, $storeId)

$imagesCollection = [];
if ($gallery) {
$productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
foreach ($gallery as $image) {
$imagesCollection[] = new \Magento\Framework\DataObject(
[
'url' => $productMediaPath . $image['file'],
'url' => $this->getProductImageUrl($image['file']),
'caption' => $image['label'] ? $image['label'] : $image['label_default'],
]
);
Expand All @@ -396,9 +413,28 @@ protected function _getAllProductImages($product, $storeId)
* Get media config
*
* @return \Magento\Catalog\Model\Product\Media\Config
* @deprecated No longer used, as we're getting full image URL from getProductImageUrl method
* @see getProductImageUrl()
*/
protected function _getMediaConfig()
{
return $this->_mediaConfig;
}

/**
* Get product image URL from image filename and path
*
* @param string $image
* @return string
*/
private function getProductImageUrl($image)
{
$productObject = $this->productModel;
$imgUrl = $this->catalogImageHelper
->init($productObject, 'product_page_image_large')
->setImageFile($image)
->getUrl();

return $imgUrl;
}
}
11 changes: 6 additions & 5 deletions app/code/Magento/Sitemap/Model/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ protected function _isSplitRequired($row)
* @param null|string $lastmod
* @param null|string $changefreq
* @param null|string $priority
* @param null|array $images
* @param null|array|\Magento\Framework\DataObject $images
* @return string
* Sitemap images
* @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
Expand All @@ -473,7 +473,7 @@ protected function _getSitemapRow($url, $lastmod = null, $changefreq = null, $pr
// Add Images to sitemap
foreach ($images->getCollection() as $image) {
$row .= '<image:image>';
$row .= '<image:loc>' . htmlspecialchars($this->_getMediaUrl($image->getUrl())) . '</image:loc>';
$row .= '<image:loc>' . htmlspecialchars($image->getUrl()) . '</image:loc>';
$row .= '<image:title>' . htmlspecialchars($images->getTitle()) . '</image:title>';
if ($image->getCaption()) {
$row .= '<image:caption>' . htmlspecialchars($image->getCaption()) . '</image:caption>';
Expand All @@ -483,9 +483,7 @@ protected function _getSitemapRow($url, $lastmod = null, $changefreq = null, $pr
// Add PageMap image for Google web search
$row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail">';
$row .= '<Attribute name="name" value="' . htmlspecialchars($images->getTitle()) . '"/>';
$row .= '<Attribute name="src" value="' . htmlspecialchars(
$this->_getMediaUrl($images->getThumbnail())
) . '"/>';
$row .= '<Attribute name="src" value="' . htmlspecialchars($images->getThumbnail()) . '"/>';
$row .= '</DataObject></PageMap>';
}

Expand Down Expand Up @@ -591,6 +589,7 @@ protected function _getBaseDir()
*/
protected function _getStoreBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK)
{
/** @var \Magento\Store\Model\Store $store */
$store = $this->_storeManager->getStore($this->getStoreId());
$isSecure = $store->isUrlSecure();
return rtrim($store->getBaseUrl($type, $isSecure), '/') . '/';
Expand All @@ -613,6 +612,8 @@ protected function _getUrl($url, $type = \Magento\Framework\UrlInterface::URL_TY
*
* @param string $url
* @return string
* @deprecated No longer used, as we're generating product image URLs inside collection instead
* @see \Magento\Sitemap\Model\ResourceModel\Catalog\Product::_loadProductImages()
*/
protected function _getMediaUrl($url)
{
Expand Down
11 changes: 8 additions & 3 deletions app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ protected function _getModelMock($mockBeforeSave = false)
]
)
);

$storeBaseMediaUrl = 'http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/';
$this->_sitemapProductMock->expects(
$this->any()
)->method(
Expand All @@ -553,13 +555,16 @@ protected function _getModelMock($mockBeforeSave = false)
[
'collection' => [
new \Magento\Framework\DataObject(
['url' => 'image1.png', 'caption' => 'caption & > title < "']
[
'url' => $storeBaseMediaUrl.'i/m/image1.png',
'caption' => 'caption & > title < "'
]
),
new \Magento\Framework\DataObject(
['url' => 'image_no_caption.png', 'caption' => null]
['url' => $storeBaseMediaUrl.'i/m/image_no_caption.png', 'caption' => null]
),
],
'thumbnail' => 'thumbnail.jpg',
'thumbnail' => $storeBaseMediaUrl.'t/h/thumbnail.jpg',
'title' => 'Product & > title < "',
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
<changefreq>monthly</changefreq>
<priority>0.5</priority>
<image:image>
<image:loc>http://store.com/image1.png</image:loc>
<image:loc>http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/i/m/image1.png</image:loc>
<image:title>Product &amp; &gt; title &lt; &quot;</image:title>
<image:caption>caption &amp; &gt; title &lt; &quot;</image:caption>
</image:image>
<image:image>
<image:loc>http://store.com/image_no_caption.png</image:loc>
<image:loc>http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/i/m/image_no_caption.png</image:loc>
<image:title>Product &amp; &gt; title &lt; &quot;</image:title>
</image:image>
<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0">
<DataObject type="thumbnail">
<Attribute name="name" value="Product &amp; &gt; title &lt; &quot;"/>
<Attribute name="src" value="http://store.com/thumbnail.jpg"/>
<Attribute name="src" value="http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/t/h/thumbnail.jpg"/>
</DataObject>
</PageMap>
</url>
Expand Down
Loading

0 comments on commit 10c6ffa

Please sign in to comment.