Skip to content

Commit d59a6fd

Browse files
committed
Merge pull request #39 from magento-south/BUGS
[SOUTH] Bugfixes
2 parents 02e0378 + 0b100bc commit d59a6fd

File tree

9 files changed

+232
-4
lines changed

9 files changed

+232
-4
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Block\Adminhtml\Order\Create;
7+
8+
class Sidebar
9+
{
10+
/**
11+
* Get item qty
12+
*
13+
* @param \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject
14+
* @param callable $proceed
15+
* @param \Magento\Framework\DataObject $item
16+
*
17+
* @return string
18+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
19+
*/
20+
public function aroundGetItemQty(
21+
\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject,
22+
\Closure $proceed,
23+
\Magento\Framework\DataObject $item
24+
) {
25+
if ($item->getProduct()->getTypeId() == \Magento\Bundle\Model\Product\Type::TYPE_CODE) {
26+
return '';
27+
}
28+
return $proceed($item);
29+
}
30+
31+
/**
32+
* Check whether product configuration is required before adding to order
33+
*
34+
* @param \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject
35+
* @param callable $proceed
36+
* @param string $productType
37+
*
38+
* @return bool
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function aroundIsConfigurationRequired(
42+
\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject,
43+
\Closure $proceed,
44+
$productType
45+
) {
46+
if ($productType == \Magento\Bundle\Model\Product\Type::TYPE_CODE) {
47+
return true;
48+
}
49+
return $proceed($productType);
50+
}
51+
}

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
*/
2020
class Type extends \Magento\Catalog\Model\Product\Type\AbstractType
2121
{
22+
/**
23+
* Product type
24+
*/
25+
const TYPE_CODE = 'bundle';
26+
2227
/**
2328
* Product is composite
2429
*

app/code/Magento/Bundle/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
1010
<plugin name="Bundle" type="Magento\Bundle\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Bundle" sortOrder="60" />
1111
</type>
12+
<type name="Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar">
13+
<plugin name="Bundle" type="Magento\Bundle\Block\Adminhtml\Order\Create\Sidebar" sortOrder="200"/>
14+
</type>
1215
<type name="Magento\Catalog\Model\Product\CopyConstructor\Composite">
1316
<arguments>
1417
<argument name="constructors" xsi:type="array">

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public function create($attribute, $context, array $config = [])
5555
'dataType' => $this->getDataType($attribute),
5656
'add_field' => true,
5757
'visible' => $attribute->getIsVisibleInGrid(),
58+
'filter' => ($attribute->getIsFilterableInGrid())
59+
? $this->getFilterType($attribute->getFrontendInput())
60+
: null,
5861
], $config);
5962

6063
if ($attribute->usesSource()) {
@@ -92,4 +95,17 @@ protected function getDataType($attribute)
9295
? $this->dataTypeMap[$attribute->getFrontendInput()]
9396
: $this->dataTypeMap['default'];
9497
}
98+
99+
/**
100+
* Retrieve filter type by $frontendInput
101+
*
102+
* @param string $frontendInput
103+
* @return string
104+
*/
105+
protected function getFilterType($frontendInput)
106+
{
107+
$filtersMap = ['date' => 'dateRange'];
108+
$result = array_replace_recursive($this->dataTypeMap, $filtersMap);
109+
return isset($result[$frontendInput]) ? $result[$frontendInput] : $result['default'];
110+
}
95111
}

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ protected function _prepareDataForUpdate(array $rowData)
377377
$attributeParameters = $this->_attributes[$attributeCode];
378378

379379
if ('select' == $attributeParameters['type']) {
380-
$value = $attributeParameters['options'][strtolower($value)];
380+
$value = isset($attributeParameters['options'][strtolower($value)])
381+
? $attributeParameters['options'][strtolower($value)]
382+
: 0;
381383
} elseif ('datetime' == $attributeParameters['type']) {
382384
$value = (new \DateTime())->setTimestamp(strtotime($value));
383385
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);

app/code/Magento/Newsletter/Model/Queue/TransportBuilder.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Newsletter\Model\Queue;
77

8+
use Magento\Email\Model\AbstractTemplate;
9+
810
class TransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder
911
{
1012
/**
@@ -26,17 +28,30 @@ public function setTemplateData($data)
2628
return $this;
2729
}
2830

31+
/**
32+
* @param AbstractTemplate $template
33+
* @return void
34+
*/
35+
protected function setTemplateFilter(AbstractTemplate $template)
36+
{
37+
if (isset($this->templateData['template_filter'])) {
38+
$template->setTemplateFilter($this->templateData['template_filter']);
39+
}
40+
}
41+
2942
/**
3043
* @inheritdoc
3144
*/
3245
protected function prepareMessage()
3346
{
47+
/** @var AbstractTemplate $template */
3448
$template = $this->getTemplate()->setData($this->templateData);
49+
$this->setTemplateFilter($template);
3550

3651
$this->message->setMessageType(
3752
\Magento\Framework\Mail\MessageInterface::TYPE_HTML
3853
)->setBody(
39-
$template->getProcessedTemplate()
54+
$template->getProcessedTemplate($this->templateVars)
4055
)->setSubject(
4156
$template->getSubject()
4257
);

app/code/Magento/Newsletter/Model/Template/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
namespace Magento\Newsletter\Model\Template;
1313

14-
class Filter extends \Magento\Widget\Model\Template\Filter
14+
class Filter extends \Magento\Widget\Model\Template\FilterEmulate
1515
{
1616
/**
1717
* Generate widget HTML if template variables are assigned

app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ public function testGetTransport(
3232
$messageType = MessageInterface::TYPE_HTML,
3333
$bodyText = '<h1>Html message</h1>'
3434
) {
35+
$filter = $this->getMock('Magento\Email\Model\Template\Filter', [], [], '', false);
3536
$data = [
3637
'template_subject' => 'Email Subject',
3738
'template_text' => $bodyText,
3839
'template_styles' => 'Styles',
3940
'template_type' => $templateType,
41+
'template_filter' => $filter,
4042
];
4143
$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
4244
$options = ['area' => 'frontend', 'store' => 1];
@@ -52,8 +54,14 @@ public function testGetTransport(
5254
$this->returnSelf()
5355
);
5456
$template->expects($this->once())->method('getSubject')->will($this->returnValue('Email Subject'));
55-
$template->expects($this->once())->method('getProcessedTemplate')->will($this->returnValue($bodyText));
5657
$template->expects($this->once())->method('setData')->with($this->equalTo($data))->will($this->returnSelf());
58+
$template->expects($this->once())
59+
->method('getProcessedTemplate')
60+
->with($vars)
61+
->will($this->returnValue($bodyText));
62+
$template->expects($this->once())
63+
->method('setTemplateFilter')
64+
->with($filter);
5765

5866
$this->templateFactoryMock->expects(
5967
$this->once()
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Newsletter\Test\Unit\Model\Template;
7+
8+
class FilterTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Newsletter\Model\Template\Filter
12+
*/
13+
protected $filter;
14+
15+
/**
16+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $storeManager;
19+
20+
/**
21+
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $appState;
24+
25+
public function setUp()
26+
{
27+
$scopeConfig = $this->getMockForAbstractClass(
28+
'\Magento\Framework\App\Config\ScopeConfigInterface',
29+
[],
30+
'',
31+
false
32+
);
33+
$this->storeManager = $this->getMockForAbstractClass(
34+
'\Magento\Store\Model\StoreManagerInterface',
35+
[],
36+
'',
37+
false
38+
);
39+
$logger = $this->getMockForAbstractClass('\Psr\Log\LoggerInterface', [], '', false);
40+
$layout = $this->getMockForAbstractClass('\Magento\Framework\View\LayoutInterface', [], '', false);
41+
$urlModel = $this->getMockForAbstractClass('\Magento\Framework\UrlInterface', [], '', false);
42+
$string = $this->getMock('\Magento\Framework\Stdlib\StringUtils', [], [], '', false);
43+
$escaper = $this->getMock('\Magento\Framework\Escaper', [], [], '', false);
44+
$assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false);
45+
$coreVariableFactory = $this->getMock('\Magento\Variable\Model\VariableFactory', ['create'], [], '', false);
46+
$layoutFactory = $this->getMock('\Magento\Framework\View\LayoutFactory', ['create'], [], '', false);
47+
$this->appState = $this->getMock('\Magento\Framework\App\State', [], [], '', false);
48+
$emogrifier = $this->getMock('\Pelago\Emogrifier', [], [], '', false);
49+
$configVariables = $this->getMock('\Magento\Email\Model\Source\Variables', [], [], '', false);
50+
$widgetResource = $this->getMock('\Magento\Widget\Model\ResourceModel\Widget', [], [], '', false);
51+
$widget = $this->getMock('\Magento\Widget\Model\Widget', [], [], '', false);
52+
53+
$this->filter = new \Magento\Newsletter\Model\Template\Filter(
54+
$string,
55+
$logger,
56+
$escaper,
57+
$assetRepo,
58+
$scopeConfig,
59+
$coreVariableFactory,
60+
$this->storeManager,
61+
$layout,
62+
$layoutFactory,
63+
$this->appState,
64+
$urlModel,
65+
$emogrifier,
66+
$configVariables,
67+
$widgetResource,
68+
$widget
69+
);
70+
71+
}
72+
73+
public function testWidgetDirective()
74+
{
75+
$subscriber = $this->getMock('\Magento\Newsletter\Model\Subscriber', [], [], '', false);
76+
$this->filter->setVariables(['subscriber' => $subscriber]);
77+
78+
$construction = '{{widget type="\Magento\Cms\Block\Widget\Page\Link" page_id="1"}}';
79+
80+
$store = $this->getMockForAbstractClass('Magento\Store\Api\Data\StoreInterface', [], '', false);
81+
$store->expects($this->once())
82+
->method('getId')
83+
->willReturn(1);
84+
$this->storeManager->expects($this->once())
85+
->method('getStore')
86+
->willReturn($store);
87+
$this->appState->expects($this->once())
88+
->method('emulateAreaCode')
89+
->with(
90+
'frontend',
91+
[$this->filter, 'generateWidget'],
92+
[
93+
[
94+
1 => $construction,
95+
2 => 'type="\Magento\Cms\Block\Widget\Page\Link" page_id="1" store_id ="1"'
96+
]
97+
]
98+
)
99+
->willReturn(
100+
'<div class="widget block block-cms-link-inline">
101+
<a href="http://magento.test/">
102+
<span>Home page</span>
103+
</a>
104+
</div>'
105+
);
106+
107+
$this->filter->widgetDirective([
108+
1 => $construction,
109+
2 => 'type="\Magento\Cms\Block\Widget\Page\Link" page_id="1"'
110+
]);
111+
}
112+
113+
public function testWidgetDirectiveWithoutRequiredVariable()
114+
{
115+
$construction = '{{widget type="\Magento\Cms\Block\Widget\Page\Link" page_id="1"}}';
116+
117+
$this->storeManager->expects($this->never())
118+
->method('getStore');
119+
$result = $this->filter->widgetDirective(
120+
[
121+
0 => $construction,
122+
1 => 'type="\Magento\Cms\Block\Widget\Page\Link" page_id="1"'
123+
]
124+
);
125+
126+
$this->assertEquals($construction, $result);
127+
}
128+
}

0 commit comments

Comments
 (0)