PDA

View Full Version : [osCmax V2.0.25] Payment type COD to be changed to be disabled if virtual product is in cart - amongst others!



sio
09-02-2011, 08:49 AM
Hello everybody,
I want to change the payment module COD (wich I do not need) into a "Pay when receiving invoice" (wich does not exist).

Since the shop offers virtual and non virtual products the payment module "Pay when reveiving invoice" shall only be available, if the cart does not carry any virtual product.

My question: How can I change the line in /includes/modules/payment/coc.php in a way that it applies not only for content=virtual but also for content contains virtual amongst others?

I tried to replace

if ($this->enabled == true) {
if ($order->content_type == 'virtual') {
$this->enabled = false;
with <= or >= but without success.
Any ideas?

Thanks

Ruben

pgmarshall
09-02-2011, 09:21 AM
Ruben,

Try using the get_content_type() function.


if ($cart->get_content_type() != 'virtual') {

Also you need to use == or != for equals or not equal to in PHP.

The possible returns from this function are virtual, mixed, physical - So I think in your example you will need something like:



if ($cart->get_content_type() != 'physical') {
$this->enabled=false;
}

Because you want to hide the module if it is virtual OR mixed ie. != (NOT EQUAL) to physical.

Regards,

sio
09-02-2011, 10:57 AM
Thank you Pgmarshall,

I tried it with

if ($this->enabled == true) {
if ($cart->get_content_type() != 'virtual') {
if ($cart->get_content_type() != 'physical') {
$this->enabled=false;
}

Is it how you meant it? Checkout payment - screen will be blanc then.

Then I tried to replace virtual with mixed and got some strange result:
When first product in cart was virtual COD was not enabled, no matter what kind of further product I added.
When first product was physicall COD was enabled no matter what kind of product I added.
if ($this->enabled == true) {
if ($order->content_type == 'mixed') {
$this->enabled = false;

So it is a step forward but still not working.

Are there any further ideas how to solve this problem?

Thank you and best regards,

Ruben

pgmarshall
09-02-2011, 02:32 PM
Nope!

Just put:


if ($cart->get_content_type() != 'physical') {
$this->enabled=false;
}


Regards,

sio
09-04-2011, 05:47 AM
Sorry pgmarshall,

I can't get it working. If I put



if ($cart->get_content_type() != 'physical') {
$this->enabled=false;
}


I just get a blank screen for checkout payment.

Do I need to make changes at some other place too?

Thank you and best regards
Ruben

pgmarshall
09-04-2011, 07:54 AM
Is the only change you made to the module?

White screen = PHP error ... turn on error reporting and post the error back here. (instructions in the wiki).

Regards

sio
09-05-2011, 01:30 AM
Is the only change you made to the module?

White screen = PHP error ... turn on error reporting and post the error back here. (instructions in the wiki).

I didn't change anything else as far as I know.

White screen = PHP error ... turn on error reporting and post the error back here. (instructions in the wiki).

It says:


Warning: Division by zero in /public_html/shop/includes/classes/shipping.php on line 104

Warning: Division by zero in /public_html/shop/includes/classes/shipping.php on line 105

Warning: Cannot modify header information - headers already sent by (output started at /home/u0030664681/public_html/shop/includes/classes/shipping.php:104) in /public_html/shop/includes/functions/general.php on line 34

In /public_html/shop/includes/classes/shipping.php it says on lines 103-105:


if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
$shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
$shipping_weight = $shipping_weight/$shipping_num_boxes;

In /public_html/shop/includes/functions/general.php on line 34 I find


header('Location: ' . $url);

Best,

Ruben

pgmarshall
09-05-2011, 03:11 AM
Do you have a value in Admin -> Configuration -> Shipping/Packing -> Enter the Maximum Package Weight you will ship?

sio
09-05-2011, 03:28 AM
Do you have a value in Admin -> Configuration -> Shipping/Packing -> Enter the Maximum Package Weight you will ship?

Thank you pgmarshall, I did not have a value in there and did not know that it was needed. Now I've entered 1000 and get the following error:


Fatal error: Call to a member function get_content_type() on a non-object in /public_html/shop/includes/modules/payment/cod.php on line 58

Line 57-59 contain your suggestion:

if ($this->enabled == true) {
if ($cart->get_content_type() != 'physical') {
$this->enabled=false;
}
}

Ruben

sio
09-06-2011, 04:19 AM
Thank you pgmarshall, I did not have a value in there and did not know that it was needed. Now I've entered 1000 and get the following error:



Line 57-59 contain your suggestion:


Ruben

hello pgmarshall,
do you have any further idea about that issue?
thank you for taking the time!

best
ruben

pgmarshall
09-06-2011, 04:39 AM
Try: if ($order->content_type != 'physical') { $this->enabled=false; }

sio
09-07-2011, 04:01 AM
Hello Pgmarshall,


Try: if ($order->content_type != 'physical') { $this->enabled=false; }

I get the result that COD will be enabled if the first item in cart is physical no matter what follows and COD will be disabled if first item is virtual.

Best
Ruben

pgmarshall
09-07-2011, 06:00 AM
Right! In cod.php the is a line that reads // disable the module if the order only contains virtual products - after this change the conditional to check for 'mixed' - ie. if ( ($order->content_type == 'virtual') || ($order->content_type == 'mixed') ) - otherwise I am drawing a blank on this ...

sio
09-08-2011, 09:44 AM
Right! In cod.php the is a line that reads // disable the module if the order only contains virtual products - after this change the conditional to check for 'mixed' - ie. if ( ($order->content_type == 'virtual') || ($order->content_type == 'mixed') ) - otherwise I am drawing a blank on this ...

That leads to disabled COD only if first product in cart is virtual.

After trying with all possible variants I found out that
1. COD is disabled when all products in cart are virtual, even if this code is deleted:

// disable the module if the order only contains virtual products
//if ($this->enabled == true) {
// if (($order->content_type == 'virtual')
// { $this->enabled=false; }
// }
}

2. If I disable COD for cart-content that is non-physical, this works out only if a virtual item is first in cart.

// disable the module if the order only contains virtual products
if ($this->enabled == true) {
if ( $order->content_type != 'physical' )
{ $this->enabled=false; }
}

3. The same with "mixed": It disables COD only if first product in cart is virtual.

// disable the module if the order only contains virtual products
if ($this->enabled == true) {
if ( $order->content_type == 'mixed' )
{ $this->enabled=false; }
}

This is like a mystery. Does anybody have a clue?

Ruben

ridexbuilder
09-08-2011, 03:05 PM
1. COD is disabled when all products in cart are virtualMakes perfect sense to me, that one. How can a virtual product be physically delivered? (rhetorical)

sio
09-08-2011, 11:23 PM
Makes perfect sense to me, that one. How can a virtual product be physically delivered? (rhetorical)


The point is, that I change "COD" into "Payable on receiving invoice" and want to have this module only enabled if there is no virtual item in the cart. In Germany it is still quite common that you get your orders delivered together with the invoice and only then you pay. But the willingness to pay probably will probably not be very high for virtual products. So this module should be offered only to carts filled with nothing but physical content.

Ruben