setMainDetail example


    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;
    }

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

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

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

        if ($productVariant->getKind() === 1) {
            $productVariant->getArticle()->setMainDetail(null);
        }

        $this->getManager()->remove($productVariant);
        $this->flush();

        return $productVariant;
    }

    /** * Convenience method to update a variant by number * * @param string $number * * @return Detail */
$product = $this->getRepository()->find($productId);
        if (!$product instanceof Product) {
            throw new ModelNotFoundException(Product::class$productId);
        }

        // Check if the main detail variant was deleted         if ($product->getMainDetail() === null) {
            $newMainDetail = $this->getArticleDetailRepository()->findOneBy(['articleId' => $productId]);
            if (!$newMainDetail instanceof ProductVariant) {
                throw new ModelNotFoundException(ProductVariant::class$productId, 'articleId');
            }
            $product->setMainDetail($newMainDetail);
        }

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

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

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