i have a Weight
attribute :
Attribute Code: weight
Scope: general
Catalog Input Type for Store Owner: Text Field
Values Required: yes
Apply To: Simple Product, Bundle Product
Allow HTML Tags on Frontend: yes
and i have a General Weight
attribute :
Attribute Code: general_weight
Scope: general
Catalog Input Type for Store Owner: Text Field
Values Required: no
Apply To: All Product Types
Use in Advanced Search: yes
Comparable on Front-end: yse
Allow HTML Tags on Frontend: yes
Visible on Product View Page on Front-end: yes
i want to assign Weight
attribute to General Weight
without four decimals. i mean i want the value of Weight
attribute( for example 2000.0000 to copy into General Weight
value on product save (but without for last decimals like 2000).
i made an small extension for that in this way:
i created Moh3n_Attvaluecopier.xml
file in app/etc/modules
with this content:
<?xml version="1.0"?>
<config>
<modules>
<Moh3n_Attvaluecopier>
<active>true</active>
<codePool>local</codePool>
</Moh3n_Attvaluecopier>
</modules>
</config>
and config.xml
file in app/code/local/Moh3n/Attvaluecopier/etc
with this content:
<?xml version="1.0"?>
<config>
<modules>
<Moh3n_Attvaluecopier>
<version>0.0.1</version>
</Moh3n_Attvaluecopier>
</modules>
<global>
<models>
<moh3nattvaluecopier>
<class>Attvaluecopier_Model</class>
</moh3nattvaluecopier>
</models>
<events>
<catalog_product_save_after>
<observers>
<moh3n_attvaluecopier_model_observer>
<type>singleton</type>
<class>Moh3n_Attvaluecopier_Model_Observer</class>
<method>copyAttribute</method>
</moh3n_attvaluecopier_model_observer>
</observers>
</catalog_product_save_after>
</events>
</global>
</config>
and Observer.php
file in app/code/local/Moh3n/Attvaluecopier/model
with this content:
<?php
class Moh3n_Attvaluecopier_Model_Observer
{
public function copyAttribute($observer){
if(!$this->_processFlag):
$this->_processFlag=true;
$_product = $observer->getProduct();
$_productid = $_product->getId();
$productModel = Mage::getModel('catalog/product');
$loadCurrentProduct = $productModel->load($_productid);
$loadCurrentProduct->setGeneralWeight(intval($loadCurrentProduct->getWeight()));
$loadCurrentProduct->save();
endif;}
}