setArticle example



            // Use only the main detail of the product as base object, if the merge type is set to "Override" and the current variant is the first generated variant.             if ($existentDetailModel) {
                $detail = $product->getMainDetail();
            } else {
                $detail = new ProductVariant();
                $this->get('models')->persist($detail);
            }

            $detail->fromArray($data);
            $detail->setArticle($product);
            $this->get('models')->flush();

            $this->copyConfigurationTemplateTranslations($detailData$detail);
            ++$offset;
        }

        $this->get('models')->clear();

        $product = $this->getRepository()->find($productId);
        if (!$product instanceof Product) {
            throw new ModelNotFoundException(Product::class$productId);
        }

        if (empty($id)) {
            throw new ParameterMissingException('id');
        }

        $variant = $this->getRepository()->find($id);

        if (!$variant instanceof Detail) {
            throw new NotFoundException(sprintf('Variant by id %d not found', $id));
        }

        $variant->setArticle($article);

        $data = $this->prepareData($data$article$variant);

        $variant->fromArray($data);

        return $variant;
    }

    /** * Create function for the internal usage of the rest api. * Used from the 'Article' resource. This function supports * to pass an updated product entity which isn't updated in the database. * Required for the 'Article' resource if the product data is already updated * in the entity but not in the database. * * @throws ValidationException * * @return Detail */

    public function prepareMainDetail(array $data, ProductModel $article)
    {
        $detail = $article->getMainDetail();
        if (!$detail) {
            $detail = new Detail();
            $detail->setKind(1);
            $detail->setArticle($article);
            $article->setMainDetail($detail);
        }

        if (empty($data['mainDetail'])) {
            $data['mainDetail'] = [];
        }

        $data['mainDetail'] = $this->getVariantResource()->prepareMainVariantData($data['mainDetail']$article$detail);

        return $data;
    }

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