1

I'm working on replicating the Bundle Product type as "Package".

I've copied the Bundle folders in Core_Mage, the Theme Layout, Adminhtml (on the frontent design), as well as the xml file in theme layout, core/mage/bunde/etc/config.xml, and adminhtml/default/layout/bundle.xml.

All files and folders have been renamed, with the words Bundle and bundle changed to Package and package respectively. The product type is still not showing as a product type on the backend.

Is there another file that I need to edit to make this happen? I'm trying to be able to reconfigure this "Package" type from the original "Bundle", but I need to keep the Bundle product type.

  • hi, are you intended to use the bundle product as well? or just this new 'Package' : if the later, then you can simply just rename the product label from bundle to 'package' and be done. – ProxiBlue Jan 7 '16 at 1:11
  • Did you create the corresponding file in app/etc/modules to load your new 'package' module? – ProxiBlue Jan 7 '16 at 1:14
1

There is really no need to copy/duplicate all the files from the bundle product, just to create a new product based off it.

What you need to do is define the new product type, in your custom extension config.xml, and then only extend those classes, and the methods, to where you want functionality changes. As an example, if you'd like the price model to do something different for this product type.

So, lets assume you have already created your base extension file structure, and you have a config.xml

Place the following directives in the global tag: (I am using code used in my gifts extension, so just replace the tags with your appropriate naming of the new bundle)

<catalog>
            <product>
                <type>

                    <gift-bundle translate="label" module="giftpromo">
                        <label>Bundle Gift Product</label>
                        <model>giftpromo/product_type_gift_bundle</model>
                        <composite>1</composite>
                        <allowed_selection_types>
                            <simple/>
                            <virtual/>
                        </allowed_selection_types>
                        <price_model>giftpromo/product_type_gift_bundle_price</price_model>
                    </gift-bundle>
                </type>
              <options>
                <gift-bundle>
                    <types>
                        <select translate="label" module="bundle">
                            <label>Drop-down</label>
                        </select>
                        <radio translate="label" module="bundle">
                            <label>Radio Buttons</label>
                        </radio>
                        <checkbox translate="label" module="bundle">
                            <label>Checkbox</label>
                        </checkbox>
                        <multi translate="label" module="bundle">
                            <label>Multiple Select</label>
                        </multi>
                    </types>
                </gift-bundle>
              </options>
            </product>
        </catalog>

In the above example, the two important bits are:

<model>giftpromo/product_type_gift_bundle</model>

This is where you define your product types base model class. You simply need to extend the core bundle class, and define the product type constant:

<?php

/**
 * defines the gift product type constant for bundles
 *
 * @category   ProxiBlue
 * @package    ProxiBlue_GiftPromo
 * @author     Lucas van Staden (support@proxiblue.com.au)
 */
class ProxiBlue_GiftPromo_Model_Product_Type_Gift_Bundle extends Mage_Bundle_Model_Product_Type
{
    const TYPE_CODE = 'gift-bundle';
}

You can also see in the example that I replaced the price model with a custom class, so I can replace the price calculations aspect of the new type. The class still extends the core bundle type

<price_model>giftpromo/product_type_gift_bundle_price</price_model>

as you can see, I simply extend the core bundle class, and rewrite any methods I needed, and then the rest is using core bundle functionality.

<?php

/**
 * Gift product price renderer.
 *
 * @category   ProxiBlue
 * @package    ProxiBlue_GiftPromo
 * @author     Lucas van Staden (support@proxiblue.com.au)
 */
class ProxiBlue_GiftPromo_Model_Product_Type_Gift_Bundle_Price extends Mage_Bundle_Model_Product_Price
{

That should bring up a basic copy of the bundle product Since I did not need indexing and such, I did not include those in my bundle product type definition, but if you look at the core bundle xml product definition, you can easily see the parts you also need to do to extend this. Again, you should simply start off with your own classes, extending the core bundles, and then systematically bring in any methods that require adjustment.

<index_data_retreiver>bundle/catalogIndex_data_bundle</index_data_retreiver>
                        <index_priority>40</index_priority>
                        <price_indexer>bundle/indexer_price</price_indexer>
                        <stock_indexer>bundle/indexer_stock</stock_indexer>

An example for code you may have to adjust, is in the indexer class form the bundles: Mage_Bundle_Model_CatalogIndex_Data_Bundle

There you will find this:

/**
     * Retreive product type code
     *
     * @return string
     */
    public function getTypeCode()
    {
        return Mage_Catalog_Model_Product_Type::TYPE_BUNDLE;
    }

which will obviously not work, as it will get the wrong product type. You need to check for this in all derived class methods, and adjust them accordingly.

In this example you have two choices:

  • rewrite the class Mage_Catalog_Model_Product_Type and add in your product type as well
  • or without adding additional rewrites into the system, simply extend that method in your own class, and change the fetching of the product type form your derived bundle class:

ProxiBlue_GiftPromo_Model_Product_Type_Gift_Bundle::TYPE_CODE

It is not difficult to create new product types. It is just time consuming as there are a lot of little gotchas. Fetching the correct product type code is the biggest of those.

Hope this helps.

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.