product quantity price calculation override plugin

  • Posts: 118
  • Thank you received: 3
11 years 9 months ago #122872

Hi all, just a query. I have been researching the ability to do price calculations based on custom fields and every post I come across (and there are heaps of them), have the answer "you need to create a product quantity price calculation override plugin". Has anyone actually completed one of these plugins?

Could Hikashop look at implementing a sample of one of these into the core Hikashop Business edition. It seems most people just want to be able to have a text field quantity multiplied by the product price, and then multiplied by another text field quantity.

eg: We sell Printing.
Fields would be "paper type", "number of pages in document", "sets required".
When the "paper type" is selected, it has a fixed price, the user then enters the number of pages in their document to print into the "number of pages in document" field, the user then enters the number of sets they want printed into the "sets required" field, then they "add to cart" (or possibly a "Calculate" button would give them a total price before adding to cart).

A simpler example would be as above but without the "paper type" field.

Seems like a simple calculation in my head but I'm not a programmer, I think this sort of plugin implemented as a standard example included with the paid for Business Edition, would be a valuable asset to Hikashop and used frequently if people know its there :)

Thoughts?

Please Log in or Create an account to join the conversation.

  • Posts: 26253
  • Thank you received: 4040
  • MODERATOR
11 years 9 months ago #122932

Hi,

We already provide a sample plugin which is called "HikaShopCustom Price plugin" (and also "plg_system_custom_price").
It is a system plugin.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 9 months ago #122964

Hello, thanks for your reply. I looked and couldn't find that plugin anywhere. I have seen multiple posts now where you have mentioned that plugin and the users have had trouble finding it, most seem to have sorted it although don't say how.

I have had a look in mywebsite.co.nz/plugins/system and have found one called "custom_price", is this it? If so, how do I get it installed? I tried the discover feature of the joomla extensions manager and it doesn't show in there either.

Hikashop 2.2.1
Joomla 2.5.14

Thanks for your help.

EDIT: Found the plugin, its still called "Hikashop Donation Plugin" in the plugin list. I'll take a look and see what it allows us to do.

Last edit: 11 years 9 months ago by ahcopyart. Reason: update info

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 9 months ago #122968

Ok, I have taken a look, but can't see where to edit the plugin. Do I have to edit the actual "custom_price" file or is there somewhere in Hikashop that allows us to alter the code for that plugin?

Please Log in or Create an account to join the conversation.

  • Posts: 26253
  • Thank you received: 4040
  • MODERATOR
11 years 9 months ago #122971

Hi,

The best for the moment is to edit the file directly.
After that, when you will have a good working plugin, you will have to see to create a new one (with a new plugin name) so you won't loose your modification with HikaShop updates.
Otherwise, because the plugin is include in the HikaShop package, it will be updated like other plugins and it will rewrite the file content, removing your modifications.

But for the moment, if you do not reinstall/update HikaShop, you can simply edit the plugin to make your tests.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 9 months ago #122999

Hello, thanks. I'll go and see if I can figure it out :)

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 9 months ago #123343

Got it sorted, thanks for your help.

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 8 months ago #125792

Ha! We were just doing some final testing and it actually is not working correctly. Basically this is happening:

Our product with the custom field "originalpdfpages" is doing this calculation:
Product Price * originalpdfpages * Order Quantity

This gives us the price per page, multiplied by the number of pages in the original pdf document multiplied by the quantity of sets ordered.

The downside is that this has stopped the other normal calculations on our other products which should just be the simple Product Price multiplied by the Order Quantity.

We have edited the Custom Price plugin, commented out all the code except the header info, this is how our plugin looks:

<?php
/**
* @package HikaShop for Joomla!
* @version 2.2.1
* @author hikashop.com
* @copyright (C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
?><?php
jimport('joomla.plugin.plugin');
class plgSystemCustom_price extends JPlugin{
}

//QCP added to calculate price based on number of original pages in PDF
function hikashop_product_price_for_quantity_in_cart(&$product){
$currencyClass = hikashop::get('class.currency');
$quantity = $product->cart_product_quantity*$product->originalpdfpages;

$currencyClass->quantityPrices($product->prices,$quantity,$product->cart_product_total_quantity);
}

function hikashop_product_price_for_quantity_in_order(&$product){
$quantity = $product->order_product_quantity*$product->originalpdfpages;

$product->order_product_total_price_no_vat = $product->order_product_price*$quantity;
$product->order_product_total_price = $product->order_product_price*$quantity;
}
//end customisation by QCP

I thought this plugin would only affect the products with the custom field, what am I missing
(Sorry I am no coder so forgive me if I did something stupid!)

Please Log in or Create an account to join the conversation.

  • Posts: 83993
  • Thank you received: 13605
  • MODERATOR
11 years 8 months ago #125807

You should change the code like that at the beginning of the two functions:
instead of:
$quantity = $product->cart_product_quantity*$product->originalpdfpages;

have:
if(!empty($product->originalpdfpages)) $quantity = $product->cart_product_quantity*$product->originalpdfpages;

that way, it won't override the price calculation

Please Log in or Create an account to join the conversation.

  • Posts: 118
  • Thank you received: 3
11 years 8 months ago #125914

Thanks heaps. I messed around with 'if' statements for ages but couldn't get it to work correctly. I modified the code to:
if(!empty($product->originalpdfpages)) {
$quantity = $product->cart_product_quantity*$product->originalpdfpages;
} else {
$quantity = $product->cart_product_quantity;
}

I found I had to put in the 'else' expression to force the normal calculation if the field was empty.
SOLVED - thanks again :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum