Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #13659: [Port 2.3-develop] Show redirect_to_base config in store scope (by @JeroenVanLeusden)
 - #13638: Forwardport-pull-13494: Fixing of Problem with updating stock item qty and stock status (by @p-bystritsky)
 - #13632: [Forwardport] #11485 do the stock check on default level because the stock on website level isn't updated and should be ignored (by @nmalevanec)
 - #13571: Fixed fatal error on "magento sampledata:deploy" when magento is not installed.  (by @4quaternion)


Fixed GitHub Issues:
 - #11484: Visual Merchandiser show prices of out of stock simple products for the associated configurable product. (reported by @joost-florijn-kega) has been fixed in #13632 by @nmalevanec in 2.3-develop branch
   Related commits:
     1. 4a46800
  • Loading branch information
magento-engcom-team authored Feb 15, 2018
2 parents a86fd3f + 711c95a commit 83ada52
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 30 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Backend/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
<label>Web</label>
<tab>general</tab>
<resource>Magento_Config::web</resource>
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="0" showInStore="0">
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Url Options</label>
<field id="use_store" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Add Store Code to Urls</label>
Expand All @@ -435,7 +435,7 @@
<![CDATA[<strong style="color:red">Warning!</strong> When using Store Code in URLs, in some cases system may not work properly if URLs without Store Codes are specified in the third party services (e.g. PayPal etc.).]]>
</comment>
</field>
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Auto-redirect to Base URL</label>
<source_model>Magento\Config\Model\Config\Source\Web\Redirect</source_model>
<comment>I.e. redirect from http://example.com/store/ to http://www.example.com/store/</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function process(Select $select)
['stock' => $stockStatusTable],
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
)
->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK)
->where('stock.website_id = ?', 0);
}

return $select;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function prepareQuantityAndStockStatus(StockItemInterface $stockItem, ar
) {
unset($quantityAndStockStatus['is_in_stock']);
}
if (isset($quantityAndStockStatus['qty'])
if (array_key_exists('qty', $quantityAndStockStatus)
&& $stockItem->getQty() == $quantityAndStockStatus['qty']
) {
unset($quantityAndStockStatus['qty']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public function testProcess()
[]
)
->willReturnSelf();
$this->select->expects($this->once())

$this->select->expects($this->exactly(2))
->method('where')
->with('stock.stock_status = ?', Stock::STOCK_IN_STOCK)
->withConsecutive(
['stock.stock_status = ?', Stock::STOCK_IN_STOCK, null],
['stock.website_id = ?', 0, null]
)
->willReturnSelf();

$this->stockStatusBaseSelectProcessor->process($this->select);
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/SampleData/Model/Dependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Magento\Framework\Config\Composer\Package;
use Magento\Framework\Config\Composer\PackageFactory;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterfaceFactory;
use Magento\Framework\Filesystem\Directory\ReadFactory;

/**
* Sample Data dependency
Expand Down Expand Up @@ -40,7 +40,7 @@ class Dependency
private $componentRegistrar;

/**
* @var ReadInterfaceFactory
* @var ReadFactory
*/
private $directoryReadFactory;

Expand All @@ -51,21 +51,21 @@ class Dependency
* @param Filesystem $filesystem @deprecated 2.3.0 $directoryReadFactory is used instead
* @param PackageFactory $packageFactory
* @param ComponentRegistrarInterface $componentRegistrar
* @param Filesystem\Directory\ReadInterfaceFactory|null $directoryReadFactory
* @param Filesystem\Directory\ReadFactory|null $directoryReadFactory
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
ComposerInformation $composerInformation,
Filesystem $filesystem,
PackageFactory $packageFactory,
ComponentRegistrarInterface $componentRegistrar,
\Magento\Framework\Filesystem\Directory\ReadInterfaceFactory $directoryReadFactory = null
\Magento\Framework\Filesystem\Directory\ReadFactory $directoryReadFactory = null
) {
$this->composerInformation = $composerInformation;
$this->packageFactory = $packageFactory;
$this->componentRegistrar = $componentRegistrar;
$this->directoryReadFactory = $directoryReadFactory ?:
ObjectManager::getInstance()->get(ReadInterfaceFactory::class);
ObjectManager::getInstance()->get(ReadFactory::class);
}

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ private function getModuleComposerPackage($moduleDir)
*/
foreach ([$moduleDir, $moduleDir . DIRECTORY_SEPARATOR . '..'] as $dir) {
/** @var Filesystem\Directory\ReadInterface $directory */
$directory = $this->directoryReadFactory->create(['path' => $dir]);
$directory = $this->directoryReadFactory->create($dir);
if ($directory->isExist('composer.json') && $directory->isReadable('composer.json')) {
/** @var Package $package */
return $this->packageFactory->create(['json' => json_decode($directory->readFile('composer.json'))]);
Expand Down
27 changes: 18 additions & 9 deletions app/code/Magento/SampleData/Test/Unit/Model/DependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Filesystem;
use Magento\Framework\Phrase;
use Magento\SampleData\Model\Dependency;
use Magento\Framework\Filesystem\DriverPool;

class DependencyTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public function testPackagesFromComposerSuggest(
$moduleDirectories
);

$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadInterfaceFactory::class)
$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
Expand Down Expand Up @@ -88,7 +89,8 @@ public static function dataPackagesFromComposerSuggest()
'composerJsonGenerator' => function (DependencyTest $test) {
return [
[
['path' => 'app/code/LocalModule'],
'app/code/LocalModule',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'local/module',
Expand All @@ -99,11 +101,13 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'app/code/LocalModuleWithoutComposerJson'],
'app/code/LocalModuleWithoutComposerJson',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'vendor/company/module'],
'vendor/company/module',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'company/module',
Expand All @@ -114,7 +118,8 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'vendor/company2/module/src/..'],
'vendor/company2/module/src/..',
DriverPool::FILE,
$test->stubComposerJsonReader(
[
'name' => 'company2/module',
Expand All @@ -125,19 +130,23 @@ public static function dataPackagesFromComposerSuggest()
)
],
[
['path' => 'vendor/company2/module/src'],
'vendor/company2/module/src',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'vendor/company/module/..'],
'vendor/company/module/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'app/code/LocalModuleWithoutComposerJson/..'],
'app/code/LocalModuleWithoutComposerJson/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
[
['path' => 'app/code/LocalModule/..'],
'app/code/LocalModule/..',
DriverPool::FILE,
$test->stubFileNotFoundReader()
],
];
Expand Down
6 changes: 0 additions & 6 deletions app/code/Magento/SampleData/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@
</argument>
</arguments>
</type>
<virtualType name="Magento\SampleData\Filesystem\Directory\Read" type="Magento\Framework\Filesystem\Directory\Read">
<arguments>
<argument name="driver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
</arguments>
</virtualType>
<preference for="Magento\Framework\Filesystem\Directory\ReadInterface" type="Magento\SampleData\Filesystem\Directory\Read" />
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
const KEY_PRODUCT_ID = StockStatusInterface::PRODUCT_ID;
const KEY_CUSTOM_ATTRIBUTES = 'custom_attributes';
const KEY_ATTRIBUTE_CODE = \Magento\Eav\Api\Data\AttributeInterface::ATTRIBUTE_CODE;
const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status';
const KEY_IS_IN_STOCK = 'is_in_stock';

const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status';
const PRODUCT_SKU = 'sku-test-catalog-inventory';

/**
Expand Down Expand Up @@ -159,6 +160,36 @@ public function testSimpleProductCreationWithoutSpecifyingCatalogInventory()
$this->assertTrue($response);
}

/**
* Tests updating product stock item data when previously product was created without specified stock_item
*/
public function testUpdatingQuantity()
{
// create a simple product with catalog inventory
$qty = null;
$productData = $this->getSimpleProductData($qty);
$response = $this->saveProduct($productData);
$stockItemData = $response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM];

$this->assertEquals($qty, $stockItemData[self::KEY_QTY]);
$this->assertEquals(false, $stockItemData[self::KEY_IS_IN_STOCK]);

// update a created product with catalog inventory
$qty = 1;
$inStock = true;
$response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM][self::KEY_QTY] = $qty;
$response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM][self::KEY_IS_IN_STOCK] = $inStock;
$responseUpdated = $this->updateProduct($response);
$stockItemDataUpdated = $responseUpdated[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM];

$this->assertEquals($qty, $stockItemDataUpdated[self::KEY_QTY]);
$this->assertEquals($inStock, $stockItemDataUpdated[self::KEY_IS_IN_STOCK]);

// delete the product; expect that all goes well
$response = $this->deleteProduct($productData[ProductInterface::SKU]);
$this->assertTrue($response);
}

// --- my helpers -----------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -195,7 +226,7 @@ protected function getSimpleProductData($qty = 1000)
[self::KEY_ATTRIBUTE_CODE => 'description', 'value' => 'My Product Description'],
[
self::KEY_ATTRIBUTE_CODE => self::CODE_QUANTITY_AND_STOCK_STATUS,
'value' => ['is_in_stock' => true, 'qty' => $qty]
'value' => [self::KEY_IS_IN_STOCK => true, 'qty' => $qty]
],
];
}
Expand All @@ -214,7 +245,7 @@ protected function getStockItemData($qty = 1000)
return [
self::KEY_STOCK_ITEM => [
self::KEY_QTY => $qty,
'is_in_stock' => true,
self::KEY_IS_IN_STOCK => true,
'is_qty_decimal' => false,
'show_default_notification_message' => false,
'use_config_min_qty' => true,
Expand Down

0 comments on commit 83ada52

Please sign in to comment.