How to with free products

Open to all! Ask other shopowners for help.
Post Reply
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

How to with free products

Post 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?


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: How to with free products

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to with free products

Post 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) .
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: How to with free products

Post 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'));
	}
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to with free products

Post 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.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply