Skip to content
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 @@ -72,6 +72,10 @@ public function execute(int $entityId, int $storeId): bool
['child_products' => $this->resourceConnection->getTableName('catalog_product_entity')],
'child_products.entity_id = bundle_selections.product_id',
[]
)->joinInner(
['child_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')],
'child_stock_item.product_id = child_products.entity_id',
[]
)->group(
['bundle_options.parent_id', 'bundle_options.option_id']
)->where(
Expand Down Expand Up @@ -103,18 +107,36 @@ public function execute(int $entityId, int $storeId): bool
'1',
'0'
);

$hasMinRequiredQuantity = $connection->getCheckSql(
'required = 1 AND manage_stock = 1 AND selection_can_change_qty = 0',
'(qty >= bundle_selections.selection_qty OR backorders > 0) AND is_in_stock = 1',
'1'
);

$requiredInStock = $connection->getCheckSql(
'required = 1 AND manage_stock = 1 AND selection_can_change_qty = 1',
'(qty >= 0 OR backorders > 0) AND is_in_stock = 1',
'1'
);

$optionsSaleabilitySelect->columns([
'required' => 'bundle_options.required',
'is_salable' => $isOptionSalableExpr,
'is_required_and_unsalable' => $isRequiredOptionUnsalable,
'has_min_required_quantity' => $hasMinRequiredQuantity,
'required_in_stock' => $requiredInStock
]);

$select = $connection->select()->from(
$optionsSaleabilitySelect,
[new \Zend_Db_Expr('(MAX(is_salable) = 1 AND MAX(is_required_and_unsalable) = 0)')]
[new \Zend_Db_Expr(
'(MAX(is_salable) = 1 AND MAX(is_required_and_unsalable) = 0)' .
'AND MIN(required_in_stock) = 1 AND MIN(has_min_required_quantity) = 1'
)]
);
$isSalable = $connection->fetchOne($select);

$isSalable = $connection->fetchOne($select);
return (bool) $isSalable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item\StockItemCriteriaMapper;

/**
* Class StockItemCriteria
* Build criteria to filter products on catalog_stockinventory table
*/
class StockItemCriteria extends AbstractCriteria implements \Magento\CatalogInventory\Api\StockItemCriteriaInterface
{
Expand Down Expand Up @@ -55,7 +55,11 @@ public function setScopeFilter($scope)
*/
public function setProductsFilter($products)
{
$this->data['products_filter'] = [$products];
if (is_array($products)) {
$this->data['products_filter'] = $products;
} else {
$this->data['products_filter'] = [$products];
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
/**
* Update stock status of configurable products based on children products stock status
*
* @param array $childrenIds
* @param array<string|int> $childrenIds
* @return void
*/
public function execute(array $childrenIds): void
Expand All @@ -70,6 +70,17 @@ public function execute(array $childrenIds): void
}
}

/**
* Updates the parent stock status based on children statuses
*
* @param int $parentId
* @return void
*/
public function executeFromParent(int $parentId): void
{
$this->processStockForParent($parentId);
}

/**
* Update stock status of configurable product based on children products stock status
*
Expand Down Expand Up @@ -106,6 +117,7 @@ private function processStockForParent(int $productId): void
if ($this->isNeedToUpdateParent($parentStockItem, $childrenIsInStock)) {
$parentStockItem->setIsInStock($childrenIsInStock);
$parentStockItem->setStockStatusChangedAuto(1);
// @phpstan-ignore method.notFound
$parentStockItem->setStockStatusChangedAutomaticallyFlag(true);
$this->stockItemRepository->save($parentStockItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\ConfigurableProduct\Model\Inventory;

use Magento\Catalog\Model\Product\Type;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Catalog\Api\Data\ProductInterface as Product;
use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
Expand All @@ -20,10 +21,7 @@
*/
class ParentItemProcessor implements ParentItemProcessorInterface
{
/**
* @var ChangeParentStockStatus
*/
private $changeParentStockStatus;
private ChangeParentStockStatus $changeParentStockStatus;

/**
* @param Configurable $configurableType
Expand All @@ -50,8 +48,12 @@ public function __construct(
* @param Product $product
* @return void
*/
public function process(Product $product)
public function process(Product $product): void
{
$this->changeParentStockStatus->execute([$product->getId()]);
if ($product->getTypeId() === Type::TYPE_SIMPLE) {
$this->changeParentStockStatus->execute([$product->getId()]);
} elseif ($product->getTypeId() === Configurable::TYPE_CODE) {
$this->changeParentStockStatus->executeFromParent((int)$product->getId());
}
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Helper/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function convertStreetLines($origStreets, $toCount)
}
}

return $lines;
return array_filter($lines);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function outputValue($format = ElementFactory::OUTPUT_FORMAT_TEXT)
$output = implode("<br />", $values);
break;
case ElementFactory::OUTPUT_FORMAT_ONELINE:
$output = implode(" ", $values);
$output = trim(implode(" ", $values), ' ');
break;
default:
$output = implode("\n", $values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected function _initSelect()
{
parent::_initSelect();
$this->joinRegionNameTable();

return $this;
}

Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/Test/Unit/Helper/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public static function getConvertStreetLinesDataProvider()
return [
[['street1', 'street2', 'street3', 'street4'], 3, ['street1 street2', 'street3', 'street4']],
[['street1', 'street2', 'street3', 'street4'], 2, ['street1 street2', 'street3 street4']],
[['street1', ''], 2, ['street1']]
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

namespace Magento\Backend\Block\Page;

use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\ProductMetadata;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Test \Magento\Backend\Block\Page\Footer
*
Expand All @@ -16,7 +20,7 @@ class FooterTest extends \PHPUnit\Framework\TestCase
/**
* Test Product Version Value
*/
const TEST_PRODUCT_VERSION = '222.333.444';
private const TEST_PRODUCT_VERSION = '222.333.444';

/**
* @var \Magento\Backend\Block\Page\Footer
Expand All @@ -26,13 +30,14 @@ class FooterTest extends \PHPUnit\Framework\TestCase
protected function setUp(): void
{
parent::setUp();
$productMetadataMock = $this->getMockBuilder(\Magento\Framework\App\ProductMetadata::class)
->onlyMethods(['getVersion'])
$productMetadataMock = $this->getMockBuilder(ProductMetadata::class)
->disableOriginalConstructor()
->getMock();

$productMetadataMock->expects($this->once())
->method('getVersion')
->method('getDistributionVersion')
->willReturn($this::TEST_PRODUCT_VERSION);

$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
Expand All @@ -44,6 +49,8 @@ protected function setUp(): void

public function testToHtml()
{
/** @var \Magento\Framework\App\CacheInterface $cacheManager */
Bootstrap::getObjectManager()->create(CacheInterface::class);
$footerContent = $this->block->toHtml();
$this->assertStringContainsString(
'ver. ' . $this::TEST_PRODUCT_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Bundle\Model\Product;

use Magento\Framework\Exception\NoSuchEntityException;

/**
* Test class for \Magento\Bundle\Model\Product\Type (bundle product type)
*
Expand Down Expand Up @@ -216,6 +218,7 @@ public function testIsSaleableOnBundleWithoutSaleableSelectionsOnRequiredOption(
/**
* Check bundle product is NOT saleable if
* there are not enough qty of selection on required option
* when user cannot define own quantities
*
* @magentoAppIsolation enabled
* @covers \Magento\Bundle\Model\Product\Type::isSalable
Expand All @@ -224,9 +227,7 @@ public function testIsSaleableOnBundleWithoutSaleableSelectionsOnRequiredOption(
public function testIsSaleableOnBundleWithNotEnoughQtyOfSelection()
{
$this->setQtyForSelections(['simple1', 'simple2', 'simple3'], 1);

$bundleProduct = $this->productRepository->get('bundle-product');

$this->assertFalse(
$bundleProduct->isSalable(),
'Bundle product supposed to be non saleable'
Expand Down Expand Up @@ -354,4 +355,22 @@ private function setQtyForSelections($productsSku, $qty)
$this->productRepository->save($product);
}
}

/**
* Check bundle product is not salable if required option where user can
* set own quantity is not in stock
*
* @return void
* @magentoAppIsolation enabled
* @throws NoSuchEntityException
*/
public function testIsSalableOnBundleWithRequiredOptionUserCanChangeQtyWithoutStock()
{
$product = $this->productRepository->get('bundle-product-checkbox-required-option');
$this->setQtyForSelections(['simple1'], 0);
$this->assertFalse(
$product->isSalable(),
'Bundle product with required option that has 0 stock should not be salable'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,50 @@

Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');

if (!function_exists('prepareBundleOptions')) {
function prepareBundleOptions(Magento\Catalog\Model\Product $product)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
if ($product->getBundleOptionsData()) {
$options = [];
foreach ($product->getBundleOptionsData() as $key => $optionData) {
if (!(bool)$optionData['delete']) {
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
->create(['data' => $optionData]);
$option->setSku($product->getSku());
$option->setOptionId(null);

$links = [];
$bundleLinks = $product->getBundleSelectionsData();
if (!empty($bundleLinks[$key])) {
foreach ($bundleLinks[$key] as $linkData) {
if (!(bool)$linkData['delete']) {
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
->create(['data' => $linkData]);
$linkProduct = $productRepository->getById($linkData['product_id']);
$link->setSku($linkProduct->getSku());
$link->setQty($linkData['selection_qty']);
if (isset($linkData['selection_can_change_qty'])) {
$link->setCanChangeQuantity((bool)$linkData['selection_can_change_qty']);
}
$links[] = $link;
}
}
$option->setProductLinks($links);
$options[] = $option;
}
}
}
$extension = $product->getExtensionAttributes();
$extension->setBundleProductOptions($options);
$product->setExtensionAttributes($extension);
}
$productRepository->save($product, true);
}
}

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
Expand Down Expand Up @@ -177,36 +221,42 @@
]
);

if ($product->getBundleOptionsData()) {
$options = [];
foreach ($product->getBundleOptionsData() as $key => $optionData) {
if (!(bool)$optionData['delete']) {
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
->create(['data' => $optionData]);
$option->setSku($product->getSku());
$option->setOptionId(null);

$links = [];
$bundleLinks = $product->getBundleSelectionsData();
if (!empty($bundleLinks[$key])) {
foreach ($bundleLinks[$key] as $linkData) {
if (!(bool)$linkData['delete']) {
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
->create(['data' => $linkData]);
$linkProduct = $productRepository->getById($linkData['product_id']);
$link->setSku($linkProduct->getSku());
$link->setQty($linkData['selection_qty']);
$links[] = $link;
}
}
$option->setProductLinks($links);
$options[] = $option;
}
}
}
$extension = $product->getExtensionAttributes();
$extension->setBundleProductOptions($options);
$product->setExtensionAttributes($extension);
}
$bundleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
$bundleProduct->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
->setId(4)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Bundle Product Checkbox Required Option')
->setSku('bundle-product-checkbox-required-option')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setPriceView(0)
->setSkuType(1)
->setWeightType(1)
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
->setPrice(10.0)
->setShipmentType(Magento\Catalog\Model\Product\Type\AbstractType::SHIPMENT_TOGETHER)
->setBundleOptionsData([
[
'title' => 'Checkbox Options',
'default_title' => 'Checkbox Options',
'type' => 'checkbox',
'required' => 1,
'delete' => '',
],
])
->setBundleSelectionsData([
[
[
'product_id' => 10,
'selection_qty' => 1,
'selection_can_change_qty' => 1,
'delete' => '',
'option_id' => 6
],
]
]);

$productRepository->save($product, true);
prepareBundleOptions($product);
prepareBundleOptions($bundleProduct);
Loading
Loading