Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mass product update with group min cart qty #19095

Merged
merged 3 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;

use Magento\Customer\Api\Data\GroupInterface;

/**
* Products mass update inventory tab
*
Expand All @@ -29,20 +31,29 @@ class Inventory extends \Magento\Backend\Block\Widget implements \Magento\Backen
*/
protected $disabledFields = [];

/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\CatalogInventory\Model\Source\Backorders $backorders
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
* @param array $data
* @param \Magento\Framework\Serialize\SerializerInterface|null $serializer
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Model\Source\Backorders $backorders,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
array $data = []
array $data = [],
\Magento\Framework\Serialize\SerializerInterface $serializer = null
) {
$this->_backorders = $backorders;
$this->stockConfiguration = $stockConfiguration;
$this->serializer = $serializer ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\SerializerInterface::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -70,11 +81,13 @@ public function getFieldSuffix()
* Retrieve current store id
*
* @return int
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getStoreId()
{
$storeId = $this->getRequest()->getParam('store');
return (int) $storeId;
$storeId = (int)$this->getRequest()->getParam('store');

return $storeId;
}

/**
Expand All @@ -88,6 +101,22 @@ public function getDefaultConfigValue($field)
return $this->stockConfiguration->getDefaultConfigValue($field);
}

/**
* Returns min_sale_qty configuration for the ALL Customer Group
*
* @return float
*/
public function getDefaultMinSaleQty()
{
$default = $this->stockConfiguration->getDefaultConfigValue('min_sale_qty');
if (!is_numeric($default)) {
$default = $this->serializer->unserialize($default);
$default = $default[GroupInterface::CUST_GROUP_ALL] ?? 1;
}

return (float) $default;
}

/**
* Tab settings
*
Expand All @@ -99,6 +128,8 @@ public function getTabLabel()
}

/**
* Return Tab title.
*
* @return \Magento\Framework\Phrase
*/
public function getTabTitle()
Expand All @@ -107,22 +138,24 @@ public function getTabTitle()
}

/**
* @return bool
* @inheritdoc
*/
public function canShowTab()
{
return true;
}

/**
* @return bool
* @inheritdoc
*/
public function isHidden()
{
return false;
}

/**
* Get availability status.
*
* @param string $fieldName
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;

use Magento\Customer\Api\Data\GroupInterface;

/**
* Class InventoryTest
*/
Expand Down Expand Up @@ -68,7 +70,8 @@ protected function setUp()
[
'context' => $this->contextMock,
'backorders' => $this->backordersMock,
'stockConfiguration' => $this->stockConfigurationMock
'stockConfiguration' => $this->stockConfigurationMock,
'serializer' => new \Magento\Framework\Serialize\Serializer\Json(),
]
);
}
Expand Down Expand Up @@ -126,6 +129,32 @@ public function testGetDefaultConfigValue()
$this->assertEquals('return-value', $this->inventory->getDefaultConfigValue('field-name'));
}

/**
* @dataProvider getDefaultMinSaleQtyDataProvider
* @param string $expected
* @param string $default
*/
public function testGetDefaultMinSaleQty($expected, $default)
{
$this->stockConfigurationMock->method('getDefaultConfigValue')->willReturn($default);
$this->assertEquals($expected, $this->inventory->getDefaultMinSaleQty());
}

public function getDefaultMinSaleQtyDataProvider()
{
return [
'single-default-value' => [
22, '22'
],
'no-default-for-all-group' => [
1, json_encode(['12' => '111'])
],
'default-for-all-group' => [
5, json_encode(['12' => '111', GroupInterface::CUST_GROUP_ALL => '5'])
]
];
}

/**
* Run test getTabLabel method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<div class="field">
<input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
name="<?= /* @escapeNotVerified */ $block->getFieldSuffix() ?>[min_sale_qty]"
value="<?= /* @escapeNotVerified */ $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
value="<?= /* @escapeNotVerified */ $block->getDefaultMinSaleQty() * 1 ?>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use @noEscape here.

disabled="disabled"/>
</div>
<div class="field choice">
Expand Down