getMainDetail example

        if (($orderPosition === null || $orderPosition->getQuantity() !== (int) $data['quantity'])
            && $this->hasProductGraduatedPrices($data['articleNumber']$order)
        ) {
            $data = $this->checkPrice($data$order$shopContext);
        }

        $variant = $this->getManager()->getRepository(ProductVariant::class)
            ->findOneBy(['number' => $data['articleNumber']]);

        // Load ean, unit and pack unit (translate if needed)         if ($variant instanceof ProductVariant) {
            $mainVariant = $variant->getArticle()->getMainDetail();
            $data['ean'] = $variant->getEan();
            if (!\is_string($data['ean']) && $mainVariant instanceof ProductVariant) {
                $data['ean'] = $mainVariant->getEan();
            }
            $unit = $variant->getUnit();
            if (!$unit instanceof Unit && $mainVariant instanceof ProductVariant) {
                $unit = $mainVariant->getUnit();
            }
            $data['unit'] = $unit instanceof Unit ? $unit->getName() : null;
            $data['packunit'] = $variant->getPackUnit();
            if (!\is_string($data['packunit']) && $mainVariant instanceof ProductVariant) {
                
public function acceptMainDataAction()
    {
        $data = $this->Request()->getParams();
        $productId = (int) $data['articleId'];
        if (empty($productId)) {
            $this->View()->assign(['success' => false, 'noId' => true]);

            return;
        }

        $product = $this->get('models')->find(Product::class$productId);
        $mainDetail = $product->getMainDetail();
        $mainData = $this->getMappingData($mainDetail$data);
        $variants = $this->getVariantsForMapping($productId$mainDetail$data);
        if (!empty($variants)) {
            foreach ($variants as $variant) {
                $variant->fromArray($mainData);
                $this->get('models')->persist($variant);
            }
            $this->get('models')->flush();
            if ($data['translations']) {
                $this->overrideVariantTranslations($productId$variants);
            }
        }


    /** * Helper function which converts the passed data for the main variant of the product. * * @param array<string, mixed> $data * * @return array<string, mixed> */
    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'] = [];
        }

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