0

I Am Creating Custom catalog_product_link_type,

I've added Additional Section in Related Products Section And It is Working.

But How to Save Values Of This additional section Into Database. enter image description here

I have Created My Custom type by adding it into catalog_product_link_type table.

Does AnyOne Know which controller, js, event is used for saving this data.??

  • 1
    There is a sample module here: github.com/mrkhoa99/Boolfly_ProductRelation – Khoa TruongDinh Nov 7 '17 at 14:22
  • @ Khoa TruongDinh Custome Type is Not Saving In this Module... – Rizwan Khan Nov 8 '17 at 5:10
  • What is your Magento version? – Khoa TruongDinh Nov 8 '17 at 5:53
  • @KhoaTruongDinh my magento version is 2.1.5 – Rizwan Khan Nov 8 '17 at 6:47
  • I will check later. I think many users can use that module, so it will work for you as well. But, I don't know why it doesn't work for your Magento version. Can you check with the 2.1.9 version? – Khoa TruongDinh Nov 8 '17 at 7:13
1

After Some R&D i Come To This Solution.

Creating Preference For Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper

<preference for="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper" type="Your\Module\Controller\Adminhtml\Product\Initialization\Helper"/>

OverRide setProductLinks() Of That Class Like This,

    protected function setProductLinks(\Magento\Catalog\Model\Product $product)
    {
        $links = $this->getLinkResolver()->getLinks();

        $product->setProductLinks([]);

        $product = $this->productLinks->initializeLinks($product, $links);
        $productLinks = $product->getProductLinks();
        $linkTypes = [
            'related' => $product->getRelatedReadonly(),
            'upsell' => $product->getUpsellReadonly(),
            'crosssell' => $product->getCrosssellReadonly(),
            'yourtype' => $product->getYourTypeReadonly()
        ];

        foreach ($linkTypes as $linkType => $readonly) {
            if (isset($links[$linkType]) && !$readonly) {
                foreach ((array) $links[$linkType] as $linkData) {
                    if (empty($linkData['id'])) {
                        continue;
                    }

                    $linkProduct = $this->getProductRepository()->getById($linkData['id']);
                    $link = $this->getProductLinkFactory()->create();
                    $link->setSku($product->getSku())
                        ->setLinkedProductSku($linkProduct->getSku())
                        ->setLinkType($linkType)
                        ->setPosition(isset($linkData['position']) ? (int)$linkData['position'] : 0);
                    $productLinks[] = $link;
                }
            }
        }

        return $product->setProductLinks($productLinks);
    }

After That Data Will Be saved In catalog_product_link And Other Related Tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.