Does the method getTotals() in ZMShoppingCart works?

Problems that you cannot find a category for.

Moderators: ckosloff, DerManoMann

Does the method getTotals() in ZMShoppingCart works?

Postby Mindbox » Wed Feb 10, 2010 10:10 am

Hey there,

I'm writing a controller for my shoppingcart and just implemented some basic functionalities. At testing I've figured out that the getTotals() method seems to work not correctly. I've tried with some outputs where the script stops and found that it stops in the _getZenTotals() method by trying to process the following code:
Code: Select all
$this->zenTotals_->process($request);


Is there something wrong or should I have to call some other methods or cart-workflow-issues so that the getTotals method is working?

Greetings

mindbox
Mindbox
Beginner
 
Posts: 28
Joined: Wed Feb 03, 2010 6:13 pm

Re: Does the method getTotals() in ZMShoppingCart works?

Postby DerManoMann » Wed Feb 10, 2010 11:19 am

I think there are two things wrong in that particular area of code.
First, the process method doesn't take any parameters - this is clearly a regression from converting all controllers process methods to taking $request.
Secondly, I think the code fails because a few lines above it goes into the if(!isset($order_total_modules)) { code. If you look at that, you'll see that the code is intended to handle the case where the $order_total_modules is not set. A new obect is created, however not assiged to $this->zenTotals_.
SO I think the whole method _getZenModules() should look like this:

Code: Select all
    protected function _getZenTotals() {
    global $order_total_modules;

        if (null == $this->zenTotals_) {
            $this->zenTotals_ = $order_total_modules;
            if (!isset($order_total_modules)) {
                ZMTools::resolveZCClass('order_total');
                $this->zenTotals_ = new order_total();
            }
            if (!isset($GLOBALS['order']) || !is_object($GLOBALS['order'])) {
                ZMTools::resolveZCClass('order');
                $GLOBALS['order'] = new order();
            }
            $this->zenTotals_->process();
        }

        return $this->zenTotals_;
    }

My guess is that you are calling this method at some point during the request processing where not all zencart init has been finished. Let me know if this works any better - I've never had any issues (which might be just that few people have tried a lot of customization yet...)
DerManoMann
Founder
 
Posts: 305
Joined: Wed Oct 21, 2009 8:52 pm
Location: New Zealand

Re: Does the method getTotals() in ZMShoppingCart works?

Postby Mindbox » Wed Feb 10, 2010 11:34 am

That looks much better. I've already thought about that some code is missing because I didn't understood where $this->zenTotals_ should be assigned with some object...
Now I've got an array with 3 keys (subtotal, shipping, total costs).
Mindbox
Beginner
 
Posts: 28
Joined: Wed Feb 03, 2010 6:13 pm


Return to General Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron