2

I followed some tutorials and wrote this code.

This is install.0.1.0.php:

$installer = $this;
$installer->startSetup();

$allowCP = array(
                    'group' => 'Prices', 
                    'type' => 'text',
                    'attribute_set' =>  'Default',
                    'backend' => '',
                    'frontend' => '',
                    'label' => 'Allow Custom Price',
                    'input' => 'select',
                    'option' => array(
                                    'value' => array( 
                                    1 => 'Yes',
                                    0 => 'No',
                                )),
                    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'default' => '1',
                    'searchable' => false,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'visible_in_advanced_search' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',  // Apply to All product type
                    'class' => ''  
                );

$installer->addAttribute('catalog_product', 'allowcustomprice', $allowCP);

$minCP = array(
                    'group' => 'Prices', 
                    'type' => 'int',
                    'attribute_set' =>  'Default',
                    'backend' => '',
                    'frontend' => '',
                    'label' => 'Min Custom Price',
                    'input' => 'text',
                    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => false,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'visible_in_advanced_search' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',  // Apply to All product type
                    'class' => ''       
            );
$installer->addAttribute('catalog_product', 'mincustomprice', $minCP);
$installer->endSetup();

This is config.xml:

<modules>
    <WebDirect_CustomPrice>
        <version>0.1.0</version>
    </WebDirect_CustomPrice>
</modules>
<!-- ******************************** -->

<global>
    <helpers>
        <customprice>
            <class>WebDirect_CustomPrice_Helper</class>
        </customprice>
    </helpers>
    <models>
        <customprice>
            <class>WebDirect_CustomPrice_Model</class>
        </customprice>
    </models>
    
    <resources>
        <customprice_setup>
          <setup>
            <module>WebDirect_CustomPrice</module>
            <class>WebDirect_CustomPrice_Model_Resource_Setup</class>
          </setup>

          <connection>
            <use>core_setup</use>
          </connection>
        </customprice_setup>

        <customprice_write>
          <connection>
            <use>core_write</use>
          </connection>
        </customprice_write>
        <customprice_read>
          <connection>
            <use>core_read</use>
          </connection>
        </customprice_read>
  </resources>

</global>

And this is the class Mymodule/Model/Resource/Setup.php:

class WebDirect_CustomPrice_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {
}

When I compile this code, there is nothing displayed, so I can't see if there is any error.

1 Answer 1

7
try 

<?php

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();


$installer->addAttributeGroup('catalog_product', 'Default', 'Prices', 1000);
$installer->addAttribute('catalog_product', 'custom_price', array(
        'group'             => 'Prices',
        'label'                => 'Apply Custom price',
        'type'                => 'int',
        'input'                => 'boolean',
        'source'               => 'eav/entity_attribute_source_boolean',
        'global'               => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'              => 1,
        'required'             => 1,
        'user_defined'         => 1,
        'searchable'           => 0,
        'filterable'           => 0,
        'comparable'           => 0,
        'visible_on_front'     => 0,
        'visible_in_advanced_search'    => 0,
        'unique'            => 0,
        'default'            => 0
));

$setup->updateAttribute('catalog_product', 'custom_price', 'is_used_for_promo_rules',1);
$setup->updateAttribute('catalog_product', 'custom_price', 'is_used_for_price_rules',1);
$installer->endSetup(); 

i think you forgot to define Attribute Group for your attribute.

hope this help

Sign up to request clarification or add additional context in comments.

8 Comments

and what about config.xml and Setup.php is there any errors
i m searching for the solution for hours i don't wanna lose more :(
i did all that and fluch cache,reindex indexes but no result
have you check in admin for attribute is created or not?
install.0.1.0.php only execute once. if you updated your code with my code then please create upgrade script and change the updated version in your etc/config.xml
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.