Extend my Basket

Hi guys,

I want to implement a function in the basket which shows how much money is left until the customer gets free shipping.
Free Shipping : 200€ .

This is my second module so don’t be shocked :slight_smile:

In my Admin i registerd this module:

oxcmp_basket => basket/extendedbasket

My module looks atm like this:
<?php

class extendedBasket extends extendedBasket_parent
{

public function getFreeShipping()
{
    if($this-&gt;oxcmp_Basket__oxprice-&gt;value &gt; 0 ) {
      return(200 - $this-&gt;oxcmp_Basket__oxprice-&gt;value);
    }
    else{
    // return nothing
    }
}
}

In the Template (basket.tpl) i call it like this:
[{$oxcmp_basket->getFreeShipping()}]

I get this error on page:
Function ‘getFreeShipping’ does not exist or is not accessible! (oxBasket)

Can you help me what im doin wrong?

best regards
Zimon

Hi guys,

If i change oxcmp_basket to oxbasket i get this php error:
[20-Jun-2011 13:17:34] PHP Fatal error: Call to a member function getFreeShipping() on a non-object in basket.tpl bla

Any1 any idea? :confused:

best regards

Hi Simoon,

Take a look at the render function of oxcmp_basket and you can see it returns the result of the call to $this->getSession->getBasket(), which returns an oxbasket object, not an oxcmp_basket object. This object is added to the render array as $oxcmp_basket.

This means your module needs to extend oxbasket, not oxcmp_basket.

oxbasket => basket/extendedbasket

Then the call in the template should access the correct function.

[{$oxcmp_basket->getFreeShipping()}]

Confusing, isn’t it…

By the way, you’ll need to get rid of the oxcmp_basket__oxprice etc and will need to take a look at functions like getPrice() & getPaymentCosts() in oxbasket, and the associated oxprice class.

Regards

ChrisJ