Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
I need to create a product in cart for a digital card, the only thing that differs from a regular product with a set value is that this product would allow the customer to set the price they want the card to be for so when it's mailed, it's loaded with the correct amount. I could use the variants but couldn't find a way to let the customer set the amount they want.

Any guidance is welcome.
Perhaps using a text-box as option would help?
This is shown in the demo https://docs.couchcms.com/concepts/shopping-cart-1.html -
Code: Select all
Your Message[*TEXT*]
KK thanks for your reply.

To my understanding the message field would give the customer the option to enter the amount but the amount will not reflect in the cart calculations/checkout and the product also still requires a base price. That is the amount that would be calculated in view cart, not the amount they entered in the message field. This would be confusing to a customer checking out I feel and result in inaccurate cart totals.

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. If it is not available out of the box, maybe I can be pointed in the right direction to try and code it.
Perhaps, a new product can be created dynamically? A client fill the form's input (which doesn't happen to be a pp_product_form, but rather a regular form) and you create a product with new pp_price in the background and only then add it to the cart, also in backfround and seamlessly to client perception.
@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.
Spot on perfect thank you KK.
6 posts Page 1 of 1