Solve the huge data output problem from the Carrier::getDeliveryPriceByRanges function (Prestashop)
Inside the Carrier::getDeliveryPriceByRanges function there are join processes between ps_range_weight table and ps_delivery table. If the ps_delivery table and ps_range_weight table have large amounts of data, the results of the join will produce an enormous data. This will cause the process stalled for some servers and we can not set the "Fees by carrier, geographical zone, and ranges".
To fix this, I modified the file: /admin/tabs/AdminShipping.php as follows:
This line:
$Delivery = Carrier::getDeliveryPriceByRanges($rangeTable);
I change to:
$Delivery = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
After that I modified the file: /classes/Carrier.php as follows:
The function:
public static function getDeliveryPriceByRanges($rangeTable)
{
$rangeTable = pSQL($rangeTable);
return Db::getInstance()->ExecuteS('
SELECT d.`id_'.$rangeTable.'`, d.`id_carrier`, d.`id_zone`, d.`price`
FROM `'._DB_PREFIX_.'delivery` d
LEFT JOIN `'._DB_PREFIX_.$rangeTable.'` r ON r.`id_'.$rangeTable.'` = d.`id_'.$rangeTable.'`
WHERE (d.`id_'.$rangeTable.'` IS NOT NULL AND d.`id_'.$rangeTable.'` != 0)
ORDER BY r.`delimiter1` ASC');
}
I change to:
public static function getDeliveryPriceByRanges($rangeTable, $id_carrier)
{
$rangeTable = pSQL($rangeTable);
return Db::getInstance()->ExecuteS('
SELECT d.`id_'.$rangeTable.'`, d.`id_carrier`, d.`id_zone`, d.`price`
FROM `'._DB_PREFIX_.'delivery` d
LEFT JOIN `'._DB_PREFIX_.$rangeTable.'` r ON r.`id_'.$rangeTable.'` = d.`id_'.$rangeTable.'`
WHERE (d.`id_'.$rangeTable.'` IS NOT NULL AND d.`id_'.$rangeTable.'` != 0 AND d.`id_carrier` = '.$id_carrier.')
ORDER BY r.`delimiter1` ASC');
}
Please Prestashop team to check this.
Feedback awaiting moderation
This post has 360 feedbacks awaiting moderation...