0

I'm trying to find a way of stopping users in the back end of the site from adding certain product types.

I don't need to remove all the functionality of the product types I just need to remove the virtual and downloadable options from the new product page.

I've tried to find where this is in the back end with a lot of code digging but I'm not very up to date with the admin section of Magento as I am with building things for the front end.

3

I just happened to do the same for my gift-promo module, hide the gift product types, so here is my code, which you can adapt to your need.

I rewrite this via config.xml

....

    <catalog>
        <rewrite>
            <product_type>ProxiBlue_GiftPromo_Model_Product_Type</product_type>
        </rewrite>
    </catalog>  

  ....

any my class has this:

/**
 * Defines the gift type constant
 *
 * @category   ProxiBlue
 * @package    ProxiBlue_GiftPromo
 * @author     Lucas van Staden (support@proxiblue.com.au)
 */
class ProxiBlue_GiftPromo_Model_Product_Type extends Mage_Catalog_Model_Product_Type {

    const TYPE_GIFT = 'gift-';

    /**
     * Remove gift product type from admin display.
     * 
     * @return type
     */
    static public function getTypes() {
        if (is_null(self::$_types)) {
            $productTypes = Mage::getConfig()->getNode('global/catalog/product/type')->asArray();
            // remove gift type from admin displays
            //if(Mage::app()->getStore()->isAdmin() && array_key_exists(ProxiBlue_GiftPromo_Model_Product_Type::TYPE_GIFT, $productTypes)){
                unset($productTypes[ProxiBlue_GiftPromo_Model_Product_Type_Gift_Simple::TYPE_CODE]);    
                unset($productTypes[ProxiBlue_GiftPromo_Model_Product_Type_Gift_Configurable::TYPE_CODE]);
                unset($productTypes[ProxiBlue_GiftPromo_Model_Product_Type_Gift_Downloadable::TYPE_DOWNLOADABLE]);
            //}
            foreach ($productTypes as $productKey => $productConfig) {
                $moduleName = 'catalog';
                if (isset($productConfig['@']['module'])) {
                    $moduleName = $productConfig['@']['module'];
                }
                $translatedLabel = Mage::helper($moduleName)->__($productConfig['label']);
                $productTypes[$productKey]['label'] = $translatedLabel;
            }
            self::$_types = $productTypes;
        }

        return self::$_types;
    }

    /**
     * Here as the getTypes method will not be directly overwritten
     * 
     * @return type
     */
    static public function getOptionArray()
    {
        $options = array();
        foreach(self::getTypes() as $typeId=>$type) {
            $options[$typeId] = Mage::helper('catalog')->__($type['label']);
        }

        return $options;
    }

}
  • Does this solve the issue? For example in the class Mage_Catalog_Model_Resource_Product_Flat_Indexer the getTypes method is still called statically from the original class: Mage_Catalog_Model_Product_Type::getTypes(). I'm asking because I'm just curious. I didn't try it. – Marius Sep 26 '13 at 11:12
  • The code is to only remove the display of The types from Admin, for Example in product create. The Fact That ind3xer still get Them, via its static call is a Good Thing. This is why getoptionarray is extended to use the class own self::gettypes. – ProxiBlue Sep 26 '13 at 12:10
  • I made a new module that overwrites Mage_Catalog_Model_Product_Type and am tinkering in the getTypes function. Problem is I'm not sure what I need to unset to get this to work. – Chris Morris Sep 30 '13 at 11:54
  • Hi, see class Mage_Catalog_Model_Product_Type for the constants to the product types. Downloadables are in their own module, under the class Mage_Downloadable_Model_Product_Type – ProxiBlue Sep 30 '13 at 17:50
0

Note: This example is to show only one option, you can modify it according to your requirement.

According to the question You only need to disable the options from drop down in Create Product Settings in admin.

you can do it this way:

  1. In /app/design/adminhtml/default/default/template/page/footer.phtml at the end of file add the code:

First add php condition to affect the current page only.


 if($this->getRequest()->getActionName() == 'new'){ ?>

Then include latest jquey and add the below script.


 jQuery.noConflict();
 jQuery(document).ready(function($){
   $('.adminhtml-catalog-product-new #product_type option[value=downloadable]').attr('selected','selected');
 });

Close the php condition.

  1. Goto /skin/adminhtml/default/default/custom.css and css:

Add the css:

 #product_type > option {
    display: none;
}
#product_type > option:last-child {
    display: block;
}

It will show only downloadable option in the drop down.

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.