UPS Shipping Options Not Sorted by Price

  • Posts: 32
  • Thank you received: 1
8 years 11 months ago #224010

-- url of the page with the problem -- : www.nicaboyne.com
-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.4.44
-- Browser(s) name and version -- : Chrome OSX
-- Error-message(debug-mod must be tuned on) -- : N/A

Hi All,

Our UPS shipping plugin is working largely as expected. However, I notice that if the customer doesn't quality for free shipping (orders > $49), the default option for UPS is Next-Day Air.

That's a very expensive shipping option and may dissuade customers from completing their order. Why is the plugin not defaulting to the cheapest option?

I am looking to the Checkout view and notice the version my client's site is using is customized (not by me). Is this where the ordering would be done and do you have a recommendation for where in 2.6.0 the shipping method details would be ordered?

Thanks!

Last edit: 8 years 11 months ago by killnine.

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

  • Posts: 12953
  • Thank you received: 1778
8 years 11 months ago #224113

Hello,
In your case you'll just have to order the cheapest shipping method before our UPS shipping method via "Hikashop->System->Shipping methods". Can you do it and test it again ?
Thanks

Last edit: 8 years 11 months ago by Mohamed Thelji.

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

  • Posts: 32
  • Thank you received: 1
8 years 11 months ago #224164

Thanks Mohamed, but within a specific shipping method (e.g. UPS) is there a way to make sure the list of methods are sorted by lowest-> highest? Or, that the default shipping method is whichever method is cheapest?

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

  • Posts: 12953
  • Thank you received: 1778
8 years 11 months ago #224209

Hello,
There is no "Sort by shipping price" option on the UPS, so the only method will be to directly edit the code of the UPS shipping plugin to add it (ups.php) like the USPS shipping method.

The following user(s) said Thank You: killnine

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

  • Posts: 32
  • Thank you received: 1
8 years 11 months ago #224543

@Mohamed: I added

array_sort()
to UPS.php and had it sort at the end of the
onShippingDisplay
. Is that where you'd expect this to get called?

I have "Auto select default shipping and payment methods" set, which means even at the first step of checkout it tries to calculate shipping. Does the plugin use onShippingDisplay at all for this? I'm not sure how it calls my shipping methods (I use a custom shipping method that provides free shipping for >$49 orders, and UPS) get called in this step.

I'm hoping I can write this in a way that it might be integrated into UPS plugin permanently.

p.s. - why is there two copies of ups.php? One in /administrator/components/com_hikashop/extensions/plg_hikashopshipping_ups/ and another in plugins/hikashopshipping/ups/?

Last edit: 8 years 11 months ago by killnine.

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

  • Posts: 12953
  • Thank you received: 1778
8 years 11 months ago #224585

Hello,
The solution will be to sort the "$new_usable_rates" variable just before these lines through the onShippingDisplay function :

foreach($new_usable_rates as $i => $usable_rate) {
	if(isset($usable_rate->shipping_price_orig) || isset($usable_rate->shipping_currency_id_orig)){
		if($usable_rate->shipping_currency_id_orig == $usable_rate->shipping_currency_id)
			$usable_rate->shipping_price_orig = $usable_rate->shipping_price;
		else
			$usable_rate->shipping_price_orig = $currencyClass->convertUniquePrice($usable_rate->shipping_price, $usable_rate->shipping_currency_id, $usable_rate->shipping_currency_id_orig);
	}
	$usable_rates[$usable_rate->shipping_id] = $usable_rate;
	$cache_usable_rates[$usable_rate->shipping_id] = $usable_rate;
}

p.s. - why is there two copies of ups.php? One in /administrator/components/com_hikashop/extensions/plg_hikashopshipping_ups/ and another in plugins/hikashopshipping/ups/?

The one you want to use is plugins/hikashopshipping/ups/

Last edit: 8 years 11 months ago by Mohamed Thelji.

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #231625

Is this is the plugins/hikashopshipping/ups/ version of the ups.php file?

Also, what would be the code needed to sort by price?

When I view the $new_usable_rates array they are actually in the proper order, but for some reason it picks "UPS Next Day" as the default. Probably because it is the first listed in the [methods] array within the shipping_params ?

Last edit: 8 years 8 months ago by p3.chuck. Reason: fixed not display the array

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

  • Posts: 12953
  • Thank you received: 1778
8 years 8 months ago #231693

Hi,

The ups.php file is the same for both locations.
But the one in plugins/hikashopshipping/ups/ is the one that is used.

Note that the data is cached. So you'll get your debug only the first time the rates are fetched.
After that, you need to change the cart (add another product, change the quantity, etc) if you want the rates to be fetched again and thus get your debug to be displayed.

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #231892

I found the caching issue. But I've still been unable get the sorting done. I need to sort this so the cheapest price is selected and so they display in order of price.

Could you please provide the sample code to accomplish this?

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

  • Posts: 12953
  • Thank you received: 1778
8 years 8 months ago #231983

Hello,

1.

When I view the $new_usable_rates array they are actually in the proper order, but for some reason it picks "UPS Next Day" as the default. Probably because it is the first listed in the [methods] array within the shipping_params ?

I just tested it myself and you were right, the shipping services were sorted after the onShippingDisplay call, so to prevent it you should edit the "administrator\components\com_hikashop\classes\shipping.php" file and change that line :
uasort($usable_methods, array($this, "sortShipping"));
By :
//uasort($usable_methods, array($this, "sortShipping"));
2.
To accomplish what you want you'll need to add these lines :
function array_sort($array, $on, $type, $order = SORT_ASC){
	if(empty($array))
		return array();

	$new_array = array();
	$sortable_array = array();
	foreach ($array as $key => $value) {
		if($value->shipping_type == $type)
			$sortable_array[$key] = $value->shipping_price;
	}

	switch ($order) {
		case SORT_ASC:
			asort($sortable_array);
		break;
		case SORT_DESC:
			arsort($sortable_array);
		break;
	}

	foreach ($sortable_array as $k => $v) {
		$new_array[$k] = $array[$k];
	}
	return $new_array;
}
Just after these lines :
	curl_close($session);
}
And to add this line :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_DESC);
Just before these lines :
foreach($new_usable_rates as $i => $usable_rate) {
	if(isset($usable_rate->shipping_price_orig) || isset($usable_rate->shipping_currency_id_orig)){
		if($usable_rate->shipping_currency_id_orig == $usable_rate->shipping_currency_id)
			$usable_rate->shipping_price_orig = $usable_rate->shipping_price;
		else
			$usable_rate->shipping_price_orig = $currencyClass->convertUniquePrice($usable_rate->shipping_price, $usable_rate->shipping_currency_id, $usable_rate->shipping_currency_id_orig);
	}
	$usable_rates[$usable_rate->shipping_id] = $usable_rate;
	$cache_usable_rates[$usable_rate->shipping_id] = $usable_rate;
}
Note that you can change that line :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_DESC);
To :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_ASC);
If you want your shipping services to be sorted from the lower to the highest shipping price.

Last edit: 8 years 8 months ago by Mohamed Thelji.

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232395

Everything is working properly except I'm getting an error:

Warning: usort() expects parameter 2 to be a valid callback, class 'plgHikashopshippingUPS' does not have a method 'cmp' in .../plugins/hikashopshipping/ups/ups.php on line 224. Line 224 is the usort line exactly as you instructed.

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

  • Posts: 12953
  • Thank you received: 1778
8 years 8 months ago #232445

Hello,
Can you test it with that shipping plugin ? I don't have any error message with it.

Attachments:
Last edit: 8 years 8 months ago by Mohamed Thelji.

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232492

Thanks.. that resolves the issue. Maybe I had some old code in there from trying to fix this issue previously.

Also, if I try to delete an item from the shopping cart - i get the following error:
Fatal error: Call to a member function get() on a non-object in F:\wamp\www\site3\administrator\components\com_hikashop\helpers\module.php on line 207

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232529

This seems to only happen when removing the last item in the cart. If that helps any.

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

  • Posts: 12953
  • Thank you received: 1778
8 years 8 months ago #232569

Hello,

Did you get that error message after using the custom UPS shipping plugin that I gave you ? I'll need a temporary FTP and Back-end access that you can send us through the contact form :
www.hikashop.com/support/contact-us.html

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232633

Credentials sent via your link. They're under Charles Wilkins.

That error still exists using the plugin version you sent. You can test it by:

  1. go to the website: www.p3proswing.com/site3
  2. Under Shop all Products, select Accessories
  3. Click 'Add to Cart' on the Foam Golf Balls
  4. Click 'Proceed to checkout'
  5. Scroll to bottom
  6. Click the 'X' under Quantity
  7. VOILA - Error !!

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

  • Posts: 12953
  • Thank you received: 1778
8 years 8 months ago #232646

Hello,
We just added a fix regarding that issue, so can you download the last Hikashop version through our website, install it and test it again ?
Thanks for your feedback.

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

  • Posts: 14
  • Thank you received: 2
8 years 8 months ago #232759

Yup, that resolved that error but created a new one. It now tells me that The UPS Plugin needs the CURL library... But I have the php curl extension installed. See the attached screenshot.

Attachments:

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232760

Sorry about the different login. I was logged in under our company account. SVT = p3.chuck

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

  • Posts: 104
  • Thank you received: 5
8 years 8 months ago #232764

Disregard. I found the issue. The curl extension was on for php, but not Apache. Once I started it for Apache, the error went away. Ironically - it wasn't an issue before the update though.

The following user(s) said Thank You: Mohamed Thelji

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

Time to create page: 0.134 seconds
Powered by Kunena Forum