i have created a tab on admin product. by following way.
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab" ifconfig="customoptionspricing/general/enable" ifvalue="1">
<name>customoptionspricing_tab</name>
<block>customoptionspricing/adminhtml_catalog_product_tab</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
Tab shows perfectly, i have some custom data to show in its phtml file.
Now i have to show product custom attribute in this tab's contents. i do not know how can i add this by using this phtml file, or any other way.
i tried to add attribute like this:
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_product', 'is_cop_product', array(
'group' => 'Custom Options Pricing',
'label' => 'Is Custom Options Pricing (COP) Product',
'type' => 'int',
'input' => 'boolean',
'visible' => true,
'required' => true,
'position' => 1,
'global' => 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL',
'note' => "is product a cop product"
));
but this way it creates another tab(new Group), with this attribute.
So i need this attribute to be added on tab that i already created.?? thanks
Try setting used_in_forms.
Mage::getSingleton( 'eav/config' )
->getAttribute( 'catalog_product','is_cop_product')
->setData( 'used_in_forms', array( 'customoptionspricing_tab' ) )
->save();
This has worked for us on 1.8 and 1.9 . In our case it was a customer attribute but I don't see why it wouldn't work for products.
Related
I just started to work with Magento. Cool thing. But I think I jumped in the middle of it so fast. However, I've been asked to create a new tab called Promotions when adding a Product. It will then have an option field (named "Is Featured") and it has values of "Yes" or "No" in form of a dropdown.
I am familiar with the structure of Magento, but I can't find where I can do the changes.
I'm using Magento 1.9.2.3 Full release.
I made an image for you guys to understand what I want better.
What should I do?!
You will have to first create the attribute:
open Catalog > Attributes > Manage Attributes
click on Add New Attribute
create a new boolean attribute (chose Yes/No in "Catalog Input Type for Store Owner") and fill the other fields
Then add the attribute to the Promotions group:
open Catalog > Attributes > Manage Attribute Sets
chose the attribute set you are going to use for this product
add a new "Group" to the column on the left with the Add New button (in this case, name it "Promotions")
drag and drop the newly created group to the position you'd like it to be
drag and drop the newly created attribute from the right column to the left one, under the Promotions group
In the installer of any of your suitable extension, add an attribute to the product with a new group, and they will be displayed there.
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'is_featured',
array(
'group' => 'Promotions',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Is Featured',
'input' => 'select',
'class' => '',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'sort_order' => 60
));
$installer->endSetup();
It will look like that:
https://gyazo.com/9a0e423d0c3e78e7c440b5cd79a3e547
Tweak attribute settings according to your requirements.
I am creating a module to insert a new attribute and a new type of product in my store. As template, I use the same registration screen of the Virtual Product type and include new options ONLY this type of product.
For this, in my config.xml, I used:
<catalog>
<product>
<type>
<incomm_virtual translate="label" module="incomm">
<label>Incomm Virtual</label>
<model>incomm/product_type</model>
<price_model>incomm/product_price</price_model>
<is_qty>1</is_qty>
<composite>0</composite>
<can_use_qty_decimals>0</can_use_qty_decimals>
</incomm_virtual>
</type>
</product>
</catalog>
and to configure the installation with the sql in same config.xml:
<resources>
<abc_incommproduct_setup>
<setup>
<module>ABC_Incomm</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
</abc_incommproduct_setup>
</resources>
The next file was used mymodule / model / product / type.php containing:
class ABC_Incomm_Model_Product_Type
extends Mage_Catalog_Model_Product_Type_Virtual
{
const TYPE_INCOMM = 'incomm';
const XML_PATH_AUTHENTICATION = 'catalog/incomm/authentication';
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
{
if ($this->_isStrictProcessMode($processMode)) {
return Mage::helper('ABC_Incomm_Helper_Data')->__(
'Incomm product %s cannot be added to cart. ' .
' On the product detail page click the "Go to parent site"'.
' button to access the product.',
$product->getName()
);
}
return parent::_prepareProduct($buyRequest, $product, $processMode);
}
}
In the same folder, the virtual.php:
class ABC_Incomm_Model_Product_Virtual extends Mage_Catalog_Model_Product_Type_Virtual {
}
Finally, the SQL installation file in sql folder / abc_incommproduct_setup / mysql-install-4-0.1.0.php:
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'terms_of_use', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'sort_order' => 4,
'label' => 'Terms of use',
'backend' => '',
'visible' => true,
'required' => true,
'wysiwyg_enabled' => true,
'visible_on_front' => true,
'apply_to' => 'incomm', //only in this type of product
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
My problem is this, after disabling the cache in magento, clear the cache and include a new type of product, in the Product Types list appears my NEW type of product, but the options NOT load the new attribute inserted via sql, the What's happening? my sqlinstall.php did not run ??
Probably because your new product type is incomm_virtual as specified in config.xml and not incomm. Try to edit 'apply_to' => 'incomm' with 'apply_to' => 'incomm_virtual' and re-run the installer
If you upgrade you script follow the similar pattern as install upgrade script, except the file-name is now data-upgrade-{old-version}-{new-version}.php and they are located under the data folder.
If you don't want to upgrade your script and just change it. don't forget to delete the existing entries for youmodule_setup code from core_resource table. it only loaded at once. if you don't delete that your script wont be loaded.
I want to add a custom field to the actions tab in the Catalog Price Rules section.
This is what I did:
I added these lines to the file app\code\core\Mage\Adminhtml\Block\Promo\Catalog\Edit\Tab\Actions.php
$fieldset->addField('custom_field', 'select', array(
'label' => 'Custom Field',
'title' => 'Custom Field',
'name' => 'custom_field',
'options' => array(
'1' => Mage::helper('catalogrule')->__('Yes'),
'0' => Mage::helper('catalogrule')->__('No'),
),
));
I changed the version to 1.6.0.4 in this file: app\code\core\Mage\CatalogRule\etc\config.xml
<Mage_CatalogRule>
<version>1.6.0.4</version>
</Mage_CatalogRule>
I created new file with the name app\code\core\Mage\CatalogRule\sql\catalogrule_setup\upgrade-1.6.0.3-1.6.0.4.php
$installer->startSetup();
$ruleProductTable = $installer->getTable('catalogrule/rule');
$columnOptions = array(
'TYPE' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
'UNSIGNED' => true,
'NULLABLE' => false,
'DEFAULT' => 0,
'COMMENT' => 'Custom Field',
);
$installer->getConnection()->addColumn($ruleProductTable, 'custom_field', $columnOptions);
$installer->endSetup();
Then, I logged in to the admin panel and tried to edit one of the catalog price rules.
I saw my new field in the actions tab - great!
But when I click "Save", the changes that I made in that field, was not saved.
I logged in to the phpmyadmin and went to catalogrule table.
In this table I can see the new field custom_field, with the value 0 (default) - so It really didn't save the changed.
My question is what I did wrong?
Why the changed in the custom_field didn't saved in the DB?
Thanks
I'm not sure why it isn't working for you my guess is your installer isn't being called. I managed the modification through a module and local edits to future proof the change.
Directory structure:
/app/code/local/custom/promo
/app/code/local/custom/promo/etc/
/app/code/local/custom/promo/sql
/app/code/local/custom/promo/sql/promo_setup
/app/code/core/local/Adminhtml/Block/Promo/Catalog/Edit/Tab
add file /app/code/local/custom/promo/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Promo>
<version>1.0</version>
</Custom_Promo>
</modules>
<global>
<resources>
<promo_setup>
<setup>
<module>Custom_Promo</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
</promo_setup>
</resources>
</global>
</config>
add file /app/code/local/custom/promo/sql/promo_setup/install-1-0.php
/* #var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$ruleProductTable = $installer->getTable('catalogrule/rule');
$columnOptions = array(
'TYPE' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
'NULLABLE' => false,
'COMMENT' => 'Custom Promo',
);
$installer->getConnection()->addColumn($ruleProductTable, 'custom_promo', $columnOptions);
$installer->endSetup();
Clear caches and verify the column is added by looking at the catalog_rule table
SELECT * FROM catalogrule;
Finally take a copy of /app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php and create the same file /app/code/core/local/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php
Edit the file and add the field before $form->setValues($model->getData());
//Custom Promo
$fieldset->addField('custom_promo', 'select', array(
'label' => 'Custom Promo',
'title' => 'Custom Promo',
'name' => 'custom_promo',
'options' => array(
'1' => Mage::helper('catalogrule')->__('Yes'),
'0' => Mage::helper('catalogrule')->__('No'),
),
));
I am using module setup script to add new attributes group, attribute set and attributes. I am able to create attribute set, attribute group and add products to group/set. But I am having hard time setting is_filterable, is_visible, is_visible_on_front and is_html_allowed_on_front parameters.
$installer->addAttribute('catalog_product', 'offer_type', array(
'backend' => '',
'frontend' => '',
'class' => '',
'default' => '',
'label' => 'Offer type',
'input' => 'text',
'type' => 'int',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => 1,
'required' => 1,
'searchable' => 0,
'filterable' => 1,
'unique' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'is_html_allowed_on_front' => 1,
'user_defined' => 1,
));
$installer->addAttributeToSet('catalog_product', $sSetId, $groupName, 'offer_type');
I see offer_type getting added to Magento and to attribute set($sSetID) and to group ($groupname). Though when I look at attribute from magento admin UI (Catalog->attributes->Manage Attributes), I see is_filterable, is_visible, is_visible_on_front and is_html_allowed_on_front parameters set to No. I have tried various combinations but no luck. I'm using Magento CE 1.7.0.2. I am not sure what is missing in my setup script. I have reffered http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/ for this. Am I missing anything?
Thanks in advance.
Do you have properly configured your installer in your config.xml ? The standard class for magento installers is Mage_Eav_Model_Entity_Setup but when dealing with products, you'll need to use Mage_Catalog_Model_Resource_Setup instead.
Why ? look at their method _prepareValues() and you'll understand what are the authorised attributes (products have more options than the standard eav_objects, you can see that when comparing the tables eav_attribute and catalog_eav_attribute)
To point to the good installer class, take a look at the standard Mage_Catalog config.xml and adapt it for your module :
<resources>
<catalog_setup>
<setup>
<module>Mage_Catalog</module>
<class>Mage_Catalog_Model_Resource_Setup</class><!-- that line !-->
</setup>
</catalog_setup>
</resources>
ps: note that the _prepareValues() method is called only when adding an attribute... if you want to update an attribute you'll need to use the full option name ("is_visible" and not just "visible")...
Another hack would be to add these attributes afterward, but it's not very beautiful:
// adding atribute :
// [...]
//getting the new attribute with full informations
$eavConfig = Mage::getSingleton('eav/config');
$installer->cleanCache();
$attribute = $eavConfig->getAttribute('catalog_product', $attributeCode);
$attribute->addData(array(
'is_visible' => 1
));
$attribute->save()
Use 'visible_on_front' => 1, in addAttribute call.
I have following code which creates column for epiration date in my Grid.php. Right now it takes data from DB field which is empty because I would like to have date picker in the column which will save picked date in DB and then show it back to admin. I know that it is possible to do it with $fieldset but I need to use addColumn
$this->addColumn('expiration_date', array(
'header' => Mage::helper('AdvancedStock')->__('Expiration Date'),
'index' => $this['expiration_date'],
'type' => 'datetime',
));
Please help.
I am not sure where you are getting this from: $this['expiration_date']
but that should work, try setting filer and sortable manually.
array(
'index' => 'fieldname',
'filter' => true,
'sortable' => true,
'type' => 'datetime',
)
You will also need to make sure you have included your fieldname in the collection query if it's a none-standard field you have added, by modifying the _prepareCollection() method.
This will be slightly different depending on the collection model you are using
$collection->addFieldToSelect('fieldname');
Instead of type => 'datetime' try type='date' . hope it helps.
You have to add
<reference name="head">
<action method="addItem">
<type>js_css</type>
<name>calendar/calendar-win2k-1.css</name>
<params/><!--<if/><condition>can_load_calendar_js</condition>-->
</action>
<action method="addItem">
<type>js</type>
<name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>-->
</action>
<action method="addItem">
<type>js</type>
<name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>-->
</action>
</reference>
in design/adminhtml/ .../layout, in your xml file corresponding your modified module.