d1m007 / gshoppingflux

PrestaShop Google Shopping Flux Module
100 stars 61 forks source link

Shipping cost not calculated correctly #111

Open schimkat opened 1 year ago

schimkat commented 1 year ago

There seems to be a problem with calculating shipping costs, based on product weight. Shipping based on product price seems to be correct. In this Sample output file shipping costs should be calculated like this:

Product weight <= 0.035 Kg = 19 DKK shipping cost .. otherwise 39 DKK shipping cost Product price >= 500 DKK = 0 DKK shipping cost

.. but it would seem that to many products are having the 19 DKK shipping, while it should be 39 DKK shipping as the product weighs more than 0.035 Kg

schimkat commented 1 year ago

I think I've found the problem. The problem is that even trough a carrier is configured with intervals for product price - then it may still be limited by overall size and weight - resulting in the carrier becoming invalid for a specific product (even if within price range). I think that this check could be missing, hence the issue.

CarrierIssue

(I'm using 1.7.2 - as the newer versions did set all shipping fee's to 0 DKK)

schimkat commented 1 year ago

Just did a quick and dirty - a cron job for fixing the output:

<?

$Flux = simplexml_load_file('/.../_JenTronicProducts_googleshopping-s1-da-DKK.xml');

if ($Flux === FALSE) {
    echo "There were errors parsing the XML file.\n";
    foreach(libxml_get_errors() as $error) {
        echo $error->message;
    }
    exit;
}

foreach ($Flux->channel->item as $item) {

    # $Title = $item->title;
    # $Price = preg_replace('/[^\d]/', '', $item->children('g', true)->price);
    $Weight = preg_replace('/[^\d\.]/', '',$item->children('g', true)->shipping_weight); 
    $Shipping = preg_replace('/[^\d]/', '',$item->children('g', true)->shipping->children('g', true)->price);

    if ($Shipping == '19' && $Weight > 0.035) {

       # print $Title . "\n";
       # print "   Price: " . $Price . " / Weight: " . $Weight . " / Shipping: " . $Shipping .  "\n";

       $item->children('g', true)->shipping->children('g', true)->price = '39 DKK';
       $item->children('g', true)->shipping->children('g', true)->service = '1-2 dage';

    }

    $Flux->asXML ('/.../JenTronicProducts_googleshopping-s1-da-DKK.xml');

}

?>