Skip to content

Commit

Permalink
Merge pull request #1456 from magento-engcom/2.1-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.1
 - MAGETWO-72252: Backport of MAGETWO-52577 for Magento 2.1: [GitHub] Set Product as Ne… #10751
 - MAGETWO-72251: Backport of MAGETWO-65607 for Magento 2.1: [GitHub][PR] Check return … #10750
 - MAGETWO-71643: [BUGFIX] Flat Category reindexList of AllChildren if the url_key of t… #10557
  • Loading branch information
ishakhsuvarov committed Sep 4, 2017
2 parents 0e7ca82 + c9179cd commit 5cfad89
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 13 deletions.
Expand Up @@ -44,12 +44,6 @@ protected function _getValueForSave($object)
{
$attributeName = $this->getAttribute()->getName();
$startDate = $object->getData($attributeName);
if ($startDate === false) {
return false;
}
if ($startDate == '' && $object->getSpecialPrice()) {
$startDate = $this->_localeDate->date();
}

return $startDate;
}
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/Model/Category.php
Expand Up @@ -1093,6 +1093,9 @@ public function reindex()
$flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
if (!$flatIndexer->isScheduled()) {
$flatIndexer->reindexRow($this->getId());
if ($this->dataHasChangedFor('url_key')) {
$flatIndexer->reindexList(explode(',', $this->getAllChildren()));
}
}
}
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
Expand Down
45 changes: 45 additions & 0 deletions app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Observer;

use Magento\Framework\Event\ObserverInterface;

/**
* Set value for Special Price start date
*/
class SetSpecialPriceStartDate implements ObserverInterface
{
/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
*/
private $localeDate;

/**
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @codeCoverageIgnore
*/
public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate)
{
$this->localeDate = $localeDate;
}

/**
* Set the current date to Special Price From attribute if it empty
*
* @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;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/events.xml
Expand Up @@ -54,4 +54,7 @@
<event name="admin_system_config_changed_section_catalog">
<observer name="catalog_update_price_attribute" instance="Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange" />
</event>
<event name="catalog_product_save_before">
<observer name="set_special_price_start_date" instance="Magento\Catalog\Observer\SetSpecialPriceStartDate" />
</event>
</config>
Expand Up @@ -39,10 +39,15 @@ public function getFinalPrice($qty, $product)
*/
public function getPrice($product)
{
if ($product->getCustomOption('simple_product')) {
return $product->getCustomOption('simple_product')->getProduct()->getPrice();
} else {
return 0;
if (!empty($product)) {
$simpleProductOption = $product->getCustomOption('simple_product');
if (!empty($simpleProductOption)) {
$simpleProduct = $simpleProductOption->getProduct();
if (!empty($simpleProduct)) {
return $simpleProduct->getPrice();
}
}
}
return 0;
}
}
Expand Up @@ -21,6 +21,7 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
const RESOURCE_PATH = '/V1/products';

const KEY_TIER_PRICES = 'tier_prices';
const KEY_SPECIAL_PRICE = 'special_price';

/**
* @var array
Expand Down Expand Up @@ -828,4 +829,21 @@ private function getStockItemData()
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
];
}

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)));
}
}
Expand Up @@ -45,7 +45,10 @@
<visibility>
<input>select</input>
</visibility>
<news_from_date />
<news_from_date>
<selector>[name="product[news_from_date]"]</selector>
<strategy>css selector</strategy>
</news_from_date>
<news_to_date>
<selector>[name="product[news_to_date]"]</selector>
<strategy>css selector</strategy>
Expand Down Expand Up @@ -178,6 +181,12 @@
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
<selector>[data-index='schedule-design-update']</selector>
<strategy>css selector</strategy>
<fields>
<custom_design_from>
<selector>[name="product[custom_design_from]"]</selector>
<strategy>css selector</strategy>
</custom_design_from>
</fields>
</schedule-design-update>
<customer-options>
<class>\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section\Options</class>
Expand Down
Expand Up @@ -29,8 +29,8 @@
<field name="country_of_manufacture" is_required="0" />
<field name="created_at" is_required="1" />
<field name="custom_design" is_required="0" />
<field name="custom_design_from" is_required="0" />
<field name="custom_design_to" is_required="0" />
<field name="custom_design_from" is_required="0" group="schedule-design-update" source="Magento\Backend\Test\Fixture\Source\Date" />
<field name="custom_design_to" is_required="0" group="schedule-design-update" source="Magento\Backend\Test\Fixture\Source\Date" />
<field name="custom_layout_update" is_required="0" />
<field name="description" is_required="0" group="content" />
<field name="gallery" is_required="0" />
Expand Down
Expand Up @@ -55,11 +55,14 @@
<data name="product/data/short_description" xsi:type="string">Simple Product short_description %isolation%</data>
<data name="product/data/description" xsi:type="string">Simple Product description %isolation%</data>
<data name="product/data/weight" xsi:type="string">52</data>
<data name="product/data/news_from_date" xsi:type="string"></data>
<data name="product/data/custom_design_from" xsi:type="string"></data>
<data name="product/data/quantity_and_stock_status/qty" xsi:type="string">659</data>
<data name="product/data/custom_options/dataset" xsi:type="string">drop_down_with_one_option_fixed_price</data>
<data name="product/data/checkout_data/dataset" xsi:type="string">simple_drop_down_with_one_option_fixed_price</data>
<data name="product/data/price/dataset" xsi:type="string">MAGETWO-23029</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductForm" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInGrid" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInCategory" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductPage" />
Expand Down

0 comments on commit 5cfad89

Please sign in to comment.