Skip to content

Commit c92c640

Browse files
Merge remote-tracking branch 'remotes/github/2.3-develop' into EPAM-PR-38
2 parents ed22463 + b2f1417 commit c92c640

File tree

73 files changed

+1863
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1863
-702
lines changed

app/code/Magento/Backend/Controller/Adminhtml/Dashboard/RefreshStatistics.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
namespace Magento\Backend\Controller\Adminhtml\Dashboard;
88

9-
class RefreshStatistics extends \Magento\Reports\Controller\Adminhtml\Report\Statistics
9+
use Magento\Framework\App\Action\HttpPostActionInterface;
10+
use Magento\Reports\Controller\Adminhtml\Report\Statistics;
11+
12+
/**
13+
* Refresh Dashboard statistics action.
14+
*/
15+
class RefreshStatistics extends Statistics implements HttpPostActionInterface
1016
{
1117
/**
1218
* @param \Magento\Backend\App\Action\Context $context
@@ -25,6 +31,8 @@ public function __construct(
2531
}
2632

2733
/**
34+
* Refresh statistics.
35+
*
2836
* @return \Magento\Backend\Model\View\Result\Redirect
2937
*/
3038
public function execute()

app/code/Magento/Catalog/Block/Adminhtml/Form/Renderer/Fieldset/Element.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
namespace Magento\Catalog\Block\Adminhtml\Form\Renderer\Fieldset;
8+
79
/**
810
* Catalog fieldset element renderer
911
*
1012
* @author Magento Core Team <[email protected]>
1113
*/
12-
namespace Magento\Catalog\Block\Adminhtml\Form\Renderer\Fieldset;
13-
1414
class Element extends \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Element
1515
{
1616
/**
@@ -29,7 +29,7 @@ public function getDataObject()
2929
}
3030

3131
/**
32-
* Retireve associated with element attribute object
32+
* Retrieve associated with element attribute object
3333
*
3434
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
3535
*/
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Product\Type;
9+
10+
use Magento\Store\Model\Store;
11+
use Magento\Catalog\Model\ResourceModel\Product\Price\SpecialPrice;
12+
use Magento\Catalog\Api\Data\SpecialPriceInterface;
13+
use Magento\Store\Api\Data\WebsiteInterface;
14+
15+
/**
16+
* Product special price model.
17+
*
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20+
*/
21+
class FrontSpecialPrice extends Price
22+
{
23+
/**
24+
* @var SpecialPrice
25+
*/
26+
private $specialPrice;
27+
28+
/**
29+
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $ruleFactory
30+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
31+
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
32+
* @param \Magento\Customer\Model\Session $customerSession
33+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
34+
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
35+
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
36+
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory
37+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
38+
* @param SpecialPrice $specialPrice
39+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
40+
*/
41+
public function __construct(
42+
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $ruleFactory,
43+
\Magento\Store\Model\StoreManagerInterface $storeManager,
44+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
45+
\Magento\Customer\Model\Session $customerSession,
46+
\Magento\Framework\Event\ManagerInterface $eventManager,
47+
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
48+
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
49+
\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory,
50+
\Magento\Framework\App\Config\ScopeConfigInterface $config,
51+
SpecialPrice $specialPrice
52+
) {
53+
$this->specialPrice = $specialPrice;
54+
parent::__construct(
55+
$ruleFactory,
56+
$storeManager,
57+
$localeDate,
58+
$customerSession,
59+
$eventManager,
60+
$priceCurrency,
61+
$groupManagement,
62+
$tierPriceFactory,
63+
$config
64+
);
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
protected function _applySpecialPrice($product, $finalPrice)
71+
{
72+
if (!$product->getSpecialPrice()) {
73+
return $finalPrice;
74+
}
75+
76+
$specialPrices = $this->getSpecialPrices($product);
77+
$specialPrice = !(empty($specialPrices)) ? min($specialPrices) : $product->getSpecialPrice();
78+
79+
$specialPrice = $this->calculateSpecialPrice(
80+
$finalPrice,
81+
$specialPrice,
82+
$product->getSpecialFromDate(),
83+
$product->getSpecialToDate(),
84+
WebsiteInterface::ADMIN_CODE
85+
);
86+
$product->setData('special_price', $specialPrice);
87+
88+
return $specialPrice;
89+
}
90+
91+
/**
92+
* Get special prices.
93+
*
94+
* @param mixed $product
95+
* @return array
96+
*/
97+
private function getSpecialPrices($product): array
98+
{
99+
$allSpecialPrices = $this->specialPrice->get([$product->getSku()]);
100+
$specialPrices = [];
101+
foreach ($allSpecialPrices as $price) {
102+
if ($this->isSuitableSpecialPrice($product, $price)) {
103+
$specialPrices[] = $price['value'];
104+
}
105+
}
106+
107+
return $specialPrices;
108+
}
109+
110+
/**
111+
* Price is suitable from default and current store + start and end date are equal.
112+
*
113+
* @param mixed $product
114+
* @param array $price
115+
* @return bool
116+
*/
117+
private function isSuitableSpecialPrice($product, array $price): bool
118+
{
119+
$priceStoreId = $price[Store::STORE_ID];
120+
if (($priceStoreId == Store::DEFAULT_STORE_ID || $product->getStoreId() == $priceStoreId)
121+
&& $price[SpecialPriceInterface::PRICE_FROM] == $product->getSpecialFromDate()
122+
&& $price[SpecialPriceInterface::PRICE_TO] == $product->getSpecialToDate()) {
123+
return true;
124+
}
125+
126+
return false;
127+
}
128+
}

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductActionGroup.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@
265265
<checkOption selector="{{ProductInWebsitesSection.website(website)}}" stepKey="selectWebsite"/>
266266
</actionGroup>
267267

268+
<actionGroup name="AdminProductAddSpecialPrice">
269+
<arguments>
270+
<argument name="specialPrice" type="string"/>
271+
</arguments>
272+
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickAdvancedPricingLink1"/>
273+
<waitForElementVisible selector="{{AdminProductFormAdvancedPricingSection.specialPrice}}" stepKey="waitSpecialPrice1"/>
274+
<click selector="{{AdminProductFormAdvancedPricingSection.useDefaultPrice}}" stepKey="checkUseDefault"/>
275+
<fillField userInput="{{specialPrice}}" selector="{{AdminProductFormAdvancedPricingSection.specialPrice}}" stepKey="fillSpecialPrice"/>
276+
<click selector="{{AdminProductFormAdvancedPricingSection.doneButton}}" stepKey="clickDone"/>
277+
<waitForElementNotVisible selector="{{AdminProductFormAdvancedPricingSection.specialPrice}}" stepKey="waitForCloseModalWindow"/>
278+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickOnSaveButton"/>
279+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/>
280+
</actionGroup>
281+
268282
<!--Switch to New Store view-->
269283
<actionGroup name="SwitchToTheNewStoreView">
270284
<arguments>

app/code/Magento/Catalog/Test/Mftf/Data/CatalogStorefrontConfigData.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,26 @@
3838
<entity name="DefaultFlatCatalogProduct" type="flat_catalog_product">
3939
<data key="value">0</data>
4040
</entity>
41+
42+
<entity name="UseFlatCatalogCategoryAndProduct" type="catalog_storefront_config">
43+
<requiredEntity type="flat_catalog_product">UseFlatCatalogProduct</requiredEntity>
44+
<requiredEntity type="flat_catalog_category">UseFlatCatalogCategory</requiredEntity>
45+
</entity>
46+
47+
<entity name="UseFlatCatalogProduct" type="flat_catalog_product">
48+
<data key="value">1</data>
49+
</entity>
50+
51+
<entity name="UseFlatCatalogCategory" type="flat_catalog_category">
52+
<data key="value">1</data>
53+
</entity>
54+
55+
<entity name="DefaultFlatCatalogCategoryAndProduct" type="catalog_storefront_config">
56+
<requiredEntity type="flat_catalog_product">DefaultFlatCatalogProduct</requiredEntity>
57+
<requiredEntity type="flat_catalog_category">DefaultFlatCatalogCategory</requiredEntity>
58+
</entity>
59+
60+
<entity name="DefaultFlatCatalogCategory" type="flat_catalog_category">
61+
<data key="value">0</data>
62+
</entity>
4163
</entities>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,6 @@
187187
<section name="AdminProductFormAdvancedPricingSection">
188188
<element name="specialPrice" type="input" selector="input[name='product[special_price]']"/>
189189
<element name="doneButton" type="button" selector=".product_form_product_form_advanced_pricing_modal button.action-primary"/>
190+
<element name="useDefaultPrice" type="checkbox" selector="//input[@name='product[special_price]']/parent::div/following-sibling::div/input[@name='use_default[special_price]']"/>
190191
</section>
191192
</sections>

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,5 @@
120120
<plugin name="catalog_app_action_dispatch_controller_context_plugin"
121121
type="Magento\Catalog\Plugin\Framework\App\Action\ContextPlugin" />
122122
</type>
123+
<preference for="Magento\Catalog\Model\Product\Type\Price" type="Magento\Catalog\Model\Product\Type\FrontSpecialPrice" />
123124
</config>

app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ protected function _initMessageTemplates()
431431
);
432432
$this->_productEntity->addMessageTemplate(
433433
self::ERROR_INVALID_TYPE,
434-
__('Value for \'type\' sub attribute in \'custom_options\' attribute contains incorrect value, acceptable values are: \'dropdown\', \'checkbox\'')
434+
__(
435+
'Value for \'type\' sub attribute in \'custom_options\' attribute contains incorrect value, acceptable values are: %1',
436+
'\''.implode('\', \'', array_keys($this->_specificTypes)).'\''
437+
)
435438
);
436439
$this->_productEntity->addMessageTemplate(self::ERROR_EMPTY_TITLE, __('Please enter a value for title.'));
437440
$this->_productEntity->addMessageTemplate(
@@ -629,7 +632,7 @@ public function validateAmbiguousData()
629632
$this->_addRowsErrors(self::ERROR_AMBIGUOUS_NEW_NAMES, $errorRows);
630633
return false;
631634
}
632-
if ($this->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
635+
if ($this->getBehavior() == Import::BEHAVIOR_APPEND) {
633636
$errorRows = $this->_findOldOptionsWithTheSameTitles();
634637
if ($errorRows) {
635638
$this->_addRowsErrors(self::ERROR_AMBIGUOUS_OLD_NAMES, $errorRows);
@@ -967,11 +970,10 @@ public function validateRow(array $rowData, $rowNumber)
967970
return false;
968971
}
969972
}
970-
return true;
971973
}
972974
}
973975

974-
return false;
976+
return true;
975977
}
976978

977979
/**
@@ -1381,7 +1383,7 @@ private function setLastOptionTitle(array &$titles) : void
13811383
*/
13821384
private function removeExistingOptions(array $products, array $optionsToRemove): void
13831385
{
1384-
if ($this->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
1386+
if ($this->getBehavior() != Import::BEHAVIOR_APPEND) {
13851387
$this->_deleteEntities(array_keys($products));
13861388
} elseif (!empty($optionsToRemove)) {
13871389
// Remove options for products with empty "custom_options" row
@@ -2108,7 +2110,7 @@ private function savePreparedCustomOptions(
21082110
array $types
21092111
): void {
21102112
if ($this->_isReadyForSaving($options, $titles, $types['values'])) {
2111-
if ($this->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
2113+
if ($this->getBehavior() == Import::BEHAVIOR_APPEND) {
21122114
$this->_compareOptionsWithExisting($options, $titles, $prices, $types['values']);
21132115
$this->restoreOriginalOptionTypeIds($types['values'], $types['prices'], $types['titles']);
21142116
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/OptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ public function testValidateRowNoCustomOption()
702702
{
703703
$rowData = include __DIR__ . '/_files/row_data_no_custom_option.php';
704704
$this->_bypassModelMethodGetMultiRowFormat($rowData);
705-
$this->assertFalse($this->modelMock->validateRow($rowData, 0));
705+
$this->assertTrue($this->modelMock->validateRow($rowData, 0));
706706
}
707707

708708
/**

app/code/Magento/CatalogRule/Test/Mftf/Test/CatalogPriceRuleAndCustomerGroupMembershipArePersistedUnderLongTermCookieTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.name$$)}}" stepKey="onStorefrontCategoryPage"/>
6565
<see selector="{{StorefrontCategoryProductSection.ProductPriceByNumber('1')}}" userInput="$$createProduct.price$$" stepKey="checkPriceSimpleProduct"/>
6666

67-
<!--Login to storfront from customer and check price-->
67+
<!--Login to storefront from customer and check price-->
6868
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="logInFromCustomer">
6969
<argument name="Customer" value="$$createCustomer$$"/>
7070
</actionGroup>

0 commit comments

Comments
 (0)