Skip to content

Commit 4068de1

Browse files
merge magento/2.3-develop into magento-epam/EPAM-PR-45
2 parents 6523252 + 05217b0 commit 4068de1

File tree

10 files changed

+278
-5
lines changed

10 files changed

+278
-5
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Tree.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
}
7272

7373
/**
74-
* @return void
74+
* @inheritdoc
7575
*/
7676
protected function _construct()
7777
{
@@ -80,7 +80,7 @@ protected function _construct()
8080
}
8181

8282
/**
83-
* @return $this
83+
* @inheritdoc
8484
*/
8585
protected function _prepareLayout()
8686
{
@@ -182,6 +182,8 @@ public function getSuggestedCategoriesJson($namePart)
182182
}
183183

184184
/**
185+
* Get add root button html
186+
*
185187
* @return string
186188
*/
187189
public function getAddRootButtonHtml()
@@ -190,6 +192,8 @@ public function getAddRootButtonHtml()
190192
}
191193

192194
/**
195+
* Get add sub button html
196+
*
193197
* @return string
194198
*/
195199
public function getAddSubButtonHtml()
@@ -198,6 +202,8 @@ public function getAddSubButtonHtml()
198202
}
199203

200204
/**
205+
* Get expand button html
206+
*
201207
* @return string
202208
*/
203209
public function getExpandButtonHtml()
@@ -206,6 +212,8 @@ public function getExpandButtonHtml()
206212
}
207213

208214
/**
215+
* Get collapse button html
216+
*
209217
* @return string
210218
*/
211219
public function getCollapseButtonHtml()
@@ -214,6 +222,8 @@ public function getCollapseButtonHtml()
214222
}
215223

216224
/**
225+
* Get store switcher
226+
*
217227
* @return string
218228
*/
219229
public function getStoreSwitcherHtml()
@@ -222,6 +232,8 @@ public function getStoreSwitcherHtml()
222232
}
223233

224234
/**
235+
* Get loader tree url
236+
*
225237
* @param bool|null $expanded
226238
* @return string
227239
*/
@@ -235,6 +247,8 @@ public function getLoadTreeUrl($expanded = null)
235247
}
236248

237249
/**
250+
* Get nodes url
251+
*
238252
* @return string
239253
*/
240254
public function getNodesUrl()
@@ -243,6 +257,8 @@ public function getNodesUrl()
243257
}
244258

245259
/**
260+
* Get switcher tree url
261+
*
246262
* @return string
247263
*/
248264
public function getSwitchTreeUrl()
@@ -254,6 +270,8 @@ public function getSwitchTreeUrl()
254270
}
255271

256272
/**
273+
* Get is was expanded
274+
*
257275
* @return bool
258276
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
259277
*/
@@ -263,6 +281,8 @@ public function getIsWasExpanded()
263281
}
264282

265283
/**
284+
* Get move url
285+
*
266286
* @return string
267287
*/
268288
public function getMoveUrl()
@@ -271,6 +291,8 @@ public function getMoveUrl()
271291
}
272292

273293
/**
294+
* Get tree
295+
*
274296
* @param mixed|null $parenNodeCategory
275297
* @return array
276298
*/
@@ -282,6 +304,8 @@ public function getTree($parenNodeCategory = null)
282304
}
283305

284306
/**
307+
* Get tree json
308+
*
285309
* @param mixed|null $parenNodeCategory
286310
* @return string
287311
*/
@@ -367,7 +391,7 @@ protected function _getNodeJson($node, $level = 0)
367391
}
368392
}
369393

370-
if ($isParent || $node->getLevel() < 2) {
394+
if ($isParent || $node->getLevel() < 1) {
371395
$item['expanded'] = true;
372396
}
373397

@@ -390,6 +414,8 @@ public function buildNodeName($node)
390414
}
391415

392416
/**
417+
* Is category movable
418+
*
393419
* @param Node|array $node
394420
* @return bool
395421
*/
@@ -403,6 +429,8 @@ protected function _isCategoryMoveable($node)
403429
}
404430

405431
/**
432+
* Is parent selected category
433+
*
406434
* @param Node|array $node
407435
* @return bool
408436
*/

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<element name="categoryInTreeUnderRoot" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{name}}')]" parameterized="true"/>
1717
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
1818
<element name="treeContainer" type="block" selector=".tree-holder" />
19+
<element name="expandRootCategory" type="text" selector="img.x-tree-elbow-end-plus"/>
1920
</section>
2021
</sections>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminFilterByNameByStoreViewOnProductGridTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Filter products"/>
15+
<title value="Product grid filtering by store view level attribute"/>
16+
<description value="Verify that products grid can be filtered on all store view level by attribute"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-98755"/>
19+
<useCaseId value="MAGETWO-98335"/>
20+
<group value="catalog"/>
21+
</annotations>
22+
<before>
23+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
24+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
25+
</before>
26+
<after>
27+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
28+
<actionGroup ref="ClearProductsFilterActionGroup" stepKey="clearProductsFilter"/>
29+
<actionGroup ref="logout" stepKey="logout"/>
30+
</after>
31+
<amOnPage url="{{AdminProductEditPage.url($$createSimpleProduct.id$$)}}" stepKey="goToEditPage"/>
32+
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="switchToDefaultStoreView">
33+
<argument name="storeView" value="_defaultStore.name"/>
34+
</actionGroup>
35+
<scrollToTopOfPage stepKey="scrollToTopOfAdminProductFormSection"/>
36+
<click selector="{{AdminProductFormSection.productNameUseDefault}}" stepKey="uncheckUseDefault"/>
37+
<fillField selector="{{AdminProductFormSection.productName}}" userInput="{{SimpleProduct.name}}" stepKey="fillNewName"/>
38+
<actionGroup ref="saveProductForm" stepKey="saveSimpleProduct"/>
39+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
40+
<actionGroup ref="filterProductGridByName" stepKey="filterGridByName">
41+
<argument name="product" value="SimpleProduct"/>
42+
</actionGroup>
43+
<see selector="{{AdminProductGridSection.firstProductRow}}" userInput="{{SimpleProduct2.name}}" stepKey="seeProductNameInGrid"/>
44+
</test>
45+
</tests>

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
*/
66
namespace Magento\Catalog\Ui\DataProvider\Product;
77

8+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Eav\Model\Entity\Attribute\AttributeInterface;
11+
812
/**
913
* Collection which is used for rendering product list in the backend.
1014
*
1115
* Used for product grid and customizes behavior of the default Product collection for grid needs.
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1218
*/
1319
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
1420
{
@@ -25,4 +31,63 @@ protected function _productLimitationJoinPrice()
2531
$this->_productLimitationFilters->setUsePriceIndex(false);
2632
return $this->_productLimitationPrice(true);
2733
}
34+
35+
/**
36+
* Add attribute filter to collection
37+
*
38+
* @param AttributeInterface|integer|string|array $attribute
39+
* @param null|string|array $condition
40+
* @param string $joinType
41+
* @return $this
42+
* @throws LocalizedException
43+
*/
44+
public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
45+
{
46+
$storeId = (int)$this->getStoreId();
47+
if ($attribute === 'is_saleable'
48+
|| is_array($attribute)
49+
|| $storeId !== $this->getDefaultStoreId()
50+
) {
51+
return parent::addAttributeToFilter($attribute, $condition, $joinType);
52+
}
53+
54+
if ($attribute instanceof AttributeInterface) {
55+
$attributeModel = $attribute;
56+
} else {
57+
$attributeModel = $this->getEntity()->getAttribute($attribute);
58+
if ($attributeModel === false) {
59+
throw new LocalizedException(
60+
__('Invalid attribute identifier for filter (%1)', get_class($attribute))
61+
);
62+
}
63+
}
64+
65+
if ($attributeModel->isScopeGlobal() || $attributeModel->getBackend()->isStatic()) {
66+
return parent::addAttributeToFilter($attribute, $condition, $joinType);
67+
}
68+
69+
$this->addAttributeToFilterAllStores($attributeModel, $condition);
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Add attribute to filter by all stores
76+
*
77+
* @param Attribute $attributeModel
78+
* @param array $condition
79+
* @return void
80+
*/
81+
private function addAttributeToFilterAllStores(Attribute $attributeModel, array $condition): void
82+
{
83+
$tableName = $this->getTable($attributeModel->getBackendTable());
84+
$entity = $this->getEntity();
85+
$fKey = 'e.' . $this->getEntityPkName($entity);
86+
$pKey = $tableName . '.' . $this->getEntityPkName($entity);
87+
$condition = "({$pKey} = {$fKey}) AND ("
88+
. $this->_getConditionSql("{$tableName}.value", $condition)
89+
. ')';
90+
$selectExistsInAllStores = $this->getConnection()->select()->from($tableName);
91+
$this->getSelect()->exists($selectExistsInAllStores, $condition);
92+
}
2893
}

app/code/Magento/Cms/Test/Mftf/Test/AdminAddWidgetToWYSIWYGWithCatalogCategoryLinkTypeTest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
<selectOption selector="{{WidgetSection.WidgetTemplate}}" userInput="Category Link Block Template" stepKey="selectTemplate" />
4747
<click selector="{{WidgetSection.BtnChooser}}" stepKey="clickSelectCategoryBtn" />
4848
<waitForLoadingMaskToDisappear stepKey="wait3"/>
49-
<click userInput="$$createPreReqCategory.name$$" stepKey="selectPreCreateCategory" />
49+
<click selector="{{AdminCategorySidebarTreeSection.expandRootCategory}}" stepKey="expandRootCategory" />
50+
<waitForElementVisible selector="{{WidgetSection.PreCreateCategory('$$createPreReqCategory.name$$')}}" stepKey="expandWait" />
51+
<click selector="{{WidgetSection.PreCreateCategory('$$createPreReqCategory.name$$')}}" stepKey="selectPreCreateCategory" />
5052
<waitForElementNotVisible selector="{{WidgetSection.SelectCategoryTitle}}" stepKey="waitForSlideoutCloses1" />
5153
<click selector="{{WidgetSection.InsertWidget}}" stepKey="clickInsertWidget" />
5254
<waitForElementNotVisible selector="{{WidgetSection.InsertWidgetTitle}}" stepKey="waitForSlideOutCloses2" />

app/code/Magento/Cms/Test/Mftf/Test/AdminAddWidgetToWYSIWYGWithCatalogProductLinkTypeTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
<selectOption selector="{{WidgetSection.WidgetTemplate}}" userInput="Product Link Block Template" stepKey="selectTemplate" />
5151
<click selector="{{WidgetSection.BtnChooser}}" stepKey="clickSelectPageBtn" />
5252
<waitForLoadingMaskToDisappear stepKey="wait4"/>
53+
<click selector="{{AdminCategorySidebarTreeSection.expandRootCategory}}" stepKey="expandRootCategory" />
54+
<waitForElementVisible selector="{{WidgetSection.PreCreateCategory('$$createPreReqCategory.name$$')}}" stepKey="expandWait" />
5355
<click selector="{{WidgetSection.PreCreateCategory('$$createPreReqCategory.name$$')}}" stepKey="selectPreCategory" />
5456
<waitForLoadingMaskToDisappear stepKey="waitLoadingMask" />
5557
<click selector="{{WidgetSection.PreCreateProduct('$$createPreReqProduct.name$$')}}" stepKey="selectPreProduct" />

app/code/Magento/Sales/Block/Adminhtml/Totals.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Sales\Block\Adminhtml;
77

8+
use Magento\Sales\Model\Order;
9+
10+
/**
11+
* Adminhtml sales totals block
12+
*/
813
class Totals extends \Magento\Sales\Block\Order\Totals
914
{
1015
/**
@@ -67,12 +72,16 @@ protected function _initTotals()
6772
if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
6873
$this->getSource()->getShippingDescription())
6974
) {
75+
$shippingLabel = __('Shipping & Handling');
76+
if ($this->isFreeShipping($this->getOrder()) && $this->getSource()->getDiscountDescription()) {
77+
$shippingLabel .= sprintf(' (%s)', $this->getSource()->getDiscountDescription());
78+
}
7079
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
7180
[
7281
'code' => 'shipping',
7382
'value' => $this->getSource()->getShippingAmount(),
7483
'base_value' => $this->getSource()->getBaseShippingAmount(),
75-
'label' => __('Shipping & Handling'),
84+
'label' => $shippingLabel,
7685
]
7786
);
7887
}
@@ -109,4 +118,23 @@ protected function _initTotals()
109118

110119
return $this;
111120
}
121+
122+
/**
123+
* Availability of free shipping in at least one order item
124+
*
125+
* @param Order $order
126+
* @return bool
127+
*/
128+
private function isFreeShipping(Order $order): bool
129+
{
130+
$isFreeShipping = false;
131+
foreach ($order->getItems() as $orderItem) {
132+
if ($orderItem->getFreeShipping() == '1') {
133+
$isFreeShipping = true;
134+
break;
135+
}
136+
}
137+
138+
return $isFreeShipping;
139+
}
112140
}

0 commit comments

Comments
 (0)