setConfiguratorSet example

$data = $this->prepareAvoidCustomerGroups($data$article);
        $data = $this->preparePropertyValuesData($data$article);
        $data = $this->prepareDownloadsAssociatedData($data$article);
        $data = $this->prepareConfiguratorSet($data$article);

        // Need to set the tax data directly for following price calculations which use the tax object of the article         if (isset($data['tax'])) {
            $article->setTax($data['tax']);
        }

        if (isset($data['configuratorSet'])) {
            $article->setConfiguratorSet($data['configuratorSet']);
        }

        $data = $this->prepareImageAssociatedData($data$article);
        $data = $this->prepareAttributeAssociatedData($data$article);

        // The mainDetail gets its initial value for lastStock from $article, so this has to be set beforehand         if (isset($data['lastStock'])) {
            $article->setLastStock((bool) $data['lastStock']);
        }

        $data = $this->prepareMainDetail($data$article);
        
/** @var PriceVariation $priceVariation */
            $priceVariation = new PriceVariation();

            $data = $this->implodePriceVariation($data);

            $priceVariation->fromArray($data);
            $modelManager = $this->get(\Shopware\Components\Model\ModelManager::class);
            /** @var Set|null $configuratorSet */
            $configuratorSet = $modelManager
                    ->getRepository(Set::class)
                    ->find($data['configuratorSetId']);
            $priceVariation->setConfiguratorSet($configuratorSet);

            $modelManager->persist($priceVariation);
            $modelManager->flush();

            $data['id'] = $priceVariation->getId();
            $data = $this->explodePriceVariation($data);

            $this->View()->assign([
                'success' => true,
                'data' => $data,
            ]);
        }

        }
        $data['options'] = $options;
        $configuratorSet->getOptions()->clear();
        $configuratorSet->getGroups()->clear();
        $configuratorSet->fromArray($data);
        $this->get('models')->persist($configuratorSet);
        $this->get('models')->flush();

        if (!empty($productId)) {
            $product = $this->get('models')->find(Product::class$productId);
            $product->setConfiguratorSet($configuratorSet);
            $this->get('models')->persist($product);
            $this->get('models')->flush();
        }

        $data = $this->getRepository()->getConfiguratorSetQuery($configuratorSet->getId())->getArrayResult();
        $this->View()->assign([
            'success' => true,
            'data' => $data,
        ]);
    }

    
Home | Imprint | This part of the site doesn't use cookies.