Jump to content

Recalculate Order by Product Monthly Recurring price


pRieStaKos

Recommended Posts

Hello, 

I'm trying to recalculate the Order Summary and set the product price, to each billing cycle by multiplying monthly price.

  • Monthly = $350 USD
  • Quarterly = Monthly * 3
  • Semi-Annually = Monthly * 6
  • Annually = Monthly * 12
  • ....

The product got $0.00 USD Price and the total is been calculated by available Config Options.

{if $cycle eq "Monthly"}
    {assign var="oldMonthlyRecurring" value=" "|explode:$recurring}
    {assign var="MonthlyRecurring" scope="global" value=($oldMonthlyRecurring[0]|replace:{$currency.prefix}:'')|round:2}
    <div class="clearfix">
        <span class="pull-left">{$cycle}:</span>
        {* <span class="pull-right">{$recurring}</span> *}
        <span class="pull-right">{$currency.prefix}{$MonthlyRecurring} {$currency.suffix}</span>
    </div>
{elseif $cycle eq "Quarterly"}
    <div class="clearfix">
        <span class="pull-left">{$cycle}:</span>
        {assign var="QuarterlyRecurring" value=($MonthlyRecurring * 3)|round:2}
        <span class="pull-right">{$currency.prefix}{$QuarterlyRecurring} {$currency.suffix}</span>
    </div>
{/if}

I'm trying to assign the monthly price as global smarty var on `ordersummary.tpl`, but  it returns 0.

Any suggestions ?

Edited by pRieStaKos
Link to comment
Share on other sites

2 hours ago, steven99 said:

Is there a reason you are not using the built-in config options to do that? 

In the quarterly if, you are trying to use  MonthlyRecurring but that was set / assigned in the monthly if .  Move the assignment out of the if block and that should help. 

 

1 hour ago, brian! said:

is there a reason for trying to do like this rather than just using pricing the config options with those multiples directly in the pricing setup ?

There is always "a reason" guys.....That's what makes our live more difficult. 😄

I created a hook to get all (sum) the configoption monthly prices and return it to a template var, so I can set the ordersummary.tpl to recalculate the billing cycle price.

 

add_hook('OrderProductPricingOverride', 1, function($vars) {
    global $smarty;
    $totalMonthly = 0;
    $productGroups = ['Product Group 1', 'Product Group 3', 'Product Group 5'];
        $productObj = Product::find($vars['pid']);
        if (in_array($productObj->productGroup['name'], $productGroups)) {
            foreach ($vars['proddata']['configoptions'] as $configoption) {
                $price = Capsule::table('tblpricing')->where('type', 'configoptions')->where('currency', 1)->where('relid', $configoption)->value('monthly');
                $totalMonthly += $price;
            }
        }
    $smarty->assign('monthlyRecurringPrice', $totalMonthly);
});

The goal is to make the Order Summary show the Starting Product Price with strike and return the Discounted (actual) Price the client gets and see what he "saves" on other billing cycles.

@brian! its a modified request of an old topic you had with discount labels (attached).

screenshot-2020.12.15-19_46_37-1608054397626.png

Edited by pRieStaKos
Link to comment
Share on other sites

5 minutes ago, steven99 said:

You may want to check out this thread that discussing something similar: 

Though I don't think that deals with config options.  However, I think you would best off using an output hook with jquery to get this done as discussed in that thread.

I don’t want to add this in the billing cycle drop list or make it an alert. 

The goal was to add it in the Order Summary with all the correct calculations and it’s already done with the hook plus tpl changes for calculations. 

Thank you all

Link to comment
Share on other sites

I was giving an example of how something similar was being done so that you could take that and  change it to your needs.   As you're using a hook already, it is best to use an output hook and use jquery / javascript to inject such changes rather then changing the template. 

Also, in your hook you assign monthlyRecurringPrice but in the template you use MonthlyRecurring and in at least the quarterly that would matter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated