Esempio n. 1
0
 /**
  * Webapi request for creating simple product.
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $this->fixture = $fixture;
     $this->fields = $this->handlerCurl->prepareData($this->fixture);
     $this->prepareData();
     $this->convertData();
     /** @var CatalogProductSimple $fixture */
     $url = $_ENV['app_frontend_url'] . 'rest/default/V1/products';
     $this->webapiTransport->write($url, $this->fields, CurlInterface::POST);
     $response = json_decode($this->webapiTransport->read(), true);
     $this->webapiTransport->close();
     if (!isset($response['id'])) {
         $this->eventManager->dispatchEvent(['curl_failed'], [$response]);
         throw new \Exception('Product creation by webapi handler was not successful!');
     }
     return $this->parseResponse($response);
 }
Esempio n. 2
0
 /**
  * Preparation of stock data.
  *
  * @param array $fields
  * @return array
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function prepareStockData(array $fields)
 {
     $fields = parent::prepareStockData($fields);
     if (isset($fields['quantity_and_stock_status']['is_in_stock']) && $fields['quantity_and_stock_status']['is_in_stock']) {
         $fields['quantity_and_stock_status']['use_config_manage_stock'] = 1;
     }
     return $fields;
 }
Esempio n. 3
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $data = parent::prepareData($fixture, null);
     $downloadable = $data['downloadable'];
     unset($data['downloadable']);
     $data = $prefix ? [$prefix => $data] : $data;
     $data['downloadable'] = $downloadable;
     return $this->replaceMappingData($data);
 }
Esempio n. 4
0
 /**
  * Prepare POST data for creating product request.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 public function prepareData(FixtureInterface $fixture)
 {
     $data = parent::prepareData($fixture);
     $assignedProducts = [];
     if (!empty($data['product']['associated'])) {
         $assignedProducts = $data['product']['associated']['assigned_products'];
         unset($data['product']['associated']);
     }
     foreach ($assignedProducts as $item) {
         $data['links']['associated'][$item['id']] = $item;
     }
     return $data;
 }
Esempio n. 5
0
 /**
  * Prepare POST data for creating product request.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 public function prepareData(FixtureInterface $fixture)
 {
     $data = parent::prepareData($fixture);
     /** @var ConfigurableAttributesData $configurableAttributesData */
     $configurableAttributesData = $fixture->getDataFieldConfig('configurable_attributes_data')['source'];
     $attributeSetId = $data['product']['attribute_set_id'];
     $data['product']['configurable_attributes_data'] = $this->prepareAttributesData($configurableAttributesData);
     $data['configurable-matrix'] = $this->prepareConfigurableMatrix($fixture);
     $data['attributes'] = $this->prepareAttributes($configurableAttributesData);
     $data['new-variations-attribute-set-id'] = $attributeSetId;
     $data['associated_product_ids'] = $this->prepareAssociatedProductIds($configurableAttributesData);
     return $this->replaceMappingData($data);
 }
Esempio n. 6
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $product
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $product, $prefix = null)
 {
     $data = parent::prepareData($product, null);
     /** @var ConfigurableAttributesData $configurableAttributesData */
     $configurableAttributesData = $product->getDataFieldConfig('configurable_attributes_data')['source'];
     $attributeSetId = $data['attribute_set_id'];
     $data['configurable_attributes_data'] = $this->prepareAttributesData($configurableAttributesData);
     $data = $prefix ? [$prefix => $data] : $data;
     $data['variations-matrix'] = $this->prepareVariationsMatrix($product);
     $data['attributes'] = $this->prepareAttributes($configurableAttributesData);
     $data['new-variations-attribute-set-id'] = $attributeSetId;
     $data['associated_product_ids'] = [];
     return $this->replaceMappingData($data);
 }
Esempio n. 7
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $data = parent::prepareData($fixture, null);
     $assignedProducts = [];
     if (!empty($data['associated'])) {
         $assignedProducts = $data['associated']['assigned_products'];
         unset($data['associated']);
     }
     $data = $prefix ? [$prefix => $data] : $data;
     foreach ($assignedProducts as $item) {
         $data['links']['associated'][$item['id']] = $item;
     }
     return $data;
 }
Esempio n. 8
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $data = parent::prepareData($fixture, null);
     $attributeSetId = $data['attribute_set_id'];
     $matrix = $data['configurable_attributes_data']['matrix'];
     $attributesData = $data['configurable_attributes_data']['attributes_data'];
     unset($data['configurable_attributes_data'], $data['attribute_set_id']);
     // Preparing attribute data
     $attributesIds = [];
     $data['configurable_attributes_data'] = $this->preparingAttributeData($attributesData, $attributesIds);
     $matrix = $this->preparingMatrixData($matrix, ['%product_name%' => $data['name'], '%product_sku%' => $data['sku']]);
     // Add prefix data
     $data = $prefix ? [$prefix => $data] : $data;
     $data['attributes'] = $attributesIds;
     $data = array_merge($data, $this->prepareVariationsMatrix($matrix));
     $data['new-variations-attribute-set-id'] = $attributeSetId;
     return $this->replaceMappingData($data);
 }
Esempio n. 9
0
 /**
  * Prepare POST data for creating product request.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 public function prepareData(FixtureInterface $fixture)
 {
     /** @var DownloadableProduct $fixture */
     $fixtureData = parent::prepareData($fixture);
     $downloadableData = ['downloadable_sample' => $fixture->getDownloadableSample(), 'downloadable_links' => $fixture->getDownloadableLinks()];
     $data = [];
     if (!empty($downloadableData['downloadable_sample'])) {
         foreach ($downloadableData['downloadable_sample']['downloadable']['sample'] as $key => $sample) {
             $data['downloadable']['sample'][$key]['title'] = $sample['title'];
             // only url type
             $data['downloadable']['sample'][$key]['type'] = 'url';
             $data['downloadable']['sample'][$key]['sample_url'] = $sample['sample_url'];
             $data['downloadable']['sample'][$key]['sort_order'] = $sample['sort_order'];
         }
         $sampleTitle = $downloadableData['downloadable_sample']['title'];
         $data['samples_title'] = ['product' => $sampleTitle];
         unset($data['downloadable_sample']);
     }
     if (!empty($downloadableData['downloadable_links'])) {
         foreach ($downloadableData['downloadable_links']['downloadable']['link'] as $key => $link) {
             $data['downloadable']['link'][$key]['title'] = $link['title'];
             // only url type
             $data['downloadable']['link'][$key]['type'] = 'url';
             $data['downloadable']['link'][$key]['link_url'] = $link['file_link_url'];
             $data['downloadable']['link'][$key]['price'] = $link['price'];
             $data['downloadable']['link'][$key]['number_of_downloads'] = $link['number_of_downloads'];
             $data['downloadable']['link'][$key]['is_shareable'] = $link['is_shareable'];
             $data['downloadable']['link'][$key]['sort_order'] = $link['sort_order'];
             $data['downloadable']['link'][$key]['sample']['type'] = 'url';
             $data['downloadable']['link'][$key]['sample']['url'] = $link['sample']['sample_url'];
         }
         $links = ['links_title' => $downloadableData['downloadable_links']['title'], 'links_purchased_separately' => $downloadableData['downloadable_links']['links_purchased_separately']];
         $data = array_merge($data, ['product' => $links]);
         unset($downloadableData['downloadable_links']);
     }
     $data = array_merge_recursive($fixtureData, $data);
     return $this->replaceMappingData($data);
 }
Esempio n. 10
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $data = parent::prepareData($fixture, null);
     $downloadableData = [];
     if (!empty($data['downloadable_links'])) {
         $data['links_title'] = $data['downloadable_links']['title'];
         $data['links_purchased_separately'] = $data['downloadable_links']['links_purchased_separately'];
         foreach ($data['downloadable_links']['downloadable']['link'] as $key => $link) {
             $downloadableData['downloadable']['link'][$key]['title'] = $link['title'];
             // only url type
             $downloadableData['downloadable']['link'][$key]['type'] = 'url';
             $downloadableData['downloadable']['link'][$key]['link_url'] = $link['file_link_url'];
             $downloadableData['downloadable']['link'][$key]['price'] = $link['price'];
             $downloadableData['downloadable']['link'][$key]['number_of_downloads'] = $link['number_of_downloads'];
             $downloadableData['downloadable']['link'][$key]['is_shareable'] = $link['is_shareable'];
             $downloadableData['downloadable']['link'][$key]['sort_order'] = $link['sort_order'];
             $downloadableData['downloadable']['link'][$key]['sample']['type'] = 'url';
             $downloadableData['downloadable']['link'][$key]['sample']['url'] = $link['sample']['sample_url'];
         }
         unset($data['downloadable_links']);
     }
     if (!empty($data['downloadable_sample'])) {
         $data['samples_title'] = $data['downloadable_sample']['title'];
         foreach ($data['downloadable_sample']['downloadable']['sample'] as $key => $sample) {
             $downloadableData['downloadable']['sample'][$key]['title'] = $sample['title'];
             // only url type
             $downloadableData['downloadable']['sample'][$key]['type'] = 'url';
             $downloadableData['downloadable']['sample'][$key]['sample_url'] = $sample['sample_url'];
             $downloadableData['downloadable']['sample'][$key]['sort_order'] = $sample['sort_order'];
         }
         unset($data['downloadable_sample']);
     }
     $data = $prefix ? [$prefix => $data] : $data;
     $data = array_merge($data, $downloadableData);
     return $this->replaceMappingData($data);
 }
Esempio n. 11
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $data = parent::prepareData($fixture, null);
     $selections = [];
     $bundleSelections = [];
     if (!empty($data['bundle_selections'])) {
         $selections = $data['bundle_selections'];
         $products = $selections['products'];
         unset($data['selections'], $selections['products']);
         foreach ($selections['bundle_options'] as $key => &$option) {
             $option['delete'] = '';
             $option['position'] = $key;
             foreach ($option['assigned_products'] as $productKey => $assignedProduct) {
                 $assignedProduct['data'] += ['product_id' => $products[$key][$productKey]->getId(), 'delete' => '', 'position' => $productKey];
                 $bundleSelections[$key][] = $assignedProduct['data'];
             }
             unset($option['assigned_products']);
         }
     }
     $data = $prefix ? [$prefix => $data] : $data;
     $data = array_merge($data, $selections);
     $data['bundle_selections'] = $bundleSelections;
     return $this->replaceMappingData($data);
 }
Esempio n. 12
0
 /**
  * Parse response.
  *
  * @param string $response
  * @return array
  */
 protected function parseResponse($response)
 {
     return array_replace_recursive(parent::parseResponse($response), $this->parseResponseSelections($response));
 }