Jump to content

Product Addons showing wrong pricing in standard orderform


websavers

Recommended Posts

In a recent WHMCS update we were provided with the ability to enter different pricing cycles for product addons. This is great! However it as resulted in the standard cart orderform not behaving well. Steps to reproduce:

  • Configure a product with annual pricing only. Configure its addon to both have Monthly and Annual pricing
  • Place an order with the standard cart orderform with the product set to annual pricing.
  • When configuring the product, the addon will show its monthly pricing, yet when you add the addon to the cart, it will show annual pricing (bait and switch!)

At bare minimum, the order form should dynamically change the display of the addon pricing (on the addon itself; where the title and description is) based on the parent product's selected cycle.

Optimally I would much prefer that the addon have a selectable drop down so that the buyer can choose a different payment cycle for their addon than the parent product, but that it would default to matching the cycle with the parent product.

Link to comment
Share on other sites

18 hours ago, jas8522 said:

At bare minimum, the order form should dynamically change the display of the addon pricing (on the addon itself; where the title and description is) based on the parent product's selected cycle.

I think you'd need a js solution for that as it's being refreshed by js... also, the correct price is shown in order summary (for that billingcycle if it's priced)... if it isn't priced, it still shows the lowest billingcycle price (it's a mess!)... but yes, it should change the display.

18 hours ago, jas8522 said:

Optimally I would much prefer that the addon have a selectable drop down so that the buyer can choose a different payment cycle for their addon than the parent product, but that it would default to matching the cycle with the parent product.

that would require significant changes... and heading off into the feature request realms.

let us hope these issues are addressed in v7.5 next month.

I will add that all the prices are there available to the template, so if you wanted to show all available prices for the addon, you could do so.

Link to comment
Share on other sites

On 2018-02-16 at 1:31 PM, brian! said:

I will add that all the prices are there available to the template, so if you wanted to show all available prices for the addon, you could do so.

Maybe you have some insight on this. My {debug} on the template shows that it *thinks* it has the prices, but intead of actually having the prices, it's got some kind of internal WHMCS pricing object... but if it really was in object format wouldn't the {debug} output show the data? It does for all other objects... in other words, I think they tried to introduce the pricing into the template vars, but messed up by providing the data in the wrong format. Though I could be interpreting that wrong!

Link to comment
Share on other sites

7 hours ago, jas8522 said:

Maybe you have some insight on this.

stares into his crystal ball.... :664_crystal_ball:

7 hours ago, jas8522 said:

My {debug} on the template shows that it *thinks* it has the prices, but instead of actually having the prices, it's got some kind of internal WHMCS pricing object...

that's the recently introduced Price Formatter class - some of the new pricing variables use this format now... they can be slightly easier to manipulate rather than the "usual" string price variables.

7 hours ago, jas8522 said:

but if it really was in object format wouldn't the {debug} output show the data? It does for all other objects...

yeah, but not for price formatter variables and arrays... you need to output them to see their values.

7 hours ago, jas8522 said:

in other words, I think they tried to introduce the pricing into the template vars, but messed up by providing the data in the wrong format.

no the prices are there, you just can't see them automatically in a debug window.

7 hours ago, jas8522 said:

Though I could be interpreting that wrong!

could be. https://youtu.be/Va_Rmpd3PZI?t=14s

if you take a look in templates/standard_cart/configureproduct.tpl, there is a block of code that shows the addon price (lowest cycle) ~ line286...

<div class="panel-price">
	{$addon.pricing}
</div>

g_A1_R8fvl_S5_CKQDtc8_AUIGA.png

but if we replace that code with a foreach loop to cycle through the array of available addon prices, and then tweak it a little to make it multi-lingual, we can list all the addon prices alongside their respective cycles (in the user's chosen language)...

<div class="panel-price">
	{foreach $addon.billingCycles as $addoncycle}
		{assign cycleterm orderpaymentterm|cat:$addoncycle@key}
		{$addoncycle.price} {$LANG.$cycleterm}<br />
	{/foreach}
</div>

I3ja_Mzf9_TECEn_GUwup_U5_TQ.png

l_Ae5_M3_OWSh_W-rev_Tz_Vyi6w.png

in the above code I haven't added setup prices, but inside that loop it would be shown by simply using {$addoncycle.setup). :idea:

Link to comment
Share on other sites

That's great, thanks so much! Is there documenation on working with these objects in templates? I couldn't seem to find it! For example, without the {debug} output showing me the structure of the object, how did you know this was the right object var? Guesswork? Output to screen until you find it?

{$addoncycle.price}

I did get some javascript in place to auto change the price, so now that you've shown me how to use the pricing object in my template, I can use this to create a dropdown.

Edited by jas8522
Link to comment
Share on other sites

9 minutes ago, jas8522 said:

That's great, thanks so much! Is there documentation on working with these objects in templates?

don't be daft - this is WHMCS that we're using... we're left to figure these things out for ourselves. 9_9

basically, just call them as you would any other variable... the fact that they're price formatted only comes into play if you want to manipulate them... but in this example, we're not doing that, we're just outputting their values.

11 minutes ago, jas8522 said:

For example, without the {debug} output showing me the structure of the object, how did you know this was the right object var? Guesswork? Output to screen until you find it?

Guesswork? how dare you! :)

from both the debug window, and the existing template code, you can easily tell where the pricing information is (or should be) - $addon.billingCycles - it's the only pricing array there!.

once you know it's an array, just loop through it and display the prices... ignore that it always says (0) after a price object... any other array and you would assume that it's empty, but not so with price formatted variables.

J7j_Dzq_U-_Rw_e_XMBay-yyx_A.png

20 minutes ago, jas8522 said:

I did get some javascript in place to auto change the price, so now that you've shown me how to use the pricing object in my template, I can use this to create a dropdown.

which i'd hope you would update this thread with for others who want to use it. :idea:

Link to comment
Share on other sites

Oh weird. I see. So the WHMCS\View|Formatter\Price Object, when actually output on screen simply becomes the actual value. Strange that they couldn't simply have it show the value in the {debug} output, no? Since that's what it actually ends up being on screen. Then there wouldn't be any documentation needed; it would work as it always has.

43 minutes ago, brian! said:

which i'd hope you would update this thread with for others who want to use it. :idea:

It works, but it's a bit sketchy in that I had no way of showing the cycle properly. I would have been able to do that if we could be guaranteed that each addon would have cycle pricing to match every single cycle of the parent product (then we could just borrow the cycle text from the parent product). But as it stands now, if you've got only monthly and annual pricing for the addon, but select biennial for the parent product, the addon goes to the lowest possible cycle -- monthly in this instance. The price is pulled via ajax query to the cart, but in the cart it doesn't show the cycle next to the addon, so I can't pull that data. So what happens is, the addon pricing is updated, but the cycle is removed from it.

/** Addon Pricing Fixes **/
function ws_update_addon_cycle_pricing(){
  
  var $billingcycle = jQuery('#inputBillingcycle').find(":selected").val();
  
  jQuery(".addon-products .panel-addon").each( function(){

    var $addon_title = jQuery(this).find('label').text();
    var $addon_inputname = jQuery(this).find('label input').attr('name');
    var $addon_price = jQuery(this).find('.panel-price');
    
    if ($addon_price.text().indexOf('One Time') === -1){ //not one-time cycle

      var cycle_matched_price = jQuery.post("cart.php", {
        ajax: 1,
        a: 'confproduct',
        calctotal: true,
        configure: true,
        i: 0,
        billingcycle: $billingcycle,
        [$addon_inputname]: 'on',
        
      }).done(function(html) {
        jQuery(html).find('.pull-left').each(function(){
          if ( jQuery(this).text().indexOf($addon_title.trim()) > -1 ){
            $addon_price.text(jQuery(this).siblings('.pull-right').text());
          }
        });   	
      });
      
    }
    
  });
  
}
//triggers
jQuery(document).ready(function(){
  
  ws_update_addon_cycle_pricing();
  
  jQuery('#inputBillingcycle').change(function(){
    ws_update_addon_cycle_pricing();
  });
  
});

 

Edited by jas8522
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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