Probably Coding Mistake Of The official Package

29.03.2014 07:49
#1
atlantik
Joomshopping forum user no avatar
Name: Jack
18.02.2014
Posts: 7
Quote
Probably Coding Mistake Of The official Package

Hello, i'm not sure if it's suitable to write technical problems here.
As i looked into the jshopping code version 3.16.2 , i realize there are probably coding mistakes.
I want to add a new shipping method, namely ups or usps.

What i have in the table #__jshopping_shipping_ext_calc:

+----+----------------+--------------------+----------------+--------+-----------------+-----------+----------+
| id | name | alias | description | params | shipping_method | published | ordering |
+----+----------------+--------------------+----------------+--------+-----------------+-----------+----------+
| 1 | StandartWeight | sm_standart_weight | StandartWeight | | | 1 | 1 |
| 2 | usps | usps | usps | | | 1 | 2 |
| 3 | Standard | standard | standard | | | 1 | 3 |
+----+----------------+--------------------+----------------+--------+-----------------+-----------+----------+

Code block:
File: components/com_jshopping/tables/shippingmethodprice.php
function calculateSum(&$cart){
$jshopConfig = JSFactory::getConfig();
if ($this->getGlobalConfigPriceNull($cart)){
return 0;
}

$price = $this->shipping_stand_price;
$package = $this->package_stand_price;
$prices = array('shipping'=>$price,'package'=>$package);

$extensions = JSFactory::getShippingExtList($this->shipping_method_id);

foreach($extensions as $extension){
if (isset($extension->exec->version) && $extension->exec->version==2){
$prices = $extension->exec->getPrices($cart, $this->getParams(), $prices, $extension, $this);
} else {
$price = $extension->exec->getPrice($cart, $this->getParams(), $price, $extension, $this);
$prices = array('shipping'=>$price,'package'=>$package);
}
}

The code block calling the above code is below:
File:com_jshopping/controolers/checkout.php Function step4

$shippings = $shippingmethod->getAllShippingMethodsCountry($id_country, $payment_id);
foreach($shippings as $key=>$value){
$shippingmethodprice->load($value->sh_pr_method_id);
if ($jshopConfig->show_list_price_shipping_weight){
$shippings[$key]->shipping_price = $shippingmethodprice->getPricesWeight($value->sh_pr_method_id, $id_country, $cart);
}

$prices = $shippingmethodprice->calculateSum($cart);

==============Bugs??? ==============

foreach($extensions as $extension){ in function calculateSum always results in the last shipping method's values, in this example it its 'Standard' shipping method, so what's the point of this function? I get all the same shipping rates in frontend for these 3 shipping methods


Joomla: 2.5
JoomShopping: 3.16.2
PHP: 5.2
MySQL: 5.1.44
Website Url: local test site

Letzte Änderung: 29.03.2014 07:52
 
03.04.2014 10:35
#2
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25857
Quote
Aw: Probably Coding Mistake Of The official Package

Not see error in coding.

$prices = $extension->exec->getPrices($cart, $this->getParams(), $prices, $extension, $this);

always different
$this->getParams()
$prices
$this


Letzte Änderung: 03.04.2014 10:37
 
04.04.2014 16:38
#3
atlantik
Joomshopping forum user no avatar
Name: Jack
18.02.2014
Posts: 7
Quote
Aw: Probably Coding Mistake Of The official Package

HI,there won't be error if i'm not going to develop a usps plugin based on usps api, which means the rate is not based on the standard weight ranges. So i have to write custom code in com_jshopping/shippings/usps/usps.php getPrices
You say the exec->getPrices's params are always different, but the outter foreach loop will always result in the last extension's getPrices return value, why it's designed like this?

foreach($extensions as $extension){
if (isset($extension->exec->version) && $extension->exec->version==2){
$prices = $extension->exec->getPrices($cart, $this->getParams(), $prices, $extension, $this);
} else {
$price = $extension->exec->getPrice($cart, $this->getParams(), $price, $extension, $this);
$prices = array('shipping'=>$price,'package'=>$package);
}
}

Standard content of function getPrices is

function getPrices($cart, $params, $prices, &$shipping_ext_row, &$shipping_method_price){
$weight_sum = $cart->getWeightProducts();
$sh_price = $shipping_method_price->getPrices("desc");

foreach($sh_price as $sh_pr){
if ($weight_sum >= $sh_pr->shipping_weight_from && ($weight_sum <= $sh_pr->shipping_weight_to || $sh_pr->shipping_weight_to==0)) {
$prices['shipping'] = $sh_pr->shipping_price;
$prices['package'] = $sh_pr->shipping_package_price;
break;
}
}
return $prices;
}

Usually $sh_price is always empty array, i reckon the foreach problem haven't been spotted just because of this?

 
04.04.2014 20:27
#4
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25857
Quote
Aw: Probably Coding Mistake Of The official Package

.../administrator/index.php?option=com_jshopping&controller=shippingextprice

Configuration

Set Shippings ..

 
08.04.2014 08:40
#5
atlantik
Joomshopping forum user no avatar
Name: Jack
18.02.2014
Posts: 7
Quote
Aw: Probably Coding Mistake Of The official Package

Hi, so ups or usps are impossible to implement, cuz the shipping system always relies on the rates based on weight ranges manually inputted ?

 
08.04.2014 21:12
#6
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25857
Quote
Aw: Probably Coding Mistake Of The official Package

I do not understand where the problem.

 


Copyrights MAXXmarketing GmbH. Alle Rechte vorbehalten
Durch die Nutzung dieser Website stimme ich zu, dass Cookies zur optimalen Gestaltung der Website sowie zur Analyse der Nutzung der Website verwendet werden. Weiterführende Informationen finden Sie hier. OK, einverstanden.