- Posts: 13
- Thank you received: 1
set shipping percentage by weight
14 years 7 months ago #42603
by mozgras
set shipping percentage by weight was created by mozgras
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.
14 years 7 months ago #42739
by nicolas
Replied by nicolas on topic Re: set shipping percentage by weight
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.
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.
14 years 7 months ago - 14 years 7 months ago #42926
by mozgras
Replied by mozgras on topic Re: set shipping percentage by weight
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:
I tried substituting this line, but I'm not sure of the variables, and it doesn't work.
Do you have any suggestions here? Thanks.
At line 59:
Code:
$rates[$k]->shipping_price = round($rate->shipping_price + $price*$rate->shipping_params->shipping_percentage/100,$currencyClass->getRounding($rate->shipping_currency_id));
Code:
$rates[$k]->shipping_price = round($rate->shipping_price + $rate->shipping_weight*$rate->shipping_params->shipping_percentage,$currencyClass->getRounding($rate->shipping_currency_id));
Last edit: 14 years 7 months ago by mozgras.
Please Log in or Create an account to join the conversation.
14 years 7 months ago #43029
by nicolas
Replied by nicolas on topic Re: set shipping percentage by weight
$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.
$order->weight
That should hopefully make it work like you want.
Please Log in or Create an account to join the conversation.
14 years 7 months ago #43083
by mozgras
Replied by mozgras on topic Re: set shipping percentage by weight
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.
14 years 7 months ago #43212
by nicolas
Replied by nicolas on topic Re: set shipping percentage by weight
You can easily access the weight of each product with that piece of code:
foreach($order->products as $product){
echo $product->product_weight;
}
foreach($order->products as $product){
echo $product->product_weight;
}
Please Log in or Create an account to join the conversation.
14 years 7 months ago - 14 years 7 months ago #43227
by mozgras
Replied by mozgras on topic Re: set shipping percentage by weight
Thanks for your help and responsiveness. I had to use ->product_weight_orig. But I got it working with this code:
line 33:
And around line 65:
line 33:
Code:
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:
Code:
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: 14 years 7 months ago by mozgras. Reason: code adjustment
Please Log in or Create an account to join the conversation.
13 years 8 months ago - 13 years 8 months ago #88273
by mozgras
Replied by mozgras on topic Re: set shipping percentage by weight
Make edits to these files:
/plugins/hikashopshipping/manual/manual.php
/administrator/components/com_hikashop/extensions/plg_hikashopshipping_manual/manual.php
/plugins/hikashopshipping/manual/manual.php
/administrator/components/com_hikashop/extensions/plg_hikashopshipping_manual/manual.php
Last edit: 13 years 8 months ago by mozgras. Reason: solved issue
Please Log in or Create an account to join the conversation.
Time to create page: 0.313 seconds