Forums / Contribution-Writing Guidelines / Guidelines for a mod

Guidelines for a mod

Locked

Started by rickf on 16 Jul 2009, 2:15 PM · Views: 6,257

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
16 Jul 2009, 2:15 PM
#1
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Guidelines for a mod

Hi All,

I am working on a mod...

My question is from a zen cart developer perspective, what is the best methodology to pass data around in the system? For example is using the $_SESSION the way to go.

For example, in my mod I modify some final prices and determine savings etc based on a "buy n get n free" thing I am working on (based on the wiki example). I am using an observer to process the changes. How do I bubble up this information to other parts of the system?

I can make this work, but I am looking for the preferred "passage of Zen coding / data sharing".

Any dev docs, links or advice is appreciated.

thanks,
Rick

16 Jul 2009, 2:54 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Guidelines for a mod

If you're changing values that affect the cart then a session variable would be appropriate and there is already a session array defined that holds that information.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

16 Jul 2009, 3:02 PM
#3
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

kuroi,

Thanks for the quick response. I can see using the $_SESSION['cart'] stuff for existing values but say I wanted to add some of my own with relevance to the cart as well...is adding to the cart session array AOK?

I am probably being a bit anal but I am trying to do the right thing.

Thanks again,
Rick

16 Jul 2009, 3:04 PM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Guidelines for a mod

Provided your careful not to mess with the values there unless that's an explicit part of your mod, I'd say that's the right place to put your cart-related data.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

17 Jul 2009, 12:25 PM
#5
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

Kuroi,

Thanks again...

I have my mod working...however, in my testing I have run into an unexpected issue. Essentially my mod changes the following:

$_SESSION['cart']->total to have a value based on my mod "buy n get n free" algorithm. It works terrific. The cart does the correct thing.

Where it gets balled up is during the checkout process. Once checking out the sub-total does not show the discounted price???

I tried adding additional observer events, however it appears as though the variable used to hold the sub total in the checkout is different then the cart total value. Looking at where the ".totalBox" is set the code uses a different variable.

Where can I update the checkout sub-total?????

any comments appreciated...

thanks,
Rick

17 Jul 2009, 12:28 PM
#6
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Guidelines for a mod

I haven't looked recently, but I'm guessing that the sub-total is built up by the order totals (ot) module from everything that goes into the order. Just changing the total wouldn't necessarily be enough. You may need to adjust the inputs or add a new one to reflect the reason that you are changing the total.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

17 Jul 2009, 4:14 PM
#7
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

Thanks Kuroi...

Looking through the code now...so is the preferred way to make discount entries? I notice the ot_subtotal.php is where the subtotal etc is determined...what is not clear is how to access this stuff from a mod perspective....

I have mucked with it a bit...seems a little clunky, wonder if I am missing something.

thanks,
Rick

18 Jul 2009, 4:47 PM
#8
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,929
Plugin Contributions:
3

Re: Guidelines for a mod

Hi,

If you look at the actual code contained in some of the order total modules, e.g ot_subtotal.php, ot_tax.php, ot_total.php
you will see that no actual calcualtions take place here, and all these modules do is output information that is calcualted in the order class.

If you want to change these values, this needs to be done while that calculation is done in the order class. (in 1.3.8 you should be looking at the code in the order class cart method (circa line. 420-520)

Unfortunately in the current (presently v1.3.8a) version there are no notifiers in the order class that would allow you to hook into that code, although if you want to add your own feel free.

There are other ways of tapping into the order total system, that would not require touching core code. This is how things like the discount coupons and group pricing work.

You could go down this route but it does have some complications. The new order total module would need to be installed, and 'activated' by the user. You would also need to ensure that it had the correct 'sort order' as generally this governs what other sort orders you can affect. e.g. if you wanted your order total module to affect the sub total, it would need to have a sort order that was less than that of the sub total order total module.

what would also work, and I think kuroi alluded to this, is to provide a order total module that replaced the current sub total module, you would of course need to provide instructions to your users to disable the original sub-total module.

19 Jul 2009, 9:19 PM
#9
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

Wilt,

Thanks, exactly what I was looking for, I appreciate the words of wisdom.

Best regards,
Rick

23 Jul 2009, 3:56 PM
#10
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

Hi all,

I assume I am missing a critical piece here...any guidance is really appreciated.

So I am building a mod for my site to support 'buy n get n free'. I have added in an ot_buy_get order_total module, I have added in the administration pieces to load the mod, which all seem to work fine.

Where this still falls flat is in how the actual order total will get updated. So far when the 'process' routine is called for my ot_buy_get module it modifies the $order->info['total'] value to reflect the savings. The cart does the correct thing showing the deductions, as well as, a savings line. The savings info is stored in a session variable.

How do I intercept where the checkout order total value is updated? Should there be a callback or class override in my ot_buy_get to handle the checkout process changes I need?

Sorry if I am being a little dense here...the program flow is not quite obvious in my limited exposure. Looking at ot_coupon as an example etc they seem to only update the same $order->info['total'] value. Where does the actual order data get modified????

Many thanks,
Rick

23 Jul 2009, 5:52 PM
#11
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,929
Plugin Contributions:
3

Re: Guidelines for a mod

Hi,

Are you asking where the order actually gets submitted to the database?

If so this is done in the order class (via checkout_process)

There are method in the order class called 'create/create_add_products' which uses the values held in $order->info

HTH

23 Jul 2009, 7:33 PM
#12
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

hmmm, there lies the confusion on my end...I have updated the $order->info total and performing a var_dump on that session array confirms it prior to confirming the order, yet the total in the cart once the order is placed is wrong.

I'll dig around some more, if you have any guidance I'd appreciate it.

Yes, I figured if I updated the cart info the database would end up holding the modified total...

thanks again,
Rick

14 Aug 2009, 7:24 PM
#13
rickf avatar

rickf

New Zenner

Join Date:
Mar 2009
Posts:
16
Plugin Contributions:
0

Re: Guidelines for a mod

Okay, so I have my mod working...I am seeing some odd behavior I hope someone can explain.

I created an ot_xxx module that resides in the includes/modules/order_total directory. It loads via the admin and processes the $order->info information to make changes to the total / tax values based on items in the cart. The mod supports buy N get N free across listed products or categories.

In the constructor is a variable:
$this->credit_class

If set to 'true' my mod works fine but the payment method ignores the payment method string value (paypal or check money order) indicated during checkout and sets it to blank. The confirm email shows discount as the payment type. If 'false' the payment method string is correct but the totals are not updated correctly.

So I do not wish to have the payment method changed. What is one to do? I feel like there is very limited documentation on what all this stuff means and have been spending a great deal of time unraveling other mods etc.

Any help is appreciated.

14 Aug 2009, 8:51 PM
#14
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,929
Plugin Contributions:
3

Re: Guidelines for a mod

The problem is that generally normal order total modules cannot dynamically alter other order totals. This is why such things as coupons/gv's etc are defined as credit_class modules.

I am also guessing the reason that your order total module is resetting the payment method (when defined as credit class module) is that it is either

A) Not defining some of the methods needed by credit class modules.

B) Is recalculating the order totals at the wrong point.

Without seeing the code it would be a little difficult to pinpoint the exact problem.

However, as a starting point you should check especially that you have defined a pre_confirmation_check method.

If the code is work in progress I'd be happy to look it over if you Pm'd it to me.

6 Jun 2010, 5:16 AM
#15
zranno avatar

zranno

New Zenner

Join Date:
Apr 2008
Posts:
9
Plugin Contributions:
0

Re: Guidelines for a mod

Wilt, were you able to solve this issue? I'm sure I have the exact same problem. I created a custom order total module by cloning the coupon module. Totals are showing correctly on page 2 and 3 of the checkout process. However, when I check the completed order, the deduction (and label) is missing.

I'm passing all the same method data as the coupon module and processing the $od_amount in the same place (i believe) as the coupon module.

Generally speaking, is there a notification in another file that should be adjusted? I'm grasping at straws here. Thanks.