Sybille Posted September 7, 2017 Share Posted September 7, 2017 Hi, Is it possible, to check on the config product if a product has pro rata billing activated or not. If pro rata billing for the particular product is activated I’d like to show a text, which says the price for the product is calculated by pro rata. On the cart page the variable $products.prorata is available but not on the config product page. Many thanks for your support. Sybille 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 7, 2017 Share Posted September 7, 2017 Hi Sybille, Is it possible, to check on the config product if a product has pro rata billing activated or not.If pro rata billing for the particular product is activated I’d like to show a text, which says the price for the product is calculated by pro rata. On the cart page the variable $products.prorata is available but not on the config product page. ahh, from memory I think you're correct and it's not available to that page. if so, the usual next step would be to write a hook to get the value... you'll be able to get the product ID (pid) from the template and use that in either a very basic db query, or via the class docs - get the prorata value, send it back to the template and then modify the template to show your message at the location of your choice if the variable equals 1 (or whatever you set the value to be). 0 Quote Link to comment Share on other sites More sharing options...
Sybille Posted September 25, 2017 Author Share Posted September 25, 2017 Many thanks for your answer and explanation. Sounds quiet complicated. I guess I'm not able to do the hook on my own. May you please help me with it? Many thanks!!! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 25, 2017 Share Posted September 25, 2017 Many thanks for your answer and explanation. Sounds quiet complicated. I guess I'm not able to do the hook on my own. May you please help me with it?! the hook would basically be... <?php /** * Detect if current cart product uses Pro Rata Option * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function cart_prorata_hook($vars) { if ($vars['templatefile']=='configureproduct'){ $pid = $vars['productinfo']['pid']; $prorata = Capsule::table('tblproducts') ->where('id',$pid) ->value('proratabilling'); if ($prorata == "1") { return array("prorata" => $prorata); } } } add_hook("ClientAreaPageCart", 1, "cart_prorata_hook"); and then somewhere appropriate in the configureproduct.tpl template, you would use... {if $prorata}this is a prorata product{/if} or whatever text you wish to output if the product uses prorata. 0 Quote Link to comment Share on other sites More sharing options...
Sybille Posted September 28, 2017 Author Share Posted September 28, 2017 Hi brian! Many thanks. The code produces an error on my system. I tried a lot but couldn't solve the problem till jet. What «productinfo» stands for in «$pid = $vars['productinfo']['pid'];» 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 28, 2017 Share Posted September 28, 2017 what's the error it produces? it works fine on a v7.2.3 dev.. I suppose if you were trying this on a v6 site, it would be ->pluck('proratabilling'); instead of ->value('proratabilling'); 0 Quote Link to comment Share on other sites More sharing options...
Sybille Posted September 28, 2017 Author Share Posted September 28, 2017 Hi brian! I just came to the same solution as you. =) Is it possible to get the output on the ordersummary? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 28, 2017 Share Posted September 28, 2017 Is it possible to get the output on the ordersummary? not as easily... depending on which order summary you mean... if it's the one at the configure product stage, then the variables would be different and the prorata value would still be missing by default, so you'd need another hook to get it; if it's the one at the viewcart stage, then you could potentially have multiple products in the cart, each of which may or may not be using pro rata... so again you would need a hook, but it might need to be a lot more complicated to cover all eventualities. 0 Quote Link to comment Share on other sites More sharing options...
Sybille Posted September 28, 2017 Author Share Posted September 28, 2017 First I need it on the order summary, the one on the product config stage (ordersummary.tpl). I thought I could use the same hook and just change "ClientAreaPageCart" in the string "add_hook("ClientAreaPageCart", 1, "cart_prorata_hook");" 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 28, 2017 Share Posted September 28, 2017 First I need it on the order summary... when you say first, that implies there's going to be a second, third & fourth! the one on the product config stage (ordersummary.tpl). I thought I could use the same hook and just change "ClientAreaPageCart" in the string "add_hook("ClientAreaPageCart", 1, "cart_prorata_hook");" well that wouldn't work for a number of reasons... not the least of which is that I don't think ordersummary can use hooks... it's not a template in the true sense, it's just a js included template, so I don't think it triggers any hook points. you could probably do it using {php} tags in the ordersummary template - but that's frowned upon and not a habit to get into using.... while you could get the PID value from the template, you'd still have to query the database to get the prorata value... if your using v6, then you can't use the classes as an alternative. unless you're prepared to put the work in, it would be easier to just output the prorata text in the proper templates, e.g configureproduct 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.