Add Package Weight to USPS Shipping

  • Posts: 20
  • Thank you received: 1
10 years 5 days ago #152818

-- HikaShop version -- : 2.3.0
-- Joomla version -- : 2.5.19
-- PHP version -- : 5.4

Is there any way to add a package weight to the USPS shipping plugin in in the same way that you can add an extra price in the shipping method?

I can get three products in the same rigid envelope so I do not want to add the weight of the envelope to the product. I would like to add the weight of the envelope to a USPS shipping method with a quantity restriction of 1 to 3 products. And then create another one with quantity restrictions of 4-6 and so on.

I would be willing to add a php hack to the plugin knowing that this would have to be done with each upgrade.

I thought about an automatic coupon taking the price of the package off of the cart if they bout three products but I have different size rigid envelopes with different weights.

I hope this makes sense. Any help would be much appreciated!

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
10 years 4 days ago #152851

Hi,

That would require to add the code:

Add weight: <input size="5" type="text" name="data[shipping][shipping_params][weight_approximation]" value="<?php echo @$this->element->shipping_params->weight_approximation; ?>" />
at the end of the file plugins/hikashopshipping/usps/usps_configuration.php
and then change the line:
$parcel->Weight=$package_weight;
to:
$parcel->Weight=$package_weight+$rate->shipping_params->weight_approximation;
in the file plugins/hikashopshipping/usps/usps.php

Then, in your USPS shipping methods, you would have a new "Add weight" field where you could configure the weight to add to the shipping method.

The following user(s) said Thank You: cbaugher

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

  • Posts: 20
  • Thank you received: 1
10 years 4 days ago #152893

Thank you!!! This worked great!!!

But I had to put the first code somewhere else since there was no plugins/hikashopshipping/usps/usps_configuration.php file.
I put it at line 139 in the administrator/components/com_hikashop/views/plugins/tmpl/form.php file and surrounded it with table tags.

<td class="key">
Add weight:
</td>
<td>
<input size="5" type="text" name="data[shipping][shipping_params][weight_approximation]" value="<?php echo @$this->element->shipping_params->weight_approximation; ?>" />
</td>
</tr>


Should there be a usps_configuration.php file?
Will this cause other problems by putting it in the form.php file and should I put it somewhere else?

I think this would be a great feature that a lot of people would love to have as part of the core.

Thank you for your help and quick reply. I love Hikashop with all of its features and customizations.

Attachments:

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
10 years 3 days ago #152906

Hi,

My bad, there is indeed no such file for that shipping plugin.
In that case, your modification is fine but you should instead do it via the menu display->views. That way, you won't loose it when you update HikaShop and you'll just have to add back the modification in the usps.php file.

The following user(s) said Thank You: cbaugher

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

  • Posts: 20
  • Thank you received: 1
10 years 3 days ago #152941

Thank you! I did not realize you could modify the plugin that way.

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

  • Posts: 9
  • Thank you received: 1
10 years 1 day ago #153167

Which files must be edited with which code to make this work properly?

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
10 years 1 day ago #153220

You need to add the code:

<td class="key">
Add weight:
</td>
<td>
<input size="5" type="text" name="data[shipping][shipping_params][weight_approximation]" value="<?php echo @$this->element->shipping_params->weight_approximation; ?>" />
</td>
</tr>
in the file "form" of the view "plugins" via the menu Display>Views before the code:
<tr id="hikashop_shipping_per_product_1"<?php if($this->element->shipping_params->shipping_per_product == false) { echo ' style="display:none;"';}?>>
					<td class="key">
						<label for="data[shipping][shipping_price_per_product]"><?php
							echo JText::_( 'PRICE_PER_PRODUCT' );
						?></label>
					</td>
					<td>
						<input type="text" name="data[shipping][shipping_params][shipping_price_per_product]" value="<?php echo @$this->element->shipping_params->shipping_price_per_product; ?>" />
					</td>
				</tr>

and then change the line:
$parcel->Weight=$package_weight;
to:
$parcel->Weight=$package_weight+$rate->shipping_params->weight_approximation;
at the end of the file plugins/hikashopshipping/usps/usps.php

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

  • Posts: 9
  • Thank you received: 1
10 years 1 day ago #153307

Thank you for the clarification. Worked perfectly.

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

  • Posts: 20
  • Thank you received: 1
9 years 3 months ago #185043

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.17

I started this thread awhile ago and you were are great help. Now with Hikashop 2.3.5 I cannot get this code to work. Your help would be much appreciated.

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
9 years 3 months ago #185082

You need to add the code:

<td class="key">
Add weight:
</td>
<td>
<input size="5" type="text" name="data[shipping][shipping_params][weight_approximation]" value="<?php echo @$this->element->shipping_params->weight_approximation; ?>" />
</td>
</tr>
in the file "form" of the view "plugins" via the menu Display>Views before the code:
<tr id="hikashop_shipping_per_product_1"<?php if($this->element->shipping_params->shipping_per_product == false) { echo ' style="display:none;"';}?>>
					<td class="key">
						<label for="data[shipping][shipping_price_per_product]"><?php
							echo JText::_( 'PRICE_PER_PRODUCT' );
						?></label>
					</td>
					<td>
						<input type="text" name="data[shipping][shipping_params][shipping_price_per_product]" value="<?php echo @$this->element->shipping_params->shipping_price_per_product; ?>" />
					</td>
				</tr>

and then change the line:
$parcel->Weight = $package['w'];
to:
$parcel->Weight=$package['w']+$rate->shipping_params->weight_approximation;
in the file plugins/hikashopshipping/usps/usps.php

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

  • Posts: 20
  • Thank you received: 1
9 years 3 months ago #185107

Thank you very much!!!!!

Last edit: 9 years 3 months ago by cbaugher.

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

  • Posts: 20
  • Thank you received: 1
8 years 3 months ago #227362

I just installed Hikashop 2.6.1 and when I went to the usps.php file to change the code
$parcel->Weight=$package_weight;
to
$parcel->Weight=$package_weight+$rate->shipping_params->weight_approximation;

I noticed that the code was different and that there are two lines of it.
$parcel->Weight = round($packages, 2);

How do I make this change with the new code.

Thanks for your help.

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
8 years 3 months ago #227368

Hi,

You can replace:
$parcel->Weight = round($packages, 2);
by:
$parcel->Weight = round($packages+$rate->shipping_params->weight_approximation, 2);

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

  • Posts: 20
  • Thank you received: 1
8 years 3 months ago #227583

Thank you that worked! However I miss copied the code so:

$parcel->Weight = round($package['w'], 2);
should be replaced with:
$parcel->Weight = round($package['w']+$rate->shipping_params->weight_approximation, 2);

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
8 years 2 months ago #227585

Hi,

Yes ; that's right.
The forum does not appreciate brackets as text ; that's why we more than recommend to put code under the code tags.
Nicolas just copy/paste the content in a previous post, that's why some parts were missing.

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: 3
  • Thank you received: 0
2 years 7 months ago #335256

Joomla
HikaShop Business 4.4.3 [2106041726]
I have been having problems implementing the above code. First thing I see the field that you were adding to the form is already in this version but as "Weight approximation (%)" field, under Specific Configuration. I tried changing the field name to weight_add in both the form field and the usps.php file. No luck. Did the field need to be declared somewhere? I saw another spot in the usps.php file where you added the product weight + product weight * weight_approximation. Tried adding in my weight_add field with out luck.

Can you help me add a package weight to USPS? Thanks

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

  • Posts: 12953
  • Thank you received: 1778
2 years 7 months ago #335286

Hello,

Yes the "Weight approximation" option was added to the plugin for every customers.

Firstly, can you give us more information about what you want to achieve ? Do you want to add an option to your USPS configuration page which will add a fixed weight for every orders ?

Kind regards,
Mohamed

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

  • Posts: 3
  • Thank you received: 0
2 years 7 months ago #335360

Yes,

Just adding a fixed weight to each order.

thanks,
DAvid DeWitt

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

  • Posts: 12953
  • Thank you received: 1778
2 years 7 months ago #335378

Hello David,

In that case the solution will be to edit the file "plugins\hikashopshipping\usps/usps.php" and :
1. add that line :

'weight_approximation_fixed' => array('Weight approximation', 'input'),
Just behind this line :
'weight_approximation' => array('Weight approximation (%)', 'input'),


2. Add these lines :
if (!empty($rate->shipping_params->weight_approximation_fixed)) {
	if (isset($product->product_weight)) $product->product_weight = round($product->product_weight + (float)$rate->shipping_params->weight_approximation_fixed, 2);
	if (isset($product->product_weight_orig)) $product->product_weight_orig = round($product->product_weight_orig + (float)$rate->shipping_params->weight_approximation_fixed, 2);
}

just after these lines :
if (!empty($rate->shipping_params->weight_approximation)) {
	if (isset($product->product_weight)) $product->product_weight = $product->product_weight + $product->product_weight * $rate->shipping_params->weight_approximation / 100;
	if (isset($product->product_weight_orig)) $product->product_weight_orig = $product->product_weight_orig + $product->product_weight_orig * $rate->shipping_params->weight_approximation / 100;
}

3. Add these lines :
if (!empty($rate->shipping_params->weight_approximation_fixed)) {
	if (isset($variant->product_weight)) $variant->product_weight = round($variant->product_weight + (float)$rate->shipping_params->weight_approximation_fixed, 2);
	if (isset($variant->product_weight_orig)) $variant->product_weight_orig = round($variant->product_weight_orig + (float)$rate->shipping_params->weight_approximation_fixed, 2);
}

After these lines :
if (!empty($rate->shipping_params->weight_approximation)) {
	if (isset($variant->product_weight)) $variant->product_weight = $variant->product_weight + $variant->product_weight * $rate->shipping_params->weight_approximation / 100;
	if (isset($variant->product_weight_orig)) $variant->product_weight_orig = $variant->product_weight_orig + $variant->product_weight_orig * $rate->shipping_params->weight_approximation / 100;
}

And you'll have a new "Weight approximation" option which will add a fixed amount to the weight of your products and not a percentage.

Kind regards,
Mohamed.

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

  • Posts: 3
  • Thank you received: 0
2 years 7 months ago #335421

In what weight will this add? lb, oz, gr, kg ??
Thanks
davvid

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

Time to create page: 0.137 seconds
Powered by Kunena Forum