Skip to content

Commit 2c935c8

Browse files
committed
MAGETWO-63236: Add ability to modify simple products data in custom websites
1 parent 424c113 commit 2c935c8

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@
9191
<field name="product_has_weight" group="product-details" />
9292
<field name="attributes" />
9393
<field name="fpt" is_required="0" group="product-details" repository="Magento\Catalog\Test\Repository\Product\Fpt" />
94+
<field name="website_data" is_required="0" repository="Magento\Catalog\Test\Repository\CatalogProductSimple\WebsiteData" />
9495
</fixture>
9596
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Webapi.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,38 @@ public function persist(FixtureInterface $fixture = null)
107107
throw new \Exception("Product creation by webapi handler was not successful! Response: {$encodedResponse}");
108108
}
109109

110+
$this->updateProduct($fixture);
110111
return $this->parseResponse($response);
111112
}
112113

114+
/**
115+
* Update product info per website.
116+
*
117+
* @param FixtureInterface $fixture
118+
* @return void
119+
* @throws \Exception
120+
*/
121+
private function updateProduct(FixtureInterface $fixture)
122+
{
123+
if (isset($fixture->getData()['website_data'])) {
124+
$websiteData = $fixture->getData()['website_data'];
125+
foreach ($fixture->getDataFieldConfig('website_ids')['source']->getStores() as $key => $store) {
126+
$url = $_ENV['app_frontend_url'] . 'rest/' . $store->getCode() . '/V1/products/' . $fixture->getSku();
127+
$this->webapiTransport->write($url, ['product' => $websiteData[$key]], CurlInterface::PUT);
128+
$encodedResponse = $this->webapiTransport->read();
129+
$response = json_decode($encodedResponse, true);
130+
$this->webapiTransport->close();
131+
132+
if (!isset($response['id'])) {
133+
$this->eventManager->dispatchEvent(['webapi_failed'], [$response]);
134+
throw new \Exception(
135+
"Product update by webapi handler was not successful! Response: {$encodedResponse}"
136+
);
137+
}
138+
}
139+
}
140+
}
141+
113142
/**
114143
* Prepare data for creating product request.
115144
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,5 +1856,38 @@
18561856
</field>
18571857
<field name="url_key" xsi:type="string">simple-product-%isolation%</field>
18581858
</dataset>
1859+
1860+
<dataset name="product_with_additional_website_and_custom_price">
1861+
<field name="sku" xsi:type="string">simple_product_with_category_%isolation%</field>
1862+
<field name="name" xsi:type="string">Simple product with category %isolation%</field>
1863+
<field name="quantity_and_stock_status" xsi:type="array">
1864+
<item name="qty" xsi:type="string">777</item>
1865+
<item name="is_in_stock" xsi:type="string">In Stock</item>
1866+
</field>
1867+
<field name="product_has_weight" xsi:type="string">This item has weight</field>
1868+
<field name="weight" xsi:type="string">1</field>
1869+
<field name="attribute_set_id" xsi:type="array">
1870+
<item name="dataset" xsi:type="string">default</item>
1871+
</field>
1872+
<field name="price" xsi:type="array">
1873+
<item name="value" xsi:type="string">10</item>
1874+
<item name="dataset" xsi:type="string" />
1875+
</field>
1876+
<field name="category_ids" xsi:type="array">
1877+
<item name="dataset" xsi:type="string">default_subcategory</item>
1878+
</field>
1879+
<field name="website_ids" xsi:type="array">
1880+
<item name="0" xsi:type="array">
1881+
<item name="dataset" xsi:type="string">default</item>
1882+
</item>
1883+
<item name="1" xsi:type="array">
1884+
<item name="dataset" xsi:type="string">custom_store</item>
1885+
</item>
1886+
</field>
1887+
<field name="url_key" xsi:type="string">simple-product-%isolation%</field>
1888+
<field name="website_data" xsi:type="array">
1889+
<item name="dataset" xsi:type="string">custom_price_in_main_and_custom_websites</item>
1890+
</field>
1891+
</dataset>
18591892
</repository>
18601893
</config>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
9+
<repository class="Magento\Catalog\Test\Repository\CatalogProductSimple\WebsiteData">
10+
<dataset name="custom_price_in_main_and_custom_websites">
11+
<field name="0" xsi:type="array">
12+
<item name="price" xsi:type="number">15</item>
13+
</field>
14+
<field name="1" xsi:type="array">
15+
<item name="price" xsi:type="number">20</item>
16+
</field>
17+
</dataset>
18+
</repository>
19+
</config>

0 commit comments

Comments
 (0)