How to Add Setup Pricing to a Product

Last modified by JMarkMurphy on Tue, December 23, 2008 16:02
Source|Old Revisions  

This is an old revision of the document!


Overview

The goal of this extension is to create a pricing structure that allows tier pricing for large quantity ordering, but also provides for a setup fee that is not dependent on the quantity ordered to be included in the price of the product. The final pricing formula would look something like this:

final price = (unit price * quantity) + setup fee

Custom options with prices do not work in this model because they are included in the unit price of the product. I will use a price type attribute to hold the setup fee for the product.

Create a New Module

The goal here is to create a new module that can be used to provide the desired pricing function without changing the core Magento code. Throughout this example I will be using the local code pool with a namespace of Company. The module name will be MyModule, and the base Magento directory will be /Magento.

To create the new module we will add the following directories to our Magento install:

/Magento/app/code/local/Company/MyModule
/Magento/app/code/local/Company/MyModule/Block
/Magento/app/code/local/Company/MyModule/Block/Cart
/Magento/app/code/local/Company/MyModule/Block/Cart/Item
/Magento/app/code/local/Company/MyModule/etc
/Magento/app/code/local/Company/MyModule/Model
/Magento/app/code/local/Company/MyModule/Model/Quote

In addition we will need to notify Magento of this new module by creating the following file:

/Magento/app/etc/modules/Company_MyModule.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <config>
  4.     <modules>
  5.         <Company_MyModule>
  6.             <active>true</active>
  7.             <codePool>local</codePool>
  8.         </Company_MyModule>
  9.     </modules>
  10. </config>

Edit config.xml

config.xml describes the module structure to Magento and, in this example, handles the rewrites necessary to tell Magento where our extended classes are, and which classes they replace. Create this file:

/Magento/app/code/local/Company/MyModule/etc/config.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <config>
  4.  
  5.     <modules>
  6.         <Company_MyModule>
  7.             <version>0.1.0</version>
  8.         </Company_MyModule>
  9.     </modules>
  10.  
  11.     <global>
  12.         <blocks>
  13.             <checkout>
  14.                 <rewrite>
  15.                     <cart_item_renderer>Company_MyModule_Block_Cart_Item_Renderer</cart_item_renderer>
  16.                 </rewrite>
  17.             </checkout>
  18.         </blocks>   
  19.        
  20.         <models>
  21.             <mymodule>
  22.                 <class>Company_MyModule_Model</class>
  23.             </mymodule>
  24.             <sales>
  25.                 <rewrite>
  26.                     <quote_item>Company_MyModule_Model_Quote_Item</quote_item>
  27.                 </rewrite>
  28.             </sales>
  29.         </models>
  30.     </global>
  31.  
  32. </config>

Extend the Renderer

Extend the Sales/Model/Quote/Item.php

Modify Templates




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs