Skip to content

Commit

Permalink
Merge pull request #767 from magento-nord/SPRINT-28-NORD
Browse files Browse the repository at this point in the history
Task
- MAGETWO-63236 Add ability to modify simple products data in custom websites
  • Loading branch information
VladimirZaets authored Jan 24, 2017
2 parents f22ee08 + 40742e5 commit d166004
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
<field name="product_has_weight" group="product-details" />
<field name="attributes" />
<field name="fpt" is_required="0" group="product-details" repository="Magento\Catalog\Test\Repository\Product\Fpt" />
<field name="website_data" is_required="0" repository="Magento\Catalog\Test\Repository\CatalogProductSimple\WebsiteData" />
</fixture>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,38 @@ public function persist(FixtureInterface $fixture = null)
throw new \Exception("Product creation by webapi handler was not successful! Response: {$encodedResponse}");
}

$this->updateProduct($fixture);
return $this->parseResponse($response);
}

/**
* Update product info per website.
*
* @param FixtureInterface $fixture
* @return void
* @throws \Exception
*/
private function updateProduct(FixtureInterface $fixture)
{
if (isset($fixture->getData()['website_data'])) {
$websiteData = $fixture->getData()['website_data'];
foreach ($fixture->getDataFieldConfig('website_ids')['source']->getStores() as $key => $store) {
$url = $_ENV['app_frontend_url'] . 'rest/' . $store->getCode() . '/V1/products/' . $fixture->getSku();
$this->webapiTransport->write($url, ['product' => $websiteData[$key]], CurlInterface::PUT);
$encodedResponse = $this->webapiTransport->read();
$response = json_decode($encodedResponse, true);
$this->webapiTransport->close();

if (!isset($response['id'])) {
$this->eventManager->dispatchEvent(['webapi_failed'], [$response]);
throw new \Exception(
"Product update by webapi handler was not successful! Response: {$encodedResponse}"
);
}
}
}
}

/**
* Prepare data for creating product request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,5 +1856,38 @@
</field>
<field name="url_key" xsi:type="string">simple-product-%isolation%</field>
</dataset>

<dataset name="product_with_additional_website_and_custom_price">
<field name="sku" xsi:type="string">simple_product_with_category_%isolation%</field>
<field name="name" xsi:type="string">Simple product with category %isolation%</field>
<field name="quantity_and_stock_status" xsi:type="array">
<item name="qty" xsi:type="string">777</item>
<item name="is_in_stock" xsi:type="string">In Stock</item>
</field>
<field name="product_has_weight" xsi:type="string">This item has weight</field>
<field name="weight" xsi:type="string">1</field>
<field name="attribute_set_id" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</field>
<field name="price" xsi:type="array">
<item name="value" xsi:type="string">10</item>
<item name="dataset" xsi:type="string" />
</field>
<field name="category_ids" xsi:type="array">
<item name="dataset" xsi:type="string">default_subcategory</item>
</field>
<field name="website_ids" xsi:type="array">
<item name="0" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</item>
<item name="1" xsi:type="array">
<item name="dataset" xsi:type="string">custom_store</item>
</item>
</field>
<field name="url_key" xsi:type="string">simple-product-%isolation%</field>
<field name="website_data" xsi:type="array">
<item name="dataset" xsi:type="string">custom_price_in_main_and_custom_websites</item>
</field>
</dataset>
</repository>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
<repository class="Magento\Catalog\Test\Repository\CatalogProductSimple\WebsiteData">
<dataset name="custom_price_in_main_and_custom_websites">
<field name="0" xsi:type="array">
<item name="price" xsi:type="number">15</item>
</field>
<field name="1" xsi:type="array">
<item name="price" xsi:type="number">20</item>
</field>
</dataset>
</repository>
</config>

0 comments on commit d166004

Please sign in to comment.