Page 1 of 1

How to with free products

Posted: Wed Jun 22, 2022 7:57 am
by Pierre_P
Hi there

A question or maybe I'm missing something.
As the title states, how does Phoenix handle payment and shipping options for products that are free and 0 weight like downloads?

Currently at checkout the user will be given payment and shipping options that are not relevant and are forced to select.

How to deal with this?

Re: How to with free products

Posted: Wed Jun 22, 2022 8:11 am
by Kofod95
I would probably just create a PI-module that allows downloading from the product Info page if price and weight is 0. If you need to track the downloads, I guess you could call the relevant checkout-hooks whenever the module is used.

//Daniel

Re: How to with free products

Posted: Wed Jun 22, 2022 8:23 am
by ecartz
There is no specific provision for free/virtual products skipping pages in checkout. But if you want that behavior, you could add it via hooks.

Code: Select all

class hook_shop_checkout_shipping__09_skip_virtual {

  public function listen_startCheckout() {
    if ('virtual' === $GLOBALS['order']->content_type) {
      $_SESSION['shipping'] = false;
      $_SESSION['shipto'] = false;
      Href::Redirect($GLOBALS['Linker']->('checkout_payment.php'));
    }
  }

}

Code: Select all

class hook_shop_checkout_payment__09_skip_free {

  public function listen_startCheckout() {
    if ($GLOBALS['order']->info['total'] <= 0) {
      $_SESSION['payment'] = false;
      $_SESSION['billto'] = false;
      Href::Redirect($GLOBALS['Linker']->('checkout_confirmation.php'));
    }
  }

}
There might be further side effects to resolve. For example, leaving checkout to order more stuff might break things. This is the kind of thing that the certified developers could help you resolve.

The filenames would be _09_skip_free.php in both cases (to match the class name as given) .

Re: How to with free products

Posted: Wed Jun 22, 2022 8:39 am
by Pierre_P
@ecartz
Thanks, solution seems usable, i will test this out though

I had in my older version:

Code: Select all

	if ( $cart->show_total() == 0 ) {
	$payment_select = $payment_modules->selection();
	$payment = $payment_select[0]['id'];
	if (!tep_session_is_registered('payment')) tep_session_register('payment');
	tep_redirect(tep_href_link('checkout_confirmation.php', '', 'SSL'));
	}

Re: How to with free products

Posted: Wed Jun 22, 2022 10:07 am
by ecartz
The more modern version of that could would be

Code: Select all

	if ( $_SESSION['cart']->show_total() == 0 ) {
	  $payment_select = $GLOBALS['payment_modules']->selection();
	  $_SESSION['payment'] = $payment_select[0]['id'];
	  Href::redirect($GLOBALS['Linker']->build('checkout_confirmation.php'));
	}
Which you could still do in a hook.