From a24a47fd6787e7ee2b67cb94f3c3e42578545105 Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Wed, 11 Jan 2017 14:52:01 +0200 Subject: [PATCH 1/4] MAGETWO-52577: [GitHub] Set Product as New from Date and Design Active From is set when setting Special Price #4387 --- .../Model/Attribute/Backend/Startdate.php | 3 -- .../SetSpecialPriceStartDateObserver.php | 42 +++++++++++++++++++ app/code/Magento/Catalog/etc/events.xml | 3 ++ .../Api/ProductRepositoryInterfaceTest.php | 18 ++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php diff --git a/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php b/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php index 7f7fa8ba62aed..e81d6b0d59404 100644 --- a/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php +++ b/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php @@ -47,9 +47,6 @@ protected function _getValueForSave($object) if ($startDate === false) { return false; } - if ($startDate == '' && $object->getSpecialPrice()) { - $startDate = $this->_localeDate->date(); - } return $startDate; } diff --git a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php new file mode 100644 index 0000000000000..640509fb12d79 --- /dev/null +++ b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php @@ -0,0 +1,42 @@ +localeDate = $localeDate; + } + + /** + * Setting Special Price start date + * + * @param \Magento\Framework\Event\Observer $observer + * @return $this + */ + public function execute(\Magento\Framework\Event\Observer $observer) + { + /** @var $product \Magento\Catalog\Model\Product */ + $product = $observer->getEvent()->getProduct(); + if ($product->getSpecialPrice() && !$product->getSpecialFromDate()) { + $product->setData('special_from_date', $this->localeDate->date()); + } + + return $this; + } +} diff --git a/app/code/Magento/Catalog/etc/events.xml b/app/code/Magento/Catalog/etc/events.xml index a495a47fe9da0..cfd5e35e4ab3e 100644 --- a/app/code/Magento/Catalog/etc/events.xml +++ b/app/code/Magento/Catalog/etc/events.xml @@ -51,4 +51,7 @@ + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index aa3e33996636b..8441d4155bfa8 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -28,6 +28,7 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract const RESOURCE_PATH = '/V1/products'; const KEY_TIER_PRICES = 'tier_prices'; + const KEY_SPECIAL_PRICE = 'special_price'; const KEY_CATEGORY_LINKS = 'category_links'; /** @@ -1122,4 +1123,21 @@ private function getMediaGalleryData($filename1, $encodedImage, $filename2) ], ]; } + + public function testSpecialPrice() + { + $productData = $this->getSimpleProductData(); + $productData['custom_attributes'] = [ + ['attribute_code' => self::KEY_SPECIAL_PRICE, 'value' => '1'] + ]; + $this->saveProduct($productData); + $response = $this->getProduct($productData[ProductInterface::SKU]); + $customAttributes = $response['custom_attributes']; + $this->assertNotEmpty($customAttributes); + $missingAttributes = ['news_from_date', 'custom_design_from']; + $expectedAttribute = ['special_price', 'special_from_date']; + $attributeCodes = array_column($customAttributes, 'attribute_code'); + $this->assertEquals(0, count(array_intersect($attributeCodes, $missingAttributes))); + $this->assertEquals(2, count(array_intersect($attributeCodes, $expectedAttribute))); + } } From 7dd0162c383b0f89992c98324c9856247c021eff Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Wed, 11 Jan 2017 15:51:47 +0200 Subject: [PATCH 2/4] MAGETWO-52577: [GitHub] Set Product as New from Date and Design Active From is set when setting Special Price #4387 --- app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php | 3 --- .../Catalog/Observer/SetSpecialPriceStartDateObserver.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php b/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php index e81d6b0d59404..0ac38555ec860 100644 --- a/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php +++ b/app/code/Magento/Catalog/Model/Attribute/Backend/Startdate.php @@ -44,9 +44,6 @@ protected function _getValueForSave($object) { $attributeName = $this->getAttribute()->getName(); $startDate = $object->getData($attributeName); - if ($startDate === false) { - return false; - } return $startDate; } diff --git a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php index 640509fb12d79..4dda2a55dea8b 100644 --- a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php +++ b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php @@ -12,7 +12,7 @@ class SetSpecialPriceStartDateObserver implements ObserverInterface /** * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface */ - protected $localeDate; + private $localeDate; /** * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate From 331e44f12db32477f685aaed3a06bb8dd8a8e39b Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Thu, 12 Jan 2017 10:32:39 +0200 Subject: [PATCH 3/4] MAGETWO-52577: [GitHub] Set Product as New from Date and Design Active From is set when setting Special Price #4387 --- ...eStartDateObserver.php => SetSpecialPriceStartDate.php} | 7 +++++-- app/code/Magento/Catalog/etc/events.xml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) rename app/code/Magento/Catalog/Observer/{SetSpecialPriceStartDateObserver.php => SetSpecialPriceStartDate.php} (85%) diff --git a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php similarity index 85% rename from app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php rename to app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php index 4dda2a55dea8b..ab14e12477d5c 100644 --- a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDateObserver.php +++ b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php @@ -7,7 +7,10 @@ use Magento\Framework\Event\ObserverInterface; -class SetSpecialPriceStartDateObserver implements ObserverInterface +/** + * Set value for Special Price start date + */ +class SetSpecialPriceStartDate implements ObserverInterface { /** * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface @@ -24,7 +27,7 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface } /** - * Setting Special Price start date + * Set the current date to Special Price From attribute if it empty * * @param \Magento\Framework\Event\Observer $observer * @return $this diff --git a/app/code/Magento/Catalog/etc/events.xml b/app/code/Magento/Catalog/etc/events.xml index cfd5e35e4ab3e..ed59ce6e74b50 100644 --- a/app/code/Magento/Catalog/etc/events.xml +++ b/app/code/Magento/Catalog/etc/events.xml @@ -52,6 +52,6 @@ - + From 16bfaf2ddc92ee822ee13778807ca93656390cd7 Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Tue, 17 Jan 2017 12:39:28 +0200 Subject: [PATCH 4/4] MAGETWO-52577: [GitHub] Set Product as New from Date and Design Active From is set when setting Special Price #4387 --- .../Test/Block/Adminhtml/Product/ProductForm.xml | 11 ++++++++++- .../Catalog/Test/Fixture/CatalogProductSimple.xml | 8 ++++---- .../Product/CreateSimpleProductEntityTest.xml | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml index ebab7cc83b283..ab19ffbd06dd5 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml @@ -45,7 +45,10 @@ select - + + [name="product[news_from_date]"] + css selector + [name="product[news_to_date]"] css selector @@ -190,6 +193,12 @@ \Magento\Ui\Test\Block\Adminhtml\Section [data-index='schedule-design-update'] css selector + + + [name="product[custom_design_from]"] + css selector + + \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section\Options diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml index 8f73299d5f6dc..17d4ed88f8158 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml @@ -29,8 +29,8 @@ - - + + @@ -80,8 +80,8 @@ - - + + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml index b27012fccfbf7..a4c79f67bdccf 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml @@ -55,11 +55,14 @@ Simple Product short_description %isolation% Simple Product description %isolation% 52 + + 659 drop_down_with_one_option_fixed_price simple_drop_down_with_one_option_fixed_price MAGETWO-23029 +