winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Hi Moshe/all,
I am trying to add a product to the cart which includes a variable quantity of options called “additional business categories”. These options increase the price of the final product by $100 per category, so I am wondering how I could make this work.
For example, let’s say my base product add URL is
http://www.mystore.com/store/checkout/cart/add/product/138/
and my customer selects “x” amount of additional business categories (remember, they are options for that product only) that should be added to this product, and then my product price will be calculated accordingly. Is this possible to do?
Thanks!!
Fred
Posted: November 26 2007
| top
Moshe
Total Posts: 1771
Joined: 2007-08-07
Los Angeles
In my example I will assume that you will receive the business categories number in URL when adding an item to the cart, and name of the attribute is ‘biz_cat_num’.
1. create attribute for business category quantity in quote item
select @ entity_type_id := entity_type_id from eav_entity_type where entity_type_code = 'quote_item' ; insert into eav_attribute ( entity_type_id , attribute_code , backend_type , frontend_input ) values @ entity_type_id , 'biz_cat_num' , 'int' , 'text' ;
2. overload app/code/core/Mage/Checkout/controllers/CartController.php::addAction:
// add this$product -> setBizCatNum ( $this -> getRequest ()-> getParam ( 'biz_cat_num' )); // right before $cart -> addProduct ( $product , $qty ) //...
3. overload app/code/core/Mage/Sales/Model/Quote/Item.php so that calculated row total will include biz_cat_num:
public function calcRowTotal () { $bizCatPrice = 100 ; // or configurable, for example: // $bizCatPrice = Mage::getStoreConfig('fred/bizcat/price') $rowTotal = $this -> getPrice ()* $this -> getQty (); $rowTotal += $bizCatPrice * $this -> getBizCatNum (); $this -> setRowTotal ( $rowTotal ); return $this ; }
Signature
- I would love to change the world, but they won’t give me the source code -
Posted: November 26 2007
| top
| # 1
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Hi Moshe,
Just one question - is there a function defined as setBizCatNum?
Thanks!
Fred
Posted: November 27 2007
| top
| # 2
Moshe
Total Posts: 1771
Joined: 2007-08-07
Los Angeles
All the models extend Varien_Object which provide functionality of dynamic getters and setters by automagic __call method of PHP5.
So, when you call
$this -> setBizCatNum ( $value );
effectively it equivalents to
$this -> _data[ 'biz_cat_num' ] = $value ;
if the method setBizCatNum() is not defined.
Same with getters:
$value = $this -> getBizCatNum (); // equivalents to $value = $this -> _data[ 'biz_cat_num' ] ;
where capital letters in method name are replaced with underscores in key name.
There is also
// same as $flag = isset($this->_data['biz_cat_num']);$flag = $this -> hasBizCatNum (); // same as unset($this->_data['biz_cat_num']); $this -> unsBizCatNum ();
You could also use more conventional
$this -> setData ( 'biz_cat_num' , $value );
But then you would loose capability of custom logic on this action.
Signature
- I would love to change the world, but they won’t give me the source code -
Posted: November 27 2007
| top
| # 3
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
That is what I was hoping to hear. Yay PHP5 Magic Methods! Thanks, Moshe!
Posted: November 27 2007
| top
| # 4
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Hi Moshe
I did all the changes as indicated, but the URL doesn’t seem to reflect our changes:
http://myonline.jagflyhosting.com/store/checkout/cart/add/product/141/biz_cat_num/2
should be the product price ($350) plus $200 (2 business categories). Yes, I’ve checked that the attribute is names correctly in the DB, and the entity_type_id = 15, which is the id corresponding to the quote_item entity type. Help!
Posted: November 27 2007
| top
| # 5
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Would anyone be able to help with the above request? Thanks in advance!
Posted: November 28 2007
| top
| # 6
Moshe
Total Posts: 1771
Joined: 2007-08-07
Los Angeles
Do you see a value in table sales_quote_entity_int for biz_cat_num attribute_id ?
Signature
- I would love to change the world, but they won’t give me the source code -
Posted: November 28 2007
| top
| # 7
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Nothing there for attribute_id 537 (biz_cat_num).
Posted: November 28 2007
| top
| # 8
Moshe
Total Posts: 1771
Joined: 2007-08-07
Los Angeles
Could you paste your customizations?
Signature
- I would love to change the world, but they won’t give me the source code -
Posted: November 28 2007
| top
| # 9
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
first, in app/code/core/Mage/Sales/Model/Quote/Item.php:
public function calcRowTotal () //Overloaded { $bizCatPrice = 100 ; // or configurable, for example: // $bizCatPrice = Mage::getStoreConfig('fred/bizcat/price') $rowTotal = $this -> getPrice ()* $this -> getQty (); $rowTotal += $bizCatPrice * $this -> getBizCatNum (); $this -> setRowTotal ( $rowTotal ); //$this->setRowTotal($this->getPrice()*$this->getQty()); return $this ; }
second, in app/code/core/Mage/Checkout/controllers/CartController.php (function addAction):
$cart = $this -> _getCart (); try { $product = Mage :: getModel ( 'catalog/product' ) -> load ( $productId ) -> setConfiguredAttributes ( $this -> getRequest ()-> getParam ( 'super_attribute' )) -> setGroupedProducts ( $this -> getRequest ()-> getParam ( 'super_group' , array())) -> setBizCatNum ( $this -> getRequest ()-> getParam ( 'biz_cat_num' )); //Custom Tweak for ACCGS Added by Fred 11/26/2007 $cart -> addProduct ( $product , $qty ) -> addProductsByIds ( $additionalIds ) -> save (); $this -> _backToCart (); } catch ( Exception $e ) { ...
--- table "eav_attribute" --- attribute_id : 537 entity_type_id : 15 attribute_code : biz_cat_num attribute_model : NULL backend_model : NULL backend_type : int backend_table : NULL frontend_model : NULL frontend_input : text frontend_label : Additional Business Categories frontend_class : validate - digits source_model : NULL is_global : 1 is_visible : 1 is_required : 1 is_user_defined : 1 default_value : 0 is_searchable : 0 is_filterable : 0 is_comparable : 0 is_visible_on_front : 0 is_unique : 1 apply_to : 0 use_in_super_product : 1 HTH !
Posted: November 28 2007
| top
| # 10
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
Bump. Help still required, thank you!
Posted: November 30 2007
| top
| # 11
Moshe
Total Posts: 1771
Joined: 2007-08-07
Los Angeles
Ok, there’s another place - look in Mage_Sales_Model_Quote_Item_Abstract::importCatalogProduct
Signature
- I would love to change the world, but they won’t give me the source code -
Posted: November 30 2007
| top
| # 12
winans_fred
Total Posts: 79
Joined: 2007-09-06
Easthampton, MA
there is nothing in there that factors in the biz_cat_num parameter. Should I put something there?
Thanks!
Posted: November 30 2007
| top
| # 13
Mark_Kimsal
Total Posts: 186
Joined: 2007-09-12
Michigan, USA
Fred, you have to edit one function in Sales/Model/Quote/Item/Abstract.php
I have two variables i’m keeping track of, so my importCatalogProduct() looks like this:
$this -> setProductId ( $product -> getId ()) -> setSku ( $product -> getSku ()) -> setName ( $product -> getName ()) -> setWeight ( $product -> getWeight ()) -> setTaxClassId ( $product -> getTaxClassId ()) -> setCost ( $product -> getCost ()); $this -> setLineitemdetails ( $product -> getLineitemdetails ()); $this -> setConfigid ( $product -> getConfigid ());
@moshe
This doesn’t seem to save my “text” type variables, only varchar.
I ran this for each variable
insert into eav_attribute ( entity_type_id , attribute_code , backend_type , frontend_input ) values ( 15 , 'lineitemdetails' , 'text' , 'text' );
There is a record in “sales_quote_entity_text” with the correct attribute_id, but the value column is empty. The set function call works, I can see the correct value inside “_data” of the quote item, I can’t find where the quote item is saved to sales_quote_entity_*.
One last question, what’s the difference between sales_quote_entities and sales_order_entities? Are sales quotes like a shopping cart or a list of line items and a sales order is the information about shipping/payments?
Signature
There’s info on lots of custom modules in my Magento Group
http://www.magentocommerce.com/group/view/174
Need Upgrade help from 0.6, 0.7, and 0.8 available? P.M. me for details on CMS integration.
Posted: December 14 2007
| top
| # 14
Mark_Kimsal
Total Posts: 186
Joined: 2007-09-12
Michigan, USA
I figured it out, sort of. If my TEXT data has commas in it, it won’t save to the DB.
“GU, UD” does not save, but
“GUUD” does… still working on this.
EDIT
Nope, that isn’t even right. Sometimes it works and sometimes it doesn’t. I have all my caching off. Now it’s mostly on the not working side. I got it to work 1 time.
Signature
There’s info on lots of custom modules in my Magento Group
http://www.magentocommerce.com/group/view/174
Need Upgrade help from 0.6, 0.7, and 0.8 available? P.M. me for details on CMS integration.
Posted: December 17 2007
| top
| # 15