by
KK » Tue Feb 11, 2020 6:37 pm
@Blutbaden
I am trying to figure out how to have a product where the customer can enter the amount and then add to cart, then this amount becomes the pp_price and is calculated in the pp_total along with the other products so during checkout the correct amount is charged.
As mentioned in the docs, the 'cart_ex.php' can contain your own custom routines.
Specifically, the 'pre_calc()' within it can be tweaked to manipulate prices of various items in the cart.
Taking the example of the demo cart (
https://www.couchcms.com/demo/simple/), the 'Paper Airplane' item within it contains a custom textbox.
Here is how we can make Couch consider any valid number entered into that textbox as the item's pp_price -
Find the following in cart_ex.php -
- Code: Select all
foreach($this->updated_rows as $key=>$orig_qty){
// A newly added item, as opposed to one being updated, will have its original quantity as 0. Is it so?
if( !$orig_qty ){
And immediately below it, add the following code -
- Code: Select all
$item = $this->items[$key];
if( $item['name']=='paper-airplane' ){ // if this is the item we are interested in ..
$custom_text = $item['options']['Custom Text'];
if( is_numeric($custom_text) ){ // ..and its custom text is set to a valid price
$this->items[$key]['price'] = $custom_text; // set that text as the item's price
}
}
I think that should give you an idea on how to proceed on the backend.
Please test and let me know if this helps.