Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3915 from magento-epam/EPAM-PR-47
Browse files Browse the repository at this point in the history
- Fixed "My Wishlist - quantity input box issue"
- [GitHub] Can't use "configurable" as the group name in attribute sets M2.1 #6123
  • Loading branch information
irenelagno authored Mar 25, 2019
2 parents ff3c9b3 + 277dba9 commit 677f1b6
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 19 deletions.
7 changes: 7 additions & 0 deletions app/code/Magento/ConfigurableProduct/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,11 @@
<type name="Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector">
<plugin name="apply_tax_class_id" type="Magento\ConfigurableProduct\Plugin\Tax\Model\Sales\Total\Quote\CommonTaxCollector" />
</type>
<type name="Magento\Eav\Model\Entity\Attribute\Group">
<arguments>
<argument name="reservedSystemNames" xsi:type="array">
<item name="configurable" xsi:type="string">configurable</item>
</argument>
</arguments>
</type>
</config>
50 changes: 33 additions & 17 deletions app/code/Magento/Eav/Model/Entity/Attribute/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Eav\Model\Entity\Attribute;

use Magento\Eav\Api\Data\AttributeGroupExtensionInterface;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Exception\LocalizedException;

/**
* Entity attribute group model
*
* @api
* @method int getSortOrder()
* @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
Expand All @@ -27,6 +32,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
*/
private $translitFilter;

/**
* @var array
*/
private $reservedSystemNames = [];

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -35,7 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
* @param \Magento\Framework\Filter\Translit $translitFilter
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param array $data (optional)
* @param array $reservedSystemNames (optional)
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand All @@ -45,7 +56,8 @@ public function __construct(
\Magento\Framework\Filter\Translit $translitFilter,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
array $reservedSystemNames = []
) {
parent::__construct(
$context,
Expand All @@ -56,6 +68,7 @@ public function __construct(
$resourceCollection,
$data
);
$this->reservedSystemNames = $reservedSystemNames;
$this->translitFilter = $translitFilter;
}

Expand All @@ -74,6 +87,7 @@ protected function _construct()
* Checks if current attribute group exists
*
* @return bool
* @throws LocalizedException
* @codeCoverageIgnore
*/
public function itemExists()
Expand All @@ -85,6 +99,7 @@ public function itemExists()
* Delete groups
*
* @return $this
* @throws LocalizedException
* @codeCoverageIgnore
*/
public function deleteGroups()
Expand All @@ -110,9 +125,10 @@ public function beforeSave()
),
'-'
);
if (empty($attributeGroupCode)) {
$isReservedSystemName = in_array(strtolower($attributeGroupCode), $this->reservedSystemNames);
if (empty($attributeGroupCode) || $isReservedSystemName) {
// in the following code md5 is not used for security purposes
$attributeGroupCode = md5($groupName);
$attributeGroupCode = md5(strtolower($groupName));
}
$this->setAttributeGroupCode($attributeGroupCode);
}
Expand All @@ -121,7 +137,8 @@ public function beforeSave()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @codeCoverageIgnoreStart
*/
public function getAttributeGroupId()
Expand All @@ -130,64 +147,63 @@ public function getAttributeGroupId()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAttributeGroupName()
{
return $this->getData(self::GROUP_NAME);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAttributeSetId()
{
return $this->getData(self::ATTRIBUTE_SET_ID);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeGroupId($attributeGroupId)
{
return $this->setData(self::GROUP_ID, $attributeGroupId);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeGroupName($attributeGroupName)
{
return $this->setData(self::GROUP_NAME, $attributeGroupName);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeSetId($attributeSetId)
{
return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @return \Magento\Eav\Api\Data\AttributeGroupExtensionInterface|null
* @return AttributeGroupExtensionInterface|null
*/
public function getExtensionAttributes()
{
return $this->_getExtensionAttributes();
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
* @param AttributeGroupExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
) {
public function setExtensionAttributes(AttributeGroupExtensionInterface $extensionAttributes)
{
return $this->_setExtensionAttributes($extensionAttributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function setUp()
'resource' => $this->resourceMock,
'translitFilter' => $translitFilter,
'context' => $contextMock,
'reservedSystemNames' => ['configurable'],
];
$objectManager = new ObjectManager($this);
$this->model = $objectManager->getObject(
Expand Down Expand Up @@ -67,6 +68,8 @@ public function attributeGroupCodeDataProvider()
{
return [
['General Group', 'general-group'],
['configurable', md5('configurable')],
['configurAble', md5('configurable')],
['///', md5('///')],
];
}
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Eav/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,3 @@
</arguments>
</type>
</config>

80 changes: 80 additions & 0 deletions app/code/Magento/Wishlist/ViewModel/AllowedQuantity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Wishlist\ViewModel;

use Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\CatalogInventory\Model\StockRegistry;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* ViewModel for Wishlist Cart Block
*/
class AllowedQuantity implements ArgumentInterface
{
/**
* @var StockRegistry
*/
private $stockRegistry;

/**
* @var ItemInterface
*/
private $item;

/**
* @param StockRegistry $stockRegistry
*/
public function __construct(StockRegistry $stockRegistry)
{
$this->stockRegistry = $stockRegistry;
}

/**
* Set product configuration item
*
* @param ItemInterface $item
* @return self
*/
public function setItem(ItemInterface $item): self
{
$this->item = $item;
return $this;
}

/**
* Get product configuration item
*
* @return ItemInterface
*/
public function getItem(): ItemInterface
{
return $this->item;
}

/**
* Get min and max qty for wishlist form.
*
* @return array
*/
public function getMinMaxQty(): array
{
$product = $this->getItem()->getProduct();
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
$params = [];

$params['minAllowed'] = (float)$stockItem->getMinSaleQty();
if ($stockItem->getMaxSaleQty()) {
$params['maxAllowed'] = (float)$stockItem->getMaxSaleQty();
} else {
$params['maxAllowed'] = (float)StockDataFilter::MAX_QTY_VALUE;
}

return $params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</block>
<block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart" name="customer.wishlist.item.cart" template="Magento_Wishlist::item/column/cart.phtml" cacheable="false">
<arguments>
<argument name="allowedQuantityViewModel" xsi:type="object">Magento\Wishlist\ViewModel\AllowedQuantity</argument>
<argument name="title" translate="true" xsi:type="string">Add to Cart</argument>
</arguments>
</block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
/** @var \Magento\Wishlist\Model\Item $item */
$item = $block->getItem();
$product = $item->getProduct();
/** @var \Magento\Wishlist\ViewModel\AllowedQuantity $viewModel */
$viewModel = $block->getData('allowedQuantityViewModel');
$allowedQty = $viewModel->setItem($item)->getMinMaxQty();
?>
<?php foreach ($block->getChildNames() as $childName): ?>
<?= /* @noEscape */ $block->getLayout()->renderElement($childName, false) ?>
Expand All @@ -21,7 +24,7 @@ $product = $item->getProduct();
<div class="field qty">
<label class="label" for="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
<div class="control">
<input type="number" data-role="qty" id="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" class="input-text qty" data-validate="{'required-number':true,'validate-greater-than-zero':true}"
<input type="number" data-role="qty" id="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" class="input-text qty" data-validate="{'required-number':true,'validate-greater-than-zero':true, 'validate-item-quantity':{'minAllowed':<?= /* @noEscape */ $allowedQty['minAllowed'] ?>,'maxAllowed':<?= /* @noEscape */ $allowedQty['maxAllowed'] ?>}}"
name="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" value="<?= /* @noEscape */ (int)($block->getAddToCartQty($item) * 1) ?>">
</div>
</div>
Expand Down

0 comments on commit 677f1b6

Please sign in to comment.