Exemple #1
-1
 public function testNewConfiguratorOptionForVariant()
 {
     $data = $this->getSimpleArticleData();
     $data['mainDetail'] = $this->getSimpleVariantData();
     $configuratorSet = $this->getSimpleConfiguratorSet(1, 2);
     $data['configuratorSet'] = $configuratorSet;
     $article = $this->resourceArticle->create($data);
     // Create 5 new variants
     $batchData = array();
     $names = array();
     for ($i = 0; $i < 5; $i++) {
         $create = $this->getSimpleVariantData();
         $create['articleId'] = $article->getId();
         $options = $this->getVariantOptionsOfSet($configuratorSet);
         unset($options[0]['optionId']);
         $name = 'New-' . uniqid();
         $names[] = $name;
         $options[0]['option'] = $name;
         $create['configuratorOptions'] = $options;
         $batchData[] = $create;
     }
     // Run batch operations
     $result = $this->resource->batch($batchData);
     $this->resource->setResultMode(\Shopware\Components\Api\Resource\Resource::HYDRATE_ARRAY);
     foreach ($result as $operation) {
         $this->assertTrue($operation['success']);
         $variant = $this->resource->getOne($operation['data']['id']);
         $this->assertCount(1, $variant['configuratorOptions']);
         $option = $variant['configuratorOptions'][0];
         $this->assertContains($option['name'], $names);
     }
 }
Exemple #2
-1
 public function updateConfiguratorVariants($articleId, $data)
 {
     foreach ($data as $updateInformation) {
         $options = $updateInformation['options'];
         $variantData = $updateInformation['data'];
         $variants = $this->getVariantsByOptions($articleId, $options);
         if (empty($variants)) {
             continue;
         }
         foreach ($variants as $variantId) {
             $this->variantApi->update($variantId, $variantData);
         }
     }
 }