I was created admin module for manage supplier information, next I want to add supplier list drop down to product details ( catalog > manage product > Inventory >) How to do it ?
-
Read this maybe it helps: marius-strajeru.blogspot.ro/2012/11/…– Marius ♦Sep 2, 2014 at 11:20
3 Answers
Step1: Copy
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php
to
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php
Create a function here which give list of all supplier list and
Step2:goto app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml create drop down using step1 define function
Edit: add this code:
<?php
$this->getSupplierList()
?>
<select id="supplierlist" name="supplierlist" class="select" <?php echo $_readonly;?>>
<?php foreach($this->getSupplierList() as $key=>$eachSuppier) { ?>
<?php ?>
<option value="<?php echo $key;?>" <?php if($key==$this->getProduct()->getdData('yourattribute_code') ):?> selected="selected"<?php endif; ?>> label </option>
</select>
Step3:Create a event on catalog_product_prepare_save save it to you attibute
add below code at config.xml
<adminhtml>
<events>
<catalog_product_prepare_save>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_prepare_save>
</events>
</adminhtml>
and Observe code is
public function saveProductTabData(Varien_Event_Observer $observer)
{
$product = $observer->getEvent()->getProduct();
try {
$customFieldValue = $observer->getEvent()->getRequest();
$product->setData('yourattribute_code',$customFieldValue['supplierlist']))
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
Edit:
Full code in module Structure:
Step1:
create config.xml
at app/code/local/Stackexchange/Magento34338/etc/
code is
<?xml version="1.0" ?>
<config>
<modules>
<Stackexchange_Magento34338>
<version>1.0.0</version>
</Stackexchange_Magento34338>
</modules>
<global>
<blocks>
<magento34338>
<class>Stackexchange_Magento34338_Block</class>
</magento34338>
<adminhtml>
<rewrite>
<catalog_product_edit_tab_inventory>Stackexchange_Magento34338_Block_Adminhtml_Catalog_Product_Edit_Tab_Inventory</catalog_product_edit_tab_inventory>
</rewrite>
</adminhtml>
</blocks>
<models>
<magento34338>
<class>Stackexchange_Magento34338_Model</class>
</magento34338>
</models>
</global>
<adminhtml>
<events>
<catalog_product_prepare_save>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>magento34338/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_prepare_save>
</events>
</adminhtml>
</config>
**Step2:**Rewrite inventory block tab an this block class Tab.php at app/code/local/Stackexchange/Magento34338/Block/Adminhtml/Catalog/Product/Edit/
and code is
<?php
class Stackexchange_Magento34338_Block_Adminhtml_Catalog_Product_Edit_Tab_Inventory extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Inventory
{
public function getSupplierList(){
$collection = Mage::getModel('supplier/supplier');
$Id_list = $collection->getCollection()->getAllIds();
$data_Array = array();
foreach ($Id_list as $ids){
$data_Array[$ids] = $collection->load($ids)->getData();
}
return $data_Array;
}
public function __construct()
{
parent:: __construct();
}
}
Step3:Observer code at Observer.php
at app/code/local/Stackexchange/Magento34338/Model code
is
<?php
class Stackexchange_Magento34338_Model_Observer{
public function saveProductTabData($observer)
{
$product = $observer->getEvent()->getProduct();
try {
$customFieldValue = $observer->getEvent()->getRequest()->getPost();
$product->setData('youattibutecode',$customFieldValue['supplierlist']);
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
}
Step4: at last add below code
at
app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml
code is
<?php
$this->getSupplierList();
?>
<td class="label"><label for="inventory_manage_stock"><?php echo Mage::helper('catalog')->__('Manage Supplier') ?></label></td>
<td class="value">
<select id="supplierlist" name="supplierlist" class="select" <?php echo $_readonly;?>>
<?php foreach($this->getSupplierList() as $key=>$eachSuppier) { ?>
<?php ?>
<option value="<?php echo $key;?>" <?php if($key==$this->getProduct()->getData('you_product_attribute') ):?> selected="selected"<?php endif; ?>> <?php echo $eachSuppier['youefilename'];?> </option>
<?php } ?>
</select>
</td>
</tr>
step5:Stackexchange_Magento34338.xml at app/etc/module/
code is
<?xml version="1.0" ?>
<config>
<modules>
<Stackexchange_Magento34338>
<codePool>local</codePool>
<active>true</active>
</Stackexchange_Magento34338>
</modules>
</config>
Note:create an attribute of text type by using inventory tab's supplierlist field update this attrbiue
-
Hi Amit, step 1 and 2 done, but step 3 is not complete can u give any help Sep 2, 2014 at 12:13
-
Step 1 :- public function getSupplierList(){ $collection = Mage::getModel('supplier/supplier'); $Id_list = $collection->getCollection()->getAllIds(); $data_Array = array(); foreach ($Id_list as $ids){ $data_Array[$ids] = $collection->load($ids)->getData(); } return $data_Array; } Sep 2, 2014 at 12:13
-
in which table you want to save data.your table or product table?– Amit Bera ♦Sep 2, 2014 at 12:17
-
-
Step 1: Go to : app\design\adminhtml\default\default\template\catalog\product\tab\inventory.phtml
Create a dropdown for Supplier list
Create a function here which give list of all supplier list
Step 2:Create a event on catalog_product_save_before save it on you table
module/etc/config.xml
<adminhtml>
<events>
<catalog_product_save_after>
<observers>
<namespace_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</namespace_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
module/Model/Model/Observer.php
<?php
class Namespace_Module_Model_Observer
{
/**
* Flag to stop observer executing more than once
*
* @var static bool
*/
static protected $_singletonFlag = false;
/**
* This method will run when the product is saved from the Magento Admin
* Use this function to update the product model, process the
* data or anything you like
*
* @param Varien_Event_Observer $observer
*/
public function saveProductTabData(Varien_Event_Observer $observer)
{
if (!self::$_singletonFlag) {
self::$_singletonFlag = true;
$product = $observer->getEvent()->getProduct();
try {
/**
* Perform any actions you want here
*
*/
$customFieldValue = $this->_getRequest()->getPost('custom_field');
/**
* Uncomment the line below to save the product
*
*/
//$product->save();
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
}
/**
* Retrieve the product model
*
* @return Mage_Catalog_Model_Product $product
*/
public function getProduct()
{
return Mage::registry('product');
}
/**
* Shortcut to getRequest
*
*/
protected function _getRequest()
{
return Mage::app()->getRequest();
}
}
MY Answer is extend form and
are given solutions
Step 1: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php
to
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php
Create a function here which give list of all supplier list Like as
Step 2: goto app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml create drop down using step1 define function
Step 3:
goto Database find table "cataloginventory_stock_item" and add new data field for your attribute code.
else run below query
/*********************************************/
ALTER TABLE cataloginventory_stock_item
ADD your_attribute_code
int unsigned NOT NULL,
COMMENT='Cataloginventory Stock Item';
/*********************************************/
End.
more details https://stackoverflow.com/questions/5079549/add-attribute-in-product-information-inventory-tab