在Magento产品管理中添加额外信息

本文详细阐述了如何在Magento框架下,通过创建供应商管理、产品与供应商关联,以及实现产品标签、Block与模板更新,进而根据产品属性自动分配销售参与者的金额。包括插件开发、新增产品标签、保存产品时的数据捕捉,以及相关代码实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前2天有个需求,当一个产品被销售后,我们需要根据产品的属性,来分配供应商、网站服务提供商等销售参与者的金额。

Magento也可以直接在界面上添加产品属性,但这不符合现有的需求。现有需求是在产品中新增一个从表。

故其设计的总体思路是:

1.创建供应商管理

2.创建产品管理中供应商与产品的关联


实现:

1.创建一个插件,来对供应商进行增、删、改(这个就不多说了,比较简单)

2.在产品管理中添加产品的额外的信息(新添一个栏目)、设置Block&模板、Layout文件

关键点:

2.1新增产品标签

<?xml version="1.0"?>
<layout version="0.1.0">
    <supplier_adminhtml_supplier_index>
        <reference name="content">
            <block type="supplier/adminhtml_supplier" name="supplier" />
        </reference>
    </supplier_adminhtml_supplier_index>
    	
	<adminhtml_catalog_product_edit>
		<reference name="product_tabs">
			<action method="addTab"><name>Supplier Service</name><block>supplier/adminhtml_Catalog_Product_Edit_Tab_SupplierTab</block></action>
		</reference>
	</adminhtml_catalog_product_edit>
</layout>

2.2 创建相应的Block,以便admin的模板页面调用

Block\Adminhtml\Catalog\Product\Edit\Tab\SupplierTab.php

class xxxx_Supplier_Block_Adminhtml_Catalog_Product_Edit_Tab_SupplierTab extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface 

{
	
	 
	
	public function __construct() {
		parent::__construct ();
		$this->_supplierGroups = null;
		$this->setTemplate ( 'supplier/tab/supplier.phtml' );//使用supplier.phtml模板
	
	}
	
       public function getSupplierPrice() {
		$read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
		$results = $read->fetchAll("SELECT * FROM supplier_serviceprice where product_id=".$this->_getObject()->getId());//在这里,可以直接使用SQL语句
		return $results;
	}
	
	public function getTabLabel() {
		return Mage::helper ( 'core' )->__ ( 'Supplier Service' );//这是新增的标签
	}
	public function getTabTitle() {
		return Mage::helper ( 'core' )->__ ( 'Supplier Service' );//这是新增的标签

} public function canShowTab() {return true;}
public function isHidden() {return false;} 
protected function _getObject(){return Mage::registry('product'); //这是当前产品,
} }

2.3 为了在保存产品时,把新增栏目的数据内容也保存,需要为catalog_product_save_after这个切入点做文章,并把这个切入点所需要使用的类名与方法名注入


 <adminhtml>
	<events> 
            <catalog_product_save_after>
            	<observers>
            		<xxx_product_savePrice>
	            		<type>singleton</type>
    	        		<class>xxx_Supplier_Model_Observer_Adminhtml_SaveServicePrice</class>
        	    		<method>savePrice</method>
        	    	</xxx_product_savePrice>
            	</observers>
            </catalog_product_save_after>
	</events>
    </adminhtml> 
并且,需要在该插件中的Model部分加入Model\Observer\Adminhtml\SaveServicePrice.php

这时在保存订单时,相关信息也就可以保存了

class xxx_Supplier_Model_Observer_Adminhtml_SaveServicePrice
{

	public function savePrice(Varien_Event_Observer $observer)
	{
	   
	  
	   $receiverSuppliers = Mage::app()->getRequest()->getPost('receiverSupplier');
	   $receiverPrice = Mage::app()->getRequest()->getPost('receiverAmount');
	  
	
		try {
			if ($this->_getProduct()) {
			    $this->_deleteCurrentAssociations();
			    $this->_addNewAssociations($receiverSuppliers,$receiverPrice);
			}
		}
		catch (Exception $e) {
			Mage::helper('supplier')->log($e->getMessage());
		}

	}
}









                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值