Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3-develop' into MSI-698
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.lock
  • Loading branch information
Valeriy Nayda committed Mar 28, 2018
2 parents e6587be + bd5bc6b commit 6686cf0
Show file tree
Hide file tree
Showing 40 changed files with 555 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ define([
);

_.each(data, function (row) {
var attributesText;

if (row.productId) {
index = _.indexOf(productIdsToDelete, row.productId);

Expand All @@ -364,36 +362,8 @@ define([
);
}
}
product = this.getProductData(row);

attributesText = '';
_.each(row.options, function (attribute) {
if (attributesText) {
attributesText += ', ';
}
attributesText += attribute['attribute_label'] + ': ' + attribute.label;
}, this);

product = {
'id': row.productId,
'product_link': row.productUrl,
'name': row.name,
'sku': row.sku,
'status': row.status,
'price': row.price,
'price_currency': row.priceCurrency,
'price_string': row.priceCurrency + row.price,
'weight': row.weight,
'qty': row.quantity,
'variationKey': row.variationKey,
'configurable_attribute': row.attribute,
'thumbnail_image': row.images.preview,
'media_gallery': row['media_gallery'],
'swatch_image': row['swatch_image'],
'small_image': row['small_image'],
image: row.image,
'thumbnail': row.thumbnail,
'attributes': attributesText
};
product[this.changedFlag] = true;
product[this.canEditField] = row.editable;
product[this.newProductField] = row.newProduct;
Expand All @@ -412,6 +382,47 @@ define([
this.unionInsertData(tmpArray);
},

/**
*
* @param {Object} row
* @returns {Object}
*/
getProductData: function (row) {
var product,
attributesText = '';

_.each(row.options, function (attribute) {
if (attributesText) {
attributesText += ', ';
}
attributesText += attribute['attribute_label'] + ': ' + attribute.label;
}, this);

product = {
'id': row.productId,
'product_link': row.productUrl,
'name': row.name,
'sku': row.sku,
'status': row.status,
'price': row.price,
'price_currency': row.priceCurrency,
'price_string': row.priceCurrency + row.price,
'weight': row.weight,
'qty': row.quantity,
'variationKey': row.variationKey,
'configurable_attribute': row.attribute,
'thumbnail_image': row.images.preview,
'media_gallery': row['media_gallery'],
'swatch_image': row['swatch_image'],
'small_image': row['small_image'],
image: row.image,
'thumbnail': row.thumbnail,
'attributes': attributesText
};

return product;
},

/**
* Remove array items matching condition.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ define([
* Make options sections.
*/
this.makeOptionSections = function () {
this.images = new self.makeImages(null);
this.price = self.price;
this.quantity = self.quantity;
};
return {
images: new this.makeImages(null),
price: this.price,
quantity: this.quantity
};
}.bind(this);

/**
* @param {Object} images
Expand Down Expand Up @@ -152,7 +154,7 @@ define([
//fill option section data
this.attributes.each(function (attribute) {
attribute.chosen.each(function (option) {
option.sections = ko.observable(new this.makeOptionSections());
option.sections = ko.observable(this.makeOptionSections());
}, this);
}, this);
//reset section.attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ define([
attributes: [],
attributesName: [$.mage.__('Images'), $.mage.__('SKU'), $.mage.__('Quantity'), $.mage.__('Price')],
sections: [],
gridTemplate: 'Magento_ConfigurableProduct/variations/steps/summary-grid'
gridTemplate: 'Magento_ConfigurableProduct/variations/steps/summary-grid',
quantityFieldName: 'quantity'
},

/** @inheritdoc */
Expand Down Expand Up @@ -112,12 +113,12 @@ define([
return memo + '-' + option.label;
}, '');
name = productName + _.reduce(options, function (memo, option) {
return memo + '-' + option.label;
}, '');
quantity = getSectionValue('quantity', options);
return memo + '-' + option.label;
}, '');
quantity = getSectionValue(this.quantityFieldName, options);

if (!quantity && productId) {
quantity = product.quantity;
quantity = product[this.quantityFieldName];
}
price = getSectionValue('price', options);

Expand All @@ -133,12 +134,12 @@ define([
images: images,
sku: sku,
name: name,
quantity: quantity,
price: price,
productId: productId,
weight: productWeight,
editable: true
};
variation[this.quantityFieldName] = quantity;

if (productId) {
variation.sku = product.sku;
Expand All @@ -163,7 +164,6 @@ define([
this.variationsExisting = gridExisting;
this.variationsNew = gridNew;
this.variationsDeleted = gridDeleted;

},

/**
Expand Down Expand Up @@ -195,7 +195,7 @@ define([
images: []
}, variation.images));
row.push(variation.sku);
row.push(variation.quantity);
row.push(variation[this.quantityFieldName]);
_.each(variation.options, function (option) {
row.push(option.label);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemsAllowedForProductType;

use Magento\Bundle\Model\Product\Type as BundleType;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;

/**
* Disable Source items management for Bundle product type.
*/
class DisableBundleTypePlugin
{
/**
* @param IsSourceItemsAllowedForProductType $subject
* @param callable $proceed
* @param string $productType
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(
IsSourceItemsAllowedForProductTypeInterface $subject,
callable $proceed,
string $productType
): bool {
if ($productType === BundleType::TYPE_CODE) {
return false;
}

return $proceed($productType);
}
}
6 changes: 5 additions & 1 deletion app/code/Magento/InventoryBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"description": "N/A",
"require": {
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
"magento/framework": "100.3.*"
"magento/framework": "100.3.*",
"magento/module-bundle": "100.3.*"
},
"suggest": {
"magento/module-inventory-configuration": "100.0.*"
},
"type": "magento2-module",
"version": "100.0.0-dev",
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/InventoryBundle/etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface">
<plugin name="disable_bundle_type"
type="Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemsAllowedForProductType\DisableBundleTypePlugin"/>
</type>
</config>
3 changes: 2 additions & 1 deletion app/code/Magento/InventoryBundle/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_InventoryBundle" setup_version="1.0.0" />
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Helper\Stock;
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface;
use Magento\InventorySalesApi\Api\IsProductSalableInterface;
use Magento\InventoryCatalog\Model\GetStockIdForCurrentWebsite;

Expand All @@ -27,16 +28,24 @@ class AdaptAssignStatusToProductPlugin
*/
private $isProductSalable;

/**
* @var DefaultStockProviderInterface
*/
private $defaultStockProvider;

/**
* @param GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite
* @param IsProductSalableInterface $isProductSalable
* @param DefaultStockProviderInterface $defaultStockProvider
*/
public function __construct(
GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite,
IsProductSalableInterface $isProductSalable
IsProductSalableInterface $isProductSalable,
DefaultStockProviderInterface $defaultStockProvider
) {
$this->getStockIdForCurrentWebsite = $getStockIdForCurrentWebsite;
$this->isProductSalable = $isProductSalable;
$this->defaultStockProvider = $defaultStockProvider;
}

/**
Expand All @@ -45,6 +54,7 @@ public function __construct(
* @param Product $product
* @param int|null $status
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundAssignStatusToProduct(
Expand All @@ -53,18 +63,13 @@ public function aroundAssignStatusToProduct(
Product $product,
$status = null
) {
// TODO: https://github.com/magento-engcom/msi/issues/532
if ($product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
&& $product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
) {
return;
}

if (null === $product->getSku()) {
return;
}
if (null === $status) {
$stockId = $this->getStockIdForCurrentWebsite->execute();

$stockId = $this->getStockIdForCurrentWebsite->execute();

if ($this->defaultStockProvider->getId() !== $stockId && null === $status) {
$status = (int)$this->isProductSalable->execute($product->getSku(), $stockId);
}
$proceed($product, $status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function execute(string $sku): array

$sourceItemsInformation[] = [
SourceItemInterface::SOURCE_CODE => $sourceItem->getSourceCode(),
SourceItemInterface::QUANTITY => $sourceItem->getQuantity(),
'quantity_per_source' => $sourceItem->getQuantity(),
'source' => $source->getName(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public function execute(EventObserver $observer)
$controller = $observer->getEvent()->getController();
$configurableMatrix = $controller->getRequest()->getParam('configurable-matrix-serialized', '');

if ($configurableMatrix != "") {
if ($configurableMatrix != '') {
$productsData = json_decode($configurableMatrix, true);
foreach ($productsData as $productData) {
$sku = $productData[ProductInterface::SKU];
$sourceItems = $productData['qty_per_source'] ?? [];

$this->processSourceItems($sourceItems, $sku);
if (isset($productData['quantity_per_source']) && is_array($productData['quantity_per_source'])) {
$sku = $productData[ProductInterface::SKU];
$this->processSourceItems($productData['quantity_per_source'], $sku);
}
}
}
}
Expand All @@ -72,8 +72,9 @@ private function processSourceItems(array $sourceItems, string $productSku)
{
foreach ($sourceItems as $key => $sourceItem) {
if (!isset($sourceItem[SourceItemInterface::STATUS])) {
$sourceItems[$key][SourceItemInterface::STATUS] =
$sourceItems[$key][SourceItemInterface::QUANTITY] > 0 ? 1 : 0;
$sourceItems[$key][SourceItemInterface::QUANTITY] = $sourceItems[$key]['quantity_per_source'];
$sourceItems[$key][SourceItemInterface::STATUS]
= $sourceItems[$key][SourceItemInterface::QUANTITY] > 0 ? 1 : 0;
}
}

Expand Down
Loading

0 comments on commit 6686cf0

Please sign in to comment.