set shipping percentage by weight

  • Posts: 13
  • Thank you received: 1
12 years 8 months ago #42603

I see how to set it up by % of the cost of the product, but can I set the shipping = weight * value?

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

  • Posts: 82796
  • Thank you received: 13357
  • MODERATOR
12 years 8 months ago #42739

You can't do that with the manual shipping plugin in HikaShop.
You can set it like that for example: from 0 to 1.5kg => $X, from 1.5 to 3.5kg => $Y
but you can't just set a percentage for it.

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

  • Posts: 13
  • Thank you received: 1
12 years 8 months ago #42926

It would be a great feature, as shipping is often calculated by weight as opposed to price. I was trying to modify the plugin php - without modifying the front-end - by using the percentage field I thought I could make it work like this:
At line 59:

$rates[$k]->shipping_price = round($rate->shipping_price + $price*$rate->shipping_params->shipping_percentage/100,$currencyClass->getRounding($rate->shipping_currency_id));
I tried substituting this line, but I'm not sure of the variables, and it doesn't work.
$rates[$k]->shipping_price = round($rate->shipping_price + $rate->shipping_weight*$rate->shipping_params->shipping_percentage,$currencyClass->getRounding($rate->shipping_currency_id));
Do you have any suggestions here? Thanks.

Last edit: 12 years 8 months ago by mozgras.

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

  • Posts: 82796
  • Thank you received: 13357
  • MODERATOR
12 years 8 months ago #43029

$rate->shipping_weight does not exists. The sum of the weight of the products in the cart is in the variable:
$order->weight

That should hopefully make it work like you want.

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

  • Posts: 13
  • Thank you received: 1
12 years 8 months ago #43083

Overall weight isn't great because I need the weight for each product, so that I can use that value to multiply by the value in the percentage field. Is there a way I can reference a product's weight and percentage value in the same bit of code? Thanks.

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

  • Posts: 82796
  • Thank you received: 13357
  • MODERATOR
12 years 8 months ago #43212

You can easily access the weight of each product with that piece of code:

foreach($order->products as $product){
echo $product->product_weight;
}

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

  • Posts: 13
  • Thank you received: 1
12 years 8 months ago #43227

Thanks for your help and responsiveness. I had to use ->product_weight_orig. But I got it working with this code:

line 33:

if(!empty($order->products)){
    					$copy = null;
                                        $product_count = 0;  //Initialize count
    					$copy->products = array();
	    				foreach($order->products as $k => $row){
	    					if($row->product_weight > 0){
	    						$copy->products[] = $row;
                                                        // Get weight and quantity for each product
                                                        $product_weight[$product_count] = $row->product_weight_orig;
                                                        $product_quantity[$product_count] = $row->cart_product_total_quantity;
                                                        $product_count++;
	    					}

And around line 65:
if(isset($rate->shipping_params->shipping_percentage) && bccomp($rate->shipping_params->shipping_percentage,0,3)){
							$currencyClass = hikashop_get('class.currency');
							//$rates[$k]->shipping_price = round($rate->shipping_price + $price*$rate->shipping_params->shipping_percentage/100,$currencyClass->getRounding($rate->shipping_currency_id));
						        //Set rate for each product
                                                        $multiplier = $rate->shipping_params->shipping_percentage;
                                                        for ($i=0;$i<$product_count;$i++){
                                                         $rates[$k]->shipping_price = round($rates[$k]->shipping_price + $product_weight[$i]*$product_quantity[$i]*$multiplier,$currencyClass->getRounding($rate->shipping_currency_id));
                                                        }
                                                }

Last edit: 12 years 7 months ago by mozgras. Reason: code adjustment

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

  • Posts: 13
  • Thank you received: 1
11 years 9 months ago #88273

Make edits to these files:
/plugins/hikashopshipping/manual/manual.php
/administrator/components/com_hikashop/extensions/plg_hikashopshipping_manual/manual.php

Last edit: 11 years 9 months ago by mozgras. Reason: solved issue

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

Time to create page: 0.064 seconds
Powered by Kunena Forum