1

I'm working on a module that will show a wizard on the frontend which ends up showing an advice on what products to buy after a couple questions.

To show an advice there will be a backend where i need to link products just like the cross-sells, upsells and related product tab on the edit product page. Does anyone know a tutorial i could follow to accomplish this?

  • What have you already tried? What have you accomplished? Did you experienced any problems? – user487772 Jun 23 '13 at 14:42
  • I just got the backend working using tabs, so i have my form with basic settings. I just tried to copy the related product tab class as a tab in my own module but I am not sure how magento manages links in the database for the related products. I need to copy the setup to accomplish this. – Michael Jun 23 '13 at 14:52
  • I just found out that Magento uses the catalog_product_link for related products. I need to link from my own table to products. I guess i need to do a total new setup with my own grid. – Michael Jun 23 '13 at 14:55
  • Here's a tutorial i found on creating your own grid inside a tab: excellencemagentoblog.com/… – Michael Jun 23 '13 at 15:05
  • This module creator will generate the code for your entity and link your entity many to many with the products: magentocommerce.com/magento-connect/utilities/developer-tools/… – Marius Jun 23 '13 at 16:22
2

First of all, as said before, you should create your custom product link type with an installer. You could also assign linked attributes.

<?php
$installer = $this;
$installer->startSetup();

//insert link_type_id

$installer->run("INSERT INTO `{$this->getTable('catalog_product_link_type')}` (link_type_id,code) VALUES ('yourLinkTypeID','yourLinkTypeName')");

//insert linked attributes

$data = array(
   array(
       'link_type_id'                  => yourLinkTypeID,
       'product_link_attribute_code'   => 'something',
       'data_type'                     => 'text'
   ),
   array(
       'link_type_id'                  => yourLinkTypeID,
       'product_link_attribute_code'   => 'something',
       'data_type'                     => 'int'
   )
);

$installer->getConnection()->insertMultiple($installer->getTable('catalog/product_link_attribute'), $data);

$installer->endSetup();
?>

You will need to create your grid (you have the tutorial you mentioned at: http://www.excellencemagentoblog.com/magento-grid-serializer-admin-tabs-grid.)

In that grid you will need to load your collection with the linked attributes and save them. For that you will define a product type link model.

    <?php
class MyModule_Model_Product_Type_Link extends Mage_Catalog_Model_Product_Link{


       public function useYourLinkTypeNameLinks()
       {
           $this->setLinkTypeId(yourLinkTypeID);
           return $this;
       }


       public function saveYourLinkTypeNameLinks($product)
       {
           $data = $product->getyourLinkTypeNameLinkData(yourLinkTypeID);
           if (!is_null($data)) {
               $this->_getResource()->saveProductLinks($product, $data,yourLinkTypeID);
           }
           return $this;
       }
    }

You can load your collection + the linked attributes in the grid (or somewhere else) by using

$collection = Mage::getModel('MyModule/product_type_link')->useyourLinkTypeNameLinks()
->getProductCollection()
->setProduct($this->_getProduct())
->addAttributeToSelect('*');

Saving them would require you to get the serialized linkdata and save it trough:

MyModule_Model_Product_Type_Link->saveYourLinkTypeNameLinks($unserializedstuff)

You could also define const LINK_TYPE_YOURLINKTYPENAME = yourLinkTypeID; in the model so you could call it instead of having to add the number everywhere.

I hope it clarifies things a bit like this, i could give you the whole upsell like process but you can read that in the core :).

| improve this answer | |
1

I'm not sure what you are asking.
If you want to have an other many to many relation between products (just like cross-sells, up-sells and related) you can use this extension. It does exactly that. Adds a new relation type called 'accessories'. You just can change the label.
If you want to link your own entity called 'advice' to the products, use this extension to create the code. It will generate the code you need for your entity and has the possibility to link your entity to the products.

| improve this answer | |

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.