Skip to content

Commit

Permalink
Merge pull request #3543 from magento-tsg-csl3/2.2-develop-pr14
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.2 (pr14)
  • Loading branch information
viktym authored Dec 18, 2018
2 parents a0614c2 + 7f5f142 commit d8267c2
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 24 deletions.
24 changes: 23 additions & 1 deletion app/code/Magento/Checkout/Model/DefaultConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ public function getConfig()
$quote = $this->checkoutSession->getQuote();
$quoteId = $quote->getId();
$email = $quote->getShippingAddress()->getEmail();
$quoteItemData = $this->getQuoteItemData();
$output['formKey'] = $this->formKey->getFormKey();
$output['customerData'] = $this->getCustomerData();
$output['quoteData'] = $this->getQuoteData();
$output['quoteItemData'] = $this->getQuoteItemData();
$output['quoteItemData'] = $quoteItemData;
$output['quoteMessages'] = $this->getQuoteItemsMessages($quoteItemData);
$output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
$output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
if ($email && !$this->isCustomerLoggedIn()) {
Expand Down Expand Up @@ -314,6 +316,7 @@ public function getConfig()
);
$output['postCodes'] = $this->postCodesConfig->getPostCodes();
$output['imageData'] = $this->imageProvider->getImages($quoteId);

$output['totalsData'] = $this->getTotalsData();
$output['shippingPolicy'] = [
'isEnabled' => $this->scopeConfig->isSetFlag(
Expand Down Expand Up @@ -448,6 +451,7 @@ private function getQuoteItemData()
$quoteItem->getProduct(),
'product_thumbnail_image'
)->getUrl();
$quoteItemData[$index]['message'] = $quoteItem->getMessage();
}
}
return $quoteItemData;
Expand Down Expand Up @@ -759,4 +763,22 @@ private function getAttributeLabels(array $customAttribute, string $customAttrib

return $attributeOptionLabels;
}

/**
* Get notification messages for the quote items
*
* @param array $quoteItemData
* @return array
*/
private function getQuoteItemsMessages(array $quoteItemData): array
{
$quoteItemsMessages = [];
if ($quoteItemData) {
foreach ($quoteItemData as $item) {
$quoteItemsMessages[$item['item_id']] = $item['message'];
}
}

return $quoteItemsMessages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<see stepKey="s95" selector="{{OrderDetailsInformationSection.itemsOrdered}}" userInput="$$simpleproduct1.name$$" />
<amOnPage stepKey="s96" url="{{AdminCustomerPage.url}}"/>
<waitForPageLoad stepKey="s97"/>
<waitForElementVisible selector="{{AdminCustomerFiltersSection.filtersButton}}" time="30" stepKey="waitFiltersButton"/>
<click stepKey="s98" selector="{{AdminCustomerFiltersSection.filtersButton}}"/>
<fillField stepKey="s99" selector="{{AdminCustomerFiltersSection.emailInput}}" userInput="$$simpleuscustomer.email$$"/>
<click stepKey="s100" selector="{{AdminCustomerFiltersSection.apply}}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@
<item name="component" xsi:type="string">Magento_Checkout/js/view/summary/item/details/subtotal</item>
<item name="displayArea" xsi:type="string">after_details</item>
</item>
<item name="message" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/summary/item/details/message</item>
<item name="displayArea" xsi:type="string">item_message</item>
</item>
</item>
</item>
</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define(['uiComponent'], function (Component) {
'use strict';

var quoteMessages = window.checkoutConfig.quoteMessages;

return Component.extend({
defaults: {
template: 'Magento_Checkout/summary/item/details/message'
},
displayArea: 'item_message',
quoteMessages: quoteMessages,

/**
* @param {Object} item
* @return {null}
*/
getMessage: function (item) {
if (this.quoteMessages[item['item_id']]) {
return this.quoteMessages[item['item_id']];
}

return null;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
</div>
<!-- /ko -->
</div>
<!-- ko foreach: getRegion('item_message') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div class="cart item message notice" if="getMessage($parents[1])">
<div data-bind="text: getMessage($parents[1])"></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
}

.product-item {
.product-item-details {
&:extend(.abs-add-clearfix all);
}

.product-item-inner {
display: table;
margin: 0 0 @indent__s;
Expand Down Expand Up @@ -166,6 +170,10 @@
}
}
}

.message {
margin-top: 10px;
}
}

.actions-toolbar {
Expand Down
19 changes: 17 additions & 2 deletions lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class TransportBuilder
*/
protected $templateOptions;

/**
* Mail from address
*
* @var string|array
*/
private $from;

/**
* Mail Transport
*
Expand Down Expand Up @@ -178,8 +185,7 @@ public function setReplyTo($email, $name = null)
*/
public function setFrom($from)
{
$result = $this->_senderResolver->resolve($from);
$this->message->setFrom($result['email'], $result['name']);
$this->from = $from;
return $this;
}

Expand Down Expand Up @@ -256,6 +262,7 @@ protected function reset()
$this->templateIdentifier = null;
$this->templateVars = null;
$this->templateOptions = null;
$this->from = null;
return $this;
}

Expand Down Expand Up @@ -289,6 +296,14 @@ protected function prepareMessage()
->setBody($body)
->setSubject(html_entity_decode($template->getSubject(), ENT_QUOTES));

if ($this->from) {
$from = $this->_senderResolver->resolve(
$this->from,
$template->getDesignConfig()->getStore()
);
$this->message->setFrom($from['email'], $from['name']);
}

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Framework\Mail\Test\Unit\Template;

use Magento\Framework\App\TemplateTypesInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Mail\MessageInterface;

/**
Expand Down Expand Up @@ -99,17 +100,37 @@ protected function setUp()
*/
public function testGetTransport($templateType, $messageType, $bodyText, $templateNamespace)
{
$this->builder->setTemplateModel($templateNamespace);

$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
$options = ['area' => 'frontend', 'store' => 1];
$from = 'email_from';
$sender = ['email' => 'from@example.com', 'name' => 'name'];

$template = $this->createMock(\Magento\Framework\Mail\TemplateInterface::class);
$this->builder->setTemplateModel($templateNamespace);
$this->builder->setFrom($from);

$template = $this->createPartialMock(
\Magento\Framework\Mail\TemplateInterface::class,
[
'setVars',
'isPlain',
'setOptions',
'getSubject',
'getType',
'processTemplate',
'getDesignConfig',
]
);
$template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf();
$template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf();
$template->expects($this->once())->method('getSubject')->willReturn('Email Subject');
$template->expects($this->once())->method('getType')->willReturn($templateType);
$template->expects($this->once())->method('processTemplate')->willReturn($bodyText);
$template->method('getDesignConfig')->willReturn(new DataObject($options));

$this->senderResolverMock->expects($this->once())
->method('resolve')
->with($from, 1)
->willReturn($sender);

$this->templateFactoryMock->expects($this->once())
->method('get')
Expand All @@ -128,6 +149,9 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
->method('setBody')
->with($this->equalTo($bodyText))
->willReturnSelf();
$this->messageMock->method('setFrom')
->with($sender['email'], $sender['name'])
->willReturnSelf();

$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);

Expand Down Expand Up @@ -161,24 +185,6 @@ public function getTransportDataProvider()
];
}

/**
* @return void
*/
public function testSetFrom()
{
$sender = ['email' => 'from@example.com', 'name' => 'name'];
$this->senderResolverMock->expects($this->once())
->method('resolve')
->with($sender)
->willReturn($sender);
$this->messageMock->expects($this->once())
->method('setFrom')
->with('from@example.com', 'name')
->willReturnSelf();

$this->builder->setFrom($sender);
}

/**
* @return void
*/
Expand Down

0 comments on commit d8267c2

Please sign in to comment.