Skip to content

Commit 1489ad7

Browse files
committed
Merge remote-tracking branch 'origin/develop' into BUGS
2 parents 542e551 + 10c6ffa commit 1489ad7

File tree

12 files changed

+159
-53
lines changed

12 files changed

+159
-53
lines changed

app/code/Magento/Contact/Model/Mail.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
namespace Magento\Contact\Model;
77

88
use Magento\Framework\Mail\Template\TransportBuilder;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Translate\Inline\StateInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
1012

1113
class Mail implements MailInterface
1214
{
@@ -26,18 +28,29 @@ class Mail implements MailInterface
2628
private $inlineTranslation;
2729

2830
/**
31+
* @var StoreManagerInterface
32+
*/
33+
private $storeManager;
34+
35+
/**
36+
* Initialize dependencies.
37+
*
2938
* @param ConfigInterface $contactsConfig
3039
* @param TransportBuilder $transportBuilder
3140
* @param StateInterface $inlineTranslation
41+
* @param StoreManagerInterface|null $storeManager
3242
*/
3343
public function __construct(
3444
ConfigInterface $contactsConfig,
3545
TransportBuilder $transportBuilder,
36-
StateInterface $inlineTranslation
46+
StateInterface $inlineTranslation,
47+
StoreManagerInterface $storeManager = null
3748
) {
3849
$this->contactsConfig = $contactsConfig;
3950
$this->transportBuilder = $transportBuilder;
4051
$this->inlineTranslation = $inlineTranslation;
52+
$this->storeManager = $storeManager ?:
53+
ObjectManager::getInstance()->get(StoreManagerInterface::class);
4154
}
4255

4356
/**
@@ -58,8 +71,8 @@ public function send($replyTo, array $variables)
5871
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
5972
->setTemplateOptions(
6073
[
61-
'area' => 'adminhtml',
62-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
74+
'area' => 'frontend',
75+
'store' => $this->storeManager->getStore()->getId()
6376
]
6477
)
6578
->setTemplateVars($variables)

app/code/Magento/Contact/Test/Unit/Model/MailTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Contact\Model\ConfigInterface;
1010
use Magento\Contact\Model\Mail;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Store\Api\Data\StoreInterface;
1113

1214
class MailTest extends \PHPUnit_Framework_TestCase
1315
{
@@ -32,6 +34,11 @@ class MailTest extends \PHPUnit_Framework_TestCase
3234
*/
3335
private $inlineTranslationMock;
3436

37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $storeManagerMock;
41+
3542
/**
3643
* @var Mail
3744
*/
@@ -50,10 +57,13 @@ protected function setUp()
5057
)->disableOriginalConstructor(
5158
)->getMock();
5259

60+
$this->storeManagerMock = $this->getMock(StoreManagerInterface::class);
61+
5362
$this->mail = new Mail(
5463
$this->configMock,
5564
$this->transportBuilderMock,
56-
$this->inlineTranslationMock
65+
$this->inlineTranslationMock,
66+
$this->storeManagerMock
5767
);
5868
}
5969

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

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

77+
$store = $this->getMock(StoreInterface::class);
78+
$store->expects($this->once())->method('getId')->willReturn(555);
79+
80+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($store);
81+
6782
$this->transportBuilderMock->expects($this->once())
6883
->method('setTemplateIdentifier')
6984
->will($this->returnSelf());
7085

7186
$this->transportBuilderMock->expects($this->once())
7287
->method('setTemplateOptions')
7388
->with([
74-
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
75-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
89+
'area' => 'frontend',
90+
'store' => 555,
7691
])
7792
->will($this->returnSelf());
7893

app/code/Magento/Contact/etc/email_templates.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
9-
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="text" module="Magento_Contact" area="adminhtml"/>
9+
<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="html" module="Magento_Contact" area="frontend"/>
1010
</config>

app/code/Magento/Contact/view/adminhtml/email/submitted_form.html

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<!--@subject {{trans "Contact Form"}} @-->
8+
<!--@vars {
9+
"var data.comment":"Comment",
10+
"var data.email":"Sender Email",
11+
"var data.name":"Sender Name",
12+
"var data.telephone":"Sender Telephone"
13+
} @-->
14+
15+
{{template config_path="design/email/header_template"}}
16+
17+
<table class="message-details">
18+
<tr>
19+
<td><b>{{trans "Name"}}</b></td>
20+
<td>{{var data.name}}</td>
21+
</tr>
22+
<tr>
23+
<td><b>{{trans "Email"}}</b></td>
24+
<td>{{var data.email}}</td>
25+
</tr>
26+
<tr>
27+
<td><b>{{trans "Phone"}}</b></td>
28+
<td>{{var data.telephone}}</td>
29+
</tr>
30+
</table>
31+
<p><b>{{trans "Message"}}</b></p>
32+
<p>{{var data.comment}}</p>
33+
34+
{{template config_path="design/email/footer_template"}}

app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
99
use Magento\Store\Model\Store;
10+
use Magento\Framework\App\ObjectManager;
1011

1112
/**
1213
* Sitemap resource product collection model
1314
*
14-
* @author Magento Core Team <core@magentocommerce.com>
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1616
*/
1717
class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
@@ -71,9 +71,20 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
7171

7272
/**
7373
* @var \Magento\Catalog\Model\Product\Media\Config
74+
* @deprecated unused
7475
*/
7576
protected $_mediaConfig;
7677

78+
/**
79+
* @var \Magento\Catalog\Model\Product
80+
*/
81+
private $productModel;
82+
83+
/**
84+
* @var \Magento\Catalog\Helper\Image
85+
*/
86+
private $catalogImageHelper;
87+
7788
/**
7889
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
7990
* @param \Magento\Sitemap\Helper\Data $sitemapData
@@ -85,6 +96,8 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
8596
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler
8697
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
8798
* @param string $connectionName
99+
* @param \Magento\Catalog\Model\Product $productModel
100+
* @param \Magento\Catalog\Helper\Image $catalogImageHelper
88101
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
89102
*/
90103
public function __construct(
@@ -97,7 +110,9 @@ public function __construct(
97110
\Magento\Catalog\Model\ResourceModel\Product\Gallery $mediaGalleryResourceModel,
98111
\Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler,
99112
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
100-
$connectionName = null
113+
$connectionName = null,
114+
\Magento\Catalog\Model\Product $productModel = null,
115+
\Magento\Catalog\Helper\Image $catalogImageHelper = null
101116
) {
102117
$this->_productResource = $productResource;
103118
$this->_storeManager = $storeManager;
@@ -107,6 +122,9 @@ public function __construct(
107122
$this->mediaGalleryReadHandler = $mediaGalleryReadHandler;
108123
$this->_mediaConfig = $mediaConfig;
109124
$this->_sitemapData = $sitemapData;
125+
$this->productModel = $productModel ?: ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
126+
$this->catalogImageHelper = $catalogImageHelper ?: ObjectManager::getInstance()
127+
->get(\Magento\Catalog\Helper\Image::class);
110128
parent::__construct($context, $connectionName);
111129
}
112130

@@ -339,7 +357,7 @@ protected function _loadProductImages($product, $storeId)
339357
) {
340358
$imagesCollection = [
341359
new \Magento\Framework\DataObject(
342-
['url' => $this->_getMediaConfig()->getBaseMediaUrlAddition() . $product->getImage()]
360+
['url' => $this->getProductImageUrl($product->getImage())]
343361
),
344362
];
345363
}
@@ -348,7 +366,7 @@ protected function _loadProductImages($product, $storeId)
348366
// Determine thumbnail path
349367
$thumbnail = $product->getThumbnail();
350368
if ($thumbnail && $product->getThumbnail() != self::NOT_SELECTED_IMAGE) {
351-
$thumbnail = $this->_getMediaConfig()->getBaseMediaUrlAddition() . $thumbnail;
369+
$thumbnail = $this->getProductImageUrl($thumbnail);
352370
} else {
353371
$thumbnail = $imagesCollection[0]->getUrl();
354372
}
@@ -378,11 +396,10 @@ protected function _getAllProductImages($product, $storeId)
378396

379397
$imagesCollection = [];
380398
if ($gallery) {
381-
$productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
382399
foreach ($gallery as $image) {
383400
$imagesCollection[] = new \Magento\Framework\DataObject(
384401
[
385-
'url' => $productMediaPath . $image['file'],
402+
'url' => $this->getProductImageUrl($image['file']),
386403
'caption' => $image['label'] ? $image['label'] : $image['label_default'],
387404
]
388405
);
@@ -396,9 +413,28 @@ protected function _getAllProductImages($product, $storeId)
396413
* Get media config
397414
*
398415
* @return \Magento\Catalog\Model\Product\Media\Config
416+
* @deprecated No longer used, as we're getting full image URL from getProductImageUrl method
417+
* @see getProductImageUrl()
399418
*/
400419
protected function _getMediaConfig()
401420
{
402421
return $this->_mediaConfig;
403422
}
423+
424+
/**
425+
* Get product image URL from image filename and path
426+
*
427+
* @param string $image
428+
* @return string
429+
*/
430+
private function getProductImageUrl($image)
431+
{
432+
$productObject = $this->productModel;
433+
$imgUrl = $this->catalogImageHelper
434+
->init($productObject, 'product_page_image_large')
435+
->setImageFile($image)
436+
->getUrl();
437+
438+
return $imgUrl;
439+
}
404440
}

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ protected function _isSplitRequired($row)
453453
* @param null|string $lastmod
454454
* @param null|string $changefreq
455455
* @param null|string $priority
456-
* @param null|array $images
456+
* @param null|array|\Magento\Framework\DataObject $images
457457
* @return string
458458
* Sitemap images
459459
* @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
@@ -478,7 +478,7 @@ protected function _getSitemapRow($url, $lastmod = null, $changefreq = null, $pr
478478
// Add Images to sitemap
479479
foreach ($images->getCollection() as $image) {
480480
$row .= '<image:image>';
481-
$row .= '<image:loc>' . htmlspecialchars($this->_getMediaUrl($image->getUrl())) . '</image:loc>';
481+
$row .= '<image:loc>' . htmlspecialchars($image->getUrl()) . '</image:loc>';
482482
$row .= '<image:title>' . htmlspecialchars($images->getTitle()) . '</image:title>';
483483
if ($image->getCaption()) {
484484
$row .= '<image:caption>' . htmlspecialchars($image->getCaption()) . '</image:caption>';
@@ -488,9 +488,7 @@ protected function _getSitemapRow($url, $lastmod = null, $changefreq = null, $pr
488488
// Add PageMap image for Google web search
489489
$row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail">';
490490
$row .= '<Attribute name="name" value="' . htmlspecialchars($images->getTitle()) . '"/>';
491-
$row .= '<Attribute name="src" value="' . htmlspecialchars(
492-
$this->_getMediaUrl($images->getThumbnail())
493-
) . '"/>';
491+
$row .= '<Attribute name="src" value="' . htmlspecialchars($images->getThumbnail()) . '"/>';
494492
$row .= '</DataObject></PageMap>';
495493
}
496494

@@ -596,6 +594,7 @@ protected function _getBaseDir()
596594
*/
597595
protected function _getStoreBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK)
598596
{
597+
/** @var \Magento\Store\Model\Store $store */
599598
$store = $this->_storeManager->getStore($this->getStoreId());
600599
$isSecure = $store->isUrlSecure();
601600
return rtrim($store->getBaseUrl($type, $isSecure), '/') . '/';
@@ -618,6 +617,8 @@ protected function _getUrl($url, $type = \Magento\Framework\UrlInterface::URL_TY
618617
*
619618
* @param string $url
620619
* @return string
620+
* @deprecated No longer used, as we're generating product image URLs inside collection instead
621+
* @see \Magento\Sitemap\Model\ResourceModel\Catalog\Product::_loadProductImages()
621622
*/
622623
protected function _getMediaUrl($url)
623624
{

app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ protected function _getModelMock($mockBeforeSave = false)
535535
]
536536
)
537537
);
538+
539+
$storeBaseMediaUrl = 'http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/';
538540
$this->_sitemapProductMock->expects(
539541
$this->any()
540542
)->method(
@@ -553,13 +555,16 @@ protected function _getModelMock($mockBeforeSave = false)
553555
[
554556
'collection' => [
555557
new \Magento\Framework\DataObject(
556-
['url' => 'image1.png', 'caption' => 'caption & > title < "']
558+
[
559+
'url' => $storeBaseMediaUrl.'i/m/image1.png',
560+
'caption' => 'caption & > title < "'
561+
]
557562
),
558563
new \Magento\Framework\DataObject(
559-
['url' => 'image_no_caption.png', 'caption' => null]
564+
['url' => $storeBaseMediaUrl.'i/m/image_no_caption.png', 'caption' => null]
560565
),
561566
],
562-
'thumbnail' => 'thumbnail.jpg',
567+
'thumbnail' => $storeBaseMediaUrl.'t/h/thumbnail.jpg',
563568
'title' => 'Product & > title < "',
564569
]
565570
),

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-4.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
<changefreq>monthly</changefreq>
1515
<priority>0.5</priority>
1616
<image:image>
17-
<image:loc>http://store.com/image1.png</image:loc>
17+
<image:loc>http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/i/m/image1.png</image:loc>
1818
<image:title>Product &amp; &gt; title &lt; &quot;</image:title>
1919
<image:caption>caption &amp; &gt; title &lt; &quot;</image:caption>
2020
</image:image>
2121
<image:image>
22-
<image:loc>http://store.com/image_no_caption.png</image:loc>
22+
<image:loc>http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/i/m/image_no_caption.png</image:loc>
2323
<image:title>Product &amp; &gt; title &lt; &quot;</image:title>
2424
</image:image>
2525
<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0">
2626
<DataObject type="thumbnail">
2727
<Attribute name="name" value="Product &amp; &gt; title &lt; &quot;"/>
28-
<Attribute name="src" value="http://store.com/thumbnail.jpg"/>
28+
<Attribute name="src" value="http://store.com/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/t/h/thumbnail.jpg"/>
2929
</DataObject>
3030
</PageMap>
3131
</url>

0 commit comments

Comments
 (0)