Fix quantity and color wrong on dispatch
authorMaxime Bourget <bmx007@gmail.com>
Tue, 18 Jun 2013 19:43:05 +0000 (20:43 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Tue, 18 Jun 2013 19:43:05 +0000 (20:43 +0100)
hooks.php

index 6922792511118fed2763c6dacb81969830dfba6b..3f146c71448c72ea5e15940d39022d2fa0b0eea7 100644 (file)
--- a/hooks.php
+++ b/hooks.php
@@ -95,10 +95,15 @@ class hooks_order_line_extra extends hooks {
                         * If an order has been selected to be picked up, only the items and the quantity picked up
                         * needs to be available.
                         */
-                       $sql = "SELECT count(*)
-                                                       FROM 0_sales_order_details
+
+               /* We don't only need to check if the detail has been pick but check
+                * that any item in the same order have or not
+                */
+                       $sql = "SELECT *
+                                                       FROM ".TB_PREF."sales_order_details sod
+                                                       JOIN ".TB_PREF."topick p ON (sod.id = p.detail_id)
                                                        WHERE order_no IN (SELECT distinct order_no
-                                                                                                                                       FROM 0_sales_order_details 
+                                                                                                                                       FROM ".TB_PREF."sales_order_details 
                                                                                                                                        WHERE id = $detail_id)";
 
                        $result = db_query($sql);
@@ -107,7 +112,7 @@ class hooks_order_line_extra extends hooks {
                                        $row = db_fetch($result);
                                        if($row) { 
                                                $available = $row['quantity'];
-                                               return array($available, 'picked');
+                                               return array($available, 'picked limited');
                                        }
                                        else {
                                                return array(0, '');
@@ -115,14 +120,14 @@ class hooks_order_line_extra extends hooks {
                
                        }
                        else {
-                               return get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh);
+                               return $this->get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh);
                        }
                }
 
                function get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh) {
                        $sql = "SELECT quantity_before, hold_until_date
                                                        FROM ".TB_PREF."denorm_order_details_queue
-                                                       NATURAL JOIN ".TB_PREF."sales_order_details
+                                                       JOIN ".TB_PREF."sales_order_details USING (id)
                                                        WHERE id = $detail_id";
                        $result = db_query($sql);
                        $quantity_before = 0;
@@ -133,7 +138,7 @@ class hooks_order_line_extra extends hooks {
                                if(OrderXtraConfig::early($hold_until, $date)) return array(0, 'early');
                                }
 
-                       return array(max($qoh - $quantity_before, 0), '');
+                       return array(max($qoh - $quantity_before, 0), 'limited');
                }
 
                function db_postwrite($cart, $trans_type) {