31 $this->productFactory = $this->objectManager->get(\
Magento\Catalog\Model\ProductFactory::class);
38 public function testRemove()
43 \
Magento\Catalog\Model\ProductRepository::class
51 'resourcePath' =>
"/V1/products/$sku/options/$optionId",
56 'serviceVersion' =>
'V1',
57 'operation' => self::SERVICE_NAME .
'DeleteByIdentifier',
64 $this->assertEquals(9, count(
$product->getOptions()));
71 public function testGet()
73 $productSku =
'simple';
76 ->get(\
Magento\Catalog\Api\ProductCustomOptionRepositoryInterface::class);
82 'resourcePath' =>
'/V1/products/' . $productSku .
"/options/" .
$optionId,
87 'serviceVersion' =>
'V1',
88 'operation' => self::SERVICE_NAME .
'Get',
94 $excepted = include
'_files/product_options.php';
95 $this->assertEquals($excepted[0],
$option);
106 $productSku =
'simple';
109 'resourcePath' =>
'/V1/products/' . $productSku .
"/options",
114 'serviceVersion' =>
'V1',
115 'operation' => self::SERVICE_NAME .
'GetList',
122 unset(
$options[$key][
'product_sku']);
124 if (!empty(
$options[$key][
'values'])) {
125 foreach (
$options[$key][
'values'] as $newKey => $valueData) {
126 unset(
$options[$key][
'values'][$newKey][
'option_type_id']);
131 $excepted = include
'_files/product_options.php';
132 $this->assertEquals(count($excepted), count(
$options));
148 $productSku =
'simple';
151 $optionDataPost[
'product_sku'] = $productSku;
154 'resourcePath' =>
'/V1/products/options',
159 'serviceVersion' =>
'V1',
160 'operation' => self::SERVICE_NAME .
'Save',
167 if (!empty(
$result[
'values'])) {
168 foreach (array_keys(
$result[
'values']) as $key) {
169 unset(
$result[
'values'][$key][
'option_type_id']);
177 $fixtureOptions = [];
178 $fixture = include
'_files/product_options.php';
179 foreach ($fixture as
$item) {
180 $fixtureOptions[
$item[
'type']] = [
181 'optionData' =>
$item,
185 return $fixtureOptions;
195 $productSku =
'simple';
197 $optionDataPost[
'product_sku'] = $productSku;
200 'resourcePath' =>
"/V1/products/options",
205 'serviceVersion' =>
'V1',
206 'operation' => self::SERVICE_NAME .
'Save',
210 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
211 if ($optionDataPost[
'title'] ===
null || $optionDataPost[
'title'] ===
'') {
212 $this->expectException(
'SoapFault');
213 $this->expectExceptionMessage(
'Missed values for option required fields');
215 $this->expectException(
'SoapFault');
216 $this->expectExceptionMessage(
'Invalid option');
219 $this->expectException(
'Exception');
220 $this->expectExceptionCode(400);
222 $this->
_webApiCall($serviceInfo, [
'option' => $optionDataPost]);
227 $fixtureOptions = [];
228 $fixture = include
'_files/product_options_negative.php';
229 foreach ($fixture as $key =>
$item) {
230 $fixtureOptions[$key] = [
231 'optionData' =>
$item,
235 return $fixtureOptions;
242 public function testUpdate()
244 $productSku =
'simple';
247 \
Magento\Catalog\Model\ProductRepository::class
254 'product_sku' => $productSku,
255 'title' =>
$option->getTitle() .
"_updated",
257 'sort_order' => (int)
$option->getSortOrder(),
258 'is_require' => (bool)
$option->getIsRequire(),
259 'price' =>
$option->getPrice(),
260 'price_type' =>
$option->getPriceType(),
262 'max_characters' => 500,
267 'resourcePath' =>
'/V1/products/options/' .
$optionId,
272 'serviceVersion' =>
'V1',
273 'operation' => self::SERVICE_NAME .
'Save',
276 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
277 $optionDataPost[
'option_id'] =
$optionId;
280 [
'id' =>
$optionId,
'option' => $optionDataPost]
282 unset($optionDataPost[
'option_id']);
284 $updatedOption = $this->
_webApiCall($serviceInfo, [
'option' => $optionDataPost]);
287 unset($updatedOption[
'values']);
288 unset($updatedOption[
'option_id']);
289 $this->assertEquals($optionDataPost, $updatedOption);
300 public function testUpdateOptionAddingNewValue($optionType)
302 $fixtureOption =
null;
305 'price_type' =>
'fixed',
306 'sku' =>
'new option sku ' . $optionType,
307 'title' =>
'New Option Title',
313 \
Magento\Catalog\Model\ProductRepository::class
320 if (
$option->getType() == $optionType) {
330 'price' =>
$value->getPrice(),
331 'price_type' =>
$value->getPriceType(),
332 'sku' =>
$value->getSku(),
333 'title' =>
$value->getTitle(),
334 'sort_order' =>
$value->getSortOrder(),
339 'product_sku' =>
$option->getProductSku(),
340 'title' =>
$option->getTitle(),
342 'is_require' =>
$option->getIsRequire(),
343 'sort_order' =>
$option->getSortOrder(),
349 'resourcePath' =>
'/V1/products/options/' . $fixtureOption->getId(),
354 'serviceVersion' =>
'V1',
355 'operation' => self::SERVICE_NAME .
'Save',
358 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
359 $data[
'option_id'] = $fixtureOption->getId();
362 [
'option_id' => $fixtureOption->getId(),
'option' =>
$data]
368 $values = end($valueObject[
'values']);
369 $this->assertEquals($valueData[
'price'],
$values[
'price']);
370 $this->assertEquals($valueData[
'price_type'],
$values[
'price_type']);
371 $this->assertEquals($valueData[
'sku'],
$values[
'sku']);
372 $this->assertEquals(
'New Option Title',
$values[
'title']);
373 $this->assertEquals(100,
$values[
'sort_order']);
379 'drop_down' => [
'drop_down'],
380 'checkbox' => [
'checkbox'],
381 'radio' => [
'radio'],
382 'multiple' => [
'multiple']
397 $productSku =
'simple';
406 'resourcePath' =>
'/V1/products/options/' .
$optionId,
411 $this->expectException(
'Exception');
412 $this->expectExceptionMessage(
$message);
413 $this->expectExceptionCode($exceptionCode);
422 return include
'_files/product_options_update_negative.php';
testAddNegative($optionData)
optionNegativeDataProvider()
_markTestAsRestOnly($message=null)
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
optionNegativeUpdateDataProvider()
validOptionDataProvider()
static getObjectManager()