Skip to content

Magento REST API returns not existing SKU when custom option was set #25461 #30667

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

Open
wants to merge 18 commits into
base: 2.5-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7e724b1
Fix for SKU without options
engcom-Hotel Oct 27, 2020
342582f
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Oct 27, 2020
12a202f
Merge branch 'mainline' into REST_API_returns_not_existing_SKU_when_c…
engcom-Hotel Oct 30, 2020
907b60b
The fix has been changed - in progress
engcom-Hotel Nov 2, 2020
e912dd0
Original SKU has been added to api response at quote and passed to th…
engcom-Hotel Nov 5, 2020
1ccf13e
Code refactoring, tests updates
engcom-Hotel Nov 6, 2020
b030e81
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 10, 2020
3f0bd36
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 11, 2020
d7ad1f6
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 12, 2020
9d1ec1c
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 12, 2020
b0176bf
MFTF coverage for the fix
engcom-Hotel Nov 17, 2020
1faf19f
Merge remote-tracking branch 'engcom-Hotel/REST_API_returns_not_exist…
engcom-Hotel Nov 17, 2020
4d7e87a
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 17, 2020
e0a2270
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 19, 2020
7954fcd
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Nov 23, 2020
bb31fb1
Refactoring
engcom-Hotel Dec 30, 2020
d514a38
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Dec 30, 2020
29e8b4a
Merge branch '2.4-develop' into REST_API_returns_not_existing_SKU_whe…
engcom-Hotel Dec 30, 2020
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
21 changes: 19 additions & 2 deletions app/code/Magento/Quote/Api/Data/CartItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface CartItemInterface extends \Magento\Framework\Api\ExtensibleDataInterfa

const KEY_SKU = 'sku';

const KEY_ORIGINAL_PRODUCT_SKU = 'original_product_sku';

const KEY_QTY = 'qty';

const KEY_NAME = 'name';
Expand Down Expand Up @@ -49,20 +51,35 @@ public function getItemId();
public function setItemId($itemId);

/**
* Returns the product SKU.
* Returns the product options SKU.
*
* @return string|null Product SKU. Otherwise, null.
*/
public function getSku();

/**
* Sets the product SKU.
* Sets the product options SKU.
*
* @param string $sku
* @return $this
*/
public function setSku($sku);

/**
* Returns the product SKU.
*
* @return string|null Product SKU. Otherwise, null.
*/
public function getOriginalProductSku();

/**
* Sets the product SKU.
*
* @param string $sku
* @return $this
*/
public function setOriginalProductSku($sku);

/**
* Returns the product quantity.
*
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public function setProduct($product)
->setProductId($product->getId())
->setProductType($product->getTypeId())
->setSku($this->getProduct()->getSku())
->setOriginalProductSku($this->getProduct()->getData('sku'))
->setName($product->getName())
->setWeight($this->getProduct()->getWeight())
->setTaxClassId($product->getTaxClassId())
Expand Down Expand Up @@ -1075,4 +1076,20 @@ public function setExtensionAttributes(\Magento\Quote\Api\Data\CartItemExtension
{
return $this->_setExtensionAttributes($extensionAttributes);
}

/**
* @inheritDoc
*/
public function getOriginalProductSku()
{
return $this->getData(self::KEY_ORIGINAL_PRODUCT_SKU);
}

/**
* @inheritDoc
*/
public function setOriginalProductSku($sku)
{
return $this->setData(self::KEY_ORIGINAL_PRODUCT_SKU, $sku);
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Quote/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
comment="Parent Item ID"/>
<column xsi:type="smallint" name="is_virtual" unsigned="true" nullable="true" identity="false"
comment="Is Virtual"/>
<column xsi:type="varchar" name="sku" nullable="true" length="255" comment="Sku"/>
<column xsi:type="varchar" name="sku" nullable="true" length="255" comment="Sku with options"/>
<column xsi:type="varchar" name="original_product_sku" nullable="true" length="255" comment="Sku"/>
<column xsi:type="varchar" name="name" nullable="true" length="255" comment="Name"/>
<column xsi:type="text" name="description" nullable="true" comment="Description"/>
<column xsi:type="text" name="applied_rule_ids" nullable="true" comment="Applied Rule Ids"/>
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/etc/fieldset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
<field name="sku">
<aspect name="to_order_item" />
</field>
<field name="original_product_sku">
<aspect name="to_order_item" />
</field>
<field name="name">
<aspect name="to_order_item" />
</field>
Expand Down
21 changes: 20 additions & 1 deletion app/code/Magento/Sales/Api/Data/OrderItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ interface OrderItemInterface extends \Magento\Framework\Api\ExtensibleDataInterf
* SKU.
*/
const SKU = 'sku';
/*
* Original product SKU.
*/
const ORIGINAL_PRODUCT_SKU = 'original_product_sku';
/*
* Name.
*/
Expand Down Expand Up @@ -389,7 +393,7 @@ interface OrderItemInterface extends \Magento\Framework\Api\ExtensibleDataInterf
const BASE_WEEE_TAX_ROW_DISPOSITION = 'base_weee_tax_row_disposition';

/**
* Parent Item
* Parent order Item
*/
const PARENT_ITEM = 'parent_item';

Expand Down Expand Up @@ -954,6 +958,13 @@ public function getRowWeight();
*/
public function getSku();

/**
* Gets the original product SKU for the order item.
*
* @return string
*/
public function getOriginalProductSku();

/**
* Gets the store ID for the order item.
*
Expand Down Expand Up @@ -1155,6 +1166,14 @@ public function setIsVirtual($isVirtual);
*/
public function setSku($sku);

/**
* Sets the SKU for the order item.
*
* @param string $sku
* @return $this
*/
public function setOriginalProductSku($sku);

/**
* Sets the name for the order item.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public function getSku()
return $this->getItem()->getSku();
}

/**
* Get original product sku
*
* @return string
*/
public function getOriginalProductSku()
{
return $this->getItem()->getOriginalProductSku();
}

/**
* Calculate total amount for the item
*
Expand Down
16 changes: 16 additions & 0 deletions app/code/Magento/Sales/Model/Order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -2415,4 +2415,20 @@ public function isProcessingAvailable()
{
return $this->getQtyToShip() > $this->getQtyToCancel();
}

/**
* @inheritDoc
*/
public function getOriginalProductSku()
{
return $this->getData(OrderItemInterface::ORIGINAL_PRODUCT_SKU);
}

/**
* @inheritDoc
*/
public function setOriginalProductSku($sku)
{
return $this->setData(OrderItemInterface::ORIGINAL_PRODUCT_SKU, $sku);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminVerifyProductSKUInOrderTest">
<annotations>
<features value="Sales"/>
<stories value="Magento REST API returns not existing SKU when custom option was set #25461 #30667"/>
<title value="Verify that order contains real SKU of products and not options sku"/>
<description value="Verify that order contains real SKU of products and not options sku"/>
<severity value="MAJOR"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createCategory"/>
<!-- Create simple with options product -->
<createData entity="SimpleProduct" stepKey="createSimpleProductWithCustomOptions">
<requiredEntity createDataKey="createCategory"/>
</createData>
<updateData createDataKey="createSimpleProductWithCustomOptions" entity="productWithDropdownOption" stepKey="updateProductWithCustomOption"/>
<!-- Create configurable product -->
<createData entity="BaseConfigurableProduct" stepKey="createConfigProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<updateData createDataKey="createConfigProduct" entity="productWithOptionRadiobutton" stepKey="updateConfigurableProductWithCustomOption"/>
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeFirstOption">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeSecondOption">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeFirstOption">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</getData>
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeSecondOption">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</getData>
<createData entity="ApiSimpleOne" stepKey="createConfigFirstChildProduct">
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeFirstOption"/>
</createData>
<createData entity="ApiSimpleTwo" stepKey="createConfigSecondChildProduct">
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeSecondOption"/>
</createData>
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeFirstOption"/>
<requiredEntity createDataKey="getConfigAttributeSecondOption"/>
</createData>
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddFirstChild">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigFirstChildProduct"/>
</createData>
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddSecondChild">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigSecondChildProduct"/>
</createData>
<!-- Create the customer -->
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
<!-- Reindex and flush the cache to display products on the category page -->
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache">
<argument name="tags" value=""/>
</actionGroup>
</before>
<after>
<!-- Delete created data -->
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToProductIndexPage"/>
<actionGroup ref="ResetProductGridToDefaultViewActionGroup" stepKey="resetProductGridToDefaultView"/>
<actionGroup ref="DeleteProductsIfTheyExistActionGroup" stepKey="deleteAllProducts"/>
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteConfigProductAttribute"/>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>
<!-- Login to Storefront as Customer -->
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer">
<argument name="Customer" value="$$createCustomer$$" />
</actionGroup>
<!-- Place the order -->
<!-- Add simple with options to cart -->
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProductWithCustomOptions.custom_attributes[url_key]$$)}}" stepKey="goSimpleProductPage"/>
<waitForPageLoad stepKey="waitForSecondProductPageLoad"/>
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectFirstOption">
<argument name="attributeLabel" value="{{ProductOptionValueDropdown.title}}"/>
<argument name="optionLabel" value="{{ProductOptionValueWithSkuDropdown1.title}}"/>
</actionGroup>
<!-- Add the product to the shopping cart -->
<actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="addSimpleProductToCart">
<argument name="productName" value="$$createSimpleProductWithCustomOptions.name$$"/>
</actionGroup>
<!-- Add configurable with options to cart -->
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="goConfigurableProductPage">
<argument name="productUrl" value="$$createConfigProduct.custom_attributes[url_key]$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddProductWithSelectedConfigurableAndCustomOptionsToCartActionGroup" stepKey="addConfigurableToCart">
<argument name="product" value="$$createConfigProduct$$"/>
<argument name="option" value="$$getConfigAttributeSecondOption.label$$"/>
<argument name="customizableOption" value="{{ProductOptionValueRadioButtons1.title}}"/>
</actionGroup>
<!-- Place the Order -->
<actionGroup ref="StorefrontOpenCheckoutPageActionGroup" stepKey="onCheckout"/>
<actionGroup ref="StorefrontCheckoutClickNextOnShippingStepActionGroup" stepKey="clickNextButton"/>
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="placeOrder"/>
<waitForPageLoad stepKey="waitForSuccess"/>
<!--Open Order View Page-->
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
<actionGroup ref="AdminOrdersPageOpenActionGroup" stepKey="openOrdersGridPage"/>
<actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="openOrderViewPage"/>
<!--Check if order has correct products sku-->
<actionGroup ref="SeeProductInItemsOrderedActionGroup" stepKey="verifySimpleProductSku">
<argument name="product" value="SimpleProduct"/>
</actionGroup>
<actionGroup ref="SeeProductInItemsOrderedActionGroup" stepKey="verifyConfigurableProductSku">
<argument name="product" value="BaseConfigurableProduct"/>
</actionGroup>
</test>
</tests>
1 change: 1 addition & 0 deletions app/code/Magento/Sales/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
<column xsi:type="smallint" name="is_virtual" unsigned="true" nullable="true" identity="false"
comment="Is Virtual"/>
<column xsi:type="varchar" name="sku" nullable="true" length="255" comment="Sku"/>
<column xsi:type="varchar" name="original_product_sku" nullable="true" length="255" comment="Product sku"/>
<column xsi:type="varchar" name="name" nullable="true" length="255" comment="Name"/>
<column xsi:type="text" name="description" nullable="true" comment="Description"/>
<column xsi:type="text" name="applied_rule_ids" nullable="true" comment="Applied Rule Ids"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ $catalogHelper = $block->getData('catalogHelper');
</div>
<div class="product-sku-block">
<span><?= $block->escapeHtml(__('SKU'))?>:</span>
<?= /* @noEscape */ implode('<br />', $catalogHelper->splitSku($block->escapeHtml($block->getSku()))) ?>
<?= /* @noEscape */
implode('<br />', $catalogHelper->splitSku($block->escapeHtml($block->getOriginalProductSku()))) ?>
</div>

<?php if ($block->getOrderOptions()): ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function testAddProductToCartWithCustomOptions()
[
'item_id' => $item->getItemId(),
'sku' => $item->getSku(),
'original_product_sku' => $item->getOriginalProductSku(),
'qty' => $item->getQty(),
'name' => $item->getName(),
'price' => $item->getPrice(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public function testGetList()
$expectedResult = [[
'item_id' => $item->getItemId(),
'sku' => $item->getSku(),
'original_product_sku' => $item->getOriginalProductSku(),
'name' => $item->getName(),
'price' => $item->getPrice(),
'qty' => $item->getQty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testGetList()
$data = [
'item_id' => (int)$item->getItemId(),
'sku' => $item->getSku(),
'original_product_sku' => $item->getOriginalProductSku(),
'name' => $item->getName(),
'price' => (float)$item->getPrice(),
'qty' => (float)$item->getQty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testGetList()
$data = [
'item_id' => $item->getItemId(),
'sku' => $item->getSku(),
'original_product_sku' => $item->getOriginalProductSku(),
'name' => $item->getName(),
'price' => $item->getPrice(),
'qty' => $item->getQty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testGet()

//check that nullable fields were marked as optional and were not sent
foreach ($response as $fieldName => $value) {
if ($fieldName == 'sku') {
if ($fieldName === 'sku' || $fieldName === 'original_product_sku') {
continue;
}
$this->assertNotNull($value);
Expand Down