tomatocart / TomatoCart-v1

TomatoCart v1.x respository
http://www.tomatocart.com
Other
22 stars 30 forks source link

address STATE dataflow from AddressBook to Order, not equal #176

Open claude-ws01 opened 10 years ago

claude-ws01 commented 10 years ago

In Admin desktop. From the addressBook to the Order. state_code, zone_id do not follow. In other words, the order is not always getting the correct values. One of the result is that without the zone information, the tax does not get calculated.

I have tried with 3 browsers. same results.

I got stock in the extjs scripts.

DEBUG LOG:

  1. I have place an error_log in /classes/json.php function encode($value) { error_log("encode===>" . $this->json->encode($value),0); return $this->json->encode($value); }
  2. I have put another error_log in /jsons/orders.php function saveAddress() ... error_log('json-orders.php->saveAddress === $_REQUEST["billing_state"]' . $data['billing_state'] . ', [billing_zone_id]'.$_REQUEST['billing_zone_id'] . ', [billing_state_code]'.$_REQUEST['billing_state_code'], 0);

TESTED WITH A FRESH TOMATOCART WEB BASE.

ADDRESS_BOOK_TABLE testing values addr1 - entry_state: TAS addr1 - entry_zone_id: 196 addr2 - entry_state: NS addr2 - entry_zone_id: 620

TESTING SEQUENCE Opening order form, one specific order.

(selecting combo address) LOG encode===>{"records":[{"id":"0","text":"Add New Address"},{"id":1,"text":"firstname1 lastname1,,1234 street1,,City1,A9A9A9,TAS,Australia"},{"id":2,"text":"firstname2 lastname2,,1234 street2,,City2,Z0Z0Z0,NS,Canada"}]}

(choosing new address) LOG encode===>{"records":[{"zone_id":191,"zone_code":"ACT","zone_name":"Australian Capital Territory"},{"zone_id":192,"zone_code":"NSW","zone_name":"New South Wales"},{"zone_id":193,"zone_code":"NT","zone_name":"Northern Territory"},{"zone_id":194,"zone_code":"QLD","zone_name":"Queensland"},{"zone_id":195,"zone_code":"SA","zone_name":"South Australia"},{"zone_id":196,"zone_code":"TAS","zone_name":"Tasmania"},{"zone_id":197,"zone_code":"VIC","zone_name":"Victoria"},{"zone_id":198,"zone_code":"WA","zone_name":"Western Australia"}]}

order form values cboBillingAdresses(state): TAS state field: Tasmania

LOG json-orders.php->saveAddress === $_REQUEST["billing_state"]Tasmania, [billing_zone_id]196, [billing_state_code]TAS (resulting ORDER_TABLE) billing_state: Tasmania billing_zone_id: 196 billing_state_code: TAS # (choosing new address) LOG encode===>{"records":[{"zone_id":615,"zone_code":"AB","zone_name":"Alberta"},{"zone_id":616,"zone_code":"BC","zone_name":"British Columbia"},{"zone_id":617,"zone_code":"MB","zone_name":"Manitoba"},{"zone_id":618,"zone_code":"NB","zone_name":"New Brunswick"},{"zone_id":619,"zone_code":"NL","zone_name":"Newfoundland and Labrador"},{"zone_id":620,"zone_code":"NS","zone_name":"Nova Scotia"},{"zone_id":621,"zone_code":"NT","zone_name":"Northwest Territories"},{"zone_id":622,"zone_code":"NU","zone_name":"Nunavut"},{"zone_id":623,"zone_code":"ON","zone_name":"Ontario"},{"zone_id":624,"zone_code":"PE","zone_name":"Prince Edward Island"},{"zone_id":625,"zone_code":"QC","zone_name":"Quebec"},{"zone_id":626,"zone_code":"SK","zone_name":"Saskatchewan"},{"zone_id":627,"zone_code":"YT","zone_name":"Yukon Territory"}]} order form values cboBillingAdresses: NS state field: NS LOG json-orders.php->saveAddress === $_REQUEST["billing_state"]NS, [billing_zone_id]196, [billing_state_code]null (resulting ORDER_TABLE) billing_state: NS billing_zone_id: 196 <- not updated billing_state_code: null # (selecting state COMBO) LOG encode===>{"records":[{"zone_id":615,"zone_code":"AB","zone_name":"Alberta"},{"zone_id":616,"zone_code":"BC","zone_name":"British Columbia"},{"zone_id":617,"zone_code":"MB","zone_name":"Manitoba"},{"zone_id":618,"zone_code":"NB","zone_name":"New Brunswick"},{"zone_id":619,"zone_code":"NL","zone_name":"Newfoundland and Labrador"},{"zone_id":620,"zone_code":"NS","zone_name":"Nova Scotia"},{"zone_id":621,"zone_code":"NT","zone_name":"Northwest Territories"},{"zone_id":622,"zone_code":"NU","zone_name":"Nunavut"},{"zone_id":623,"zone_code":"ON","zone_name":"Ontario"},{"zone_id":624,"zone_code":"PE","zone_name":"Prince Edward Island"},{"zone_id":625,"zone_code":"QC","zone_name":"Quebec"},{"zone_id":626,"zone_code":"SK","zone_name":"Saskatchewan"},{"zone_id":627,"zone_code":"YT","zone_name":"Yukon Territory"}]} state field: Nova Scotia LOG json-orders.php->saveAddress === $_REQUEST["billing_state"]Nova Scotia, [billing_zone_id]620, [billing_state_code]NS (resulting ORDER_TABLE) billing_state: Nova Scotia billing_zone_id: 620 billing_state_code: NS # # I tested with other countries. Changing in the customer form, then going on an order. Here are some results. FRANCE, Aude cboBillingAdresses: 11 state field: 11 (resulting ORDER_TABLE) billing_state: 11 billing_zone_id: 0 billing_state_code: null # GERMANY, Sachsen address_book_table values addr1 - entry_state: SN addr1 - entry_zone_id: 1223 ORDER FORM cboBillingAdresses: SN state field: SN (resulting ORDER_TABLE) billing_state: SN billing_zone_id: 0 billing_state_code: null # # Further more. On my live system. When there are products in the order, the update button will NOT fire the update. There are no saveAddress call sent to the server. If I delete all the products from the order, then the update will fire a call to the server. Also, for some reason that I have not found, switching database changes the behavior of the Order form, with regards to the billing/shipping addresses. if you got questions... or suggestions. please tell me. thx C.
claude-ws01 commented 10 years ago

FURTHERMORE. I tested with the shipping fields as well (delivery_state, delivery_state_code, delivery_zone_id). same problem.

For the time being I have modified: /admin/includes/classes/customers.php function getAddressBookData()

in query: $Qab = $osC_Database->query('select ab.address_book_id, ab.entry_gender as gender, ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, ab.entry_telephone as telephone_number, ab.entry_fax as fax_number, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where');

CHANGED: ab.entry_state as state FOR z.zone_name as state

...

Still, it does not solve my problem with the button update not firing when products in the order. But at least the tax will get calculated.

thx.

c.

claude-ws01 commented 10 years ago

Sorry I closed the issue by mistake.

I also made correction to:

Because it did not initialize these fields correctly. when adding a new order in admin panel $Qorder->bindValue(':delivery_state', $data['state']); $Qorder->bindValue(':delivery_state_code', $data['state_code']); $Qorder->bindValue(':billing_state', $data['state']); $Qorder->bindValue(':billing_state_code', $data['state_code']);


here's the function.

  function createOrder($data){
      global $osC_Database, $osC_Currencies;
      $error = false;
      $osC_Database->startTransaction();

      $Qcustomer = $osC_Database->query('select c.customers_default_address_id, a.entry_company as company, a.entry_firstname as firstname, a.entry_lastname as lastname, a.entry_street_address as street_address, a.entry_suburb as suburb, a.entry_postcode as postcode, a.entry_city as city, z.zone_name as state, a.entry_state as state_code, a.entry_country_id as country_id, a.entry_zone_id as zone_id, co.countries_name as country, co.countries_iso_code_2 as country_iso2, co.countries_iso_code_3 as country_iso3, co.address_format as address_format from :table_customers c left join :table_address_book a on c.customers_default_address_id = a.address_book_id left join :table_countries co on a.entry_country_id = co.countries_id left join :table_zones z on (a.entry_zone_id = z.zone_id) where c.customers_id = :customers_id');
      $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
      $Qcustomer->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
      $Qcustomer->bindTable(':table_countries', TABLE_COUNTRIES);
      $Qcustomer->bindTable(':table_zones', TABLE_ZONES);
      $Qcustomer->bindInt(':customers_id', $data['customers_id']);
      $Qcustomer->execute();

      $customer_data = $Qcustomer->toArray();
      $data = array_merge($data, $customer_data);

      $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_state_code, customers_country, customers_country_iso2, customers_country_iso3, customers_telephone, customers_email_address, customers_address_format, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_zone_id, delivery_state_code, delivery_country_id, delivery_country, delivery_country_iso2, delivery_country_iso3, delivery_address_format, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_zone_id, billing_state_code, billing_country_id, billing_country, billing_country_iso2, billing_country_iso3, billing_address_format, payment_method, payment_module, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_state_code, :customers_country, :customers_country_iso2, :customers_country_iso3, :customers_telephone, :customers_email_address, :customers_address_format, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_zone_id, :delivery_state_code, :delivery_country_id, :delivery_country, :delivery_country_iso2, :delivery_country_iso3, :delivery_address_format, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_zone_id, :billing_state_code, :billing_country_id, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)');
      $Qorder->bindTable(':table_orders', TABLE_ORDERS);
      $Qorder->bindInt(':customers_id', $data['customers_id']);
      $Qorder->bindValue(':customers_name', $data['customers_name']);
      $Qorder->bindValue(':customers_company', '' /*$order->customer['company']*/);
      $Qorder->bindValue(':customers_street_address', '' /*$order->customer['street_address']*/);
      $Qorder->bindValue(':customers_suburb', '' /*$order->customer['suburb']*/);
      $Qorder->bindValue(':customers_city', '' /*$order->customer['city']*/);
      $Qorder->bindValue(':customers_postcode', '' /*$order->customer['postcode']*/);
      $Qorder->bindValue(':customers_state', '' /*$order->customer['state']*/);
      $Qorder->bindValue(':customers_state_code', '');
      $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);
      $Qorder->bindValue(':customers_country_iso2', '');
      $Qorder->bindValue(':customers_country_iso3', '');
      $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);
      $Qorder->bindValue(':customers_email_address', $data['customers_email_address']);
      $Qorder->bindValue(':customers_address_format', '');
      $Qorder->bindValue(':customers_ip_address', '');
      $Qorder->bindValue(':delivery_name', $data['firstname'] . ',' . $data['lastname']);
      $Qorder->bindValue(':delivery_company', $data['company']);
      $Qorder->bindValue(':delivery_street_address', $data['street_address']);
      $Qorder->bindValue(':delivery_suburb', $data['suburb']);
      $Qorder->bindValue(':delivery_city', $data['city']);
      $Qorder->bindValue(':delivery_postcode', $data['postcode']);
      $Qorder->bindValue(':delivery_state', $data['state']);
      $Qorder->bindValue(':delivery_zone_id', $data['zone_id']);
      $Qorder->bindValue(':delivery_state_code', $data['state_code']);
      $Qorder->bindValue(':delivery_country_id', $data['country_id']);
      $Qorder->bindValue(':delivery_country', $data['country']);
      $Qorder->bindValue(':delivery_country_iso2', $data['country_iso2']);
      $Qorder->bindValue(':delivery_country_iso3', $data['country_iso3']);
      $Qorder->bindValue(':delivery_address_format', $data['address_format']);
      $Qorder->bindValue(':billing_name', $data['firstname'] . ',' . $data['lastname']);
      $Qorder->bindValue(':billing_company', $data['company']);
      $Qorder->bindValue(':billing_street_address', $data['street_address']);
      $Qorder->bindValue(':billing_suburb', $data['suburb']);
      $Qorder->bindValue(':billing_city', $data['city']);
      $Qorder->bindValue(':billing_postcode', $data['postcode']);
      $Qorder->bindValue(':billing_state', $data['state']);
      $Qorder->bindValue(':billing_zone_id', $data['zone_id']);
      $Qorder->bindValue(':billing_state_code', $data['state_code']);
      $Qorder->bindValue(':billing_country_id', $data['country_id']);
      $Qorder->bindValue(':billing_country', $data['country']);
      $Qorder->bindValue(':billing_country_iso2', $data['country_iso2']);
      $Qorder->bindValue(':billing_country_iso3', $data['country_iso3']);
      $Qorder->bindValue(':billing_address_format', $data['address_format']);
      $Qorder->bindValue(':payment_method', '');
      $Qorder->bindValue(':payment_module', '');
      $Qorder->bindInt(':orders_status', 1);
      $Qorder->bindValue(':currency', DEFAULT_CURRENCY);
      $Qorder->bindValue(':currency_value', $osC_Currencies->value(DEFAULT_CURRENCY));
      $Qorder->setLogging($_SESSION['module']);
      $Qorder->execute();

      if ( $osC_Database->isError() ) {
        $error = true;
      } else {
        $orders_id = $osC_Database->nextID();

        $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
        $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
        $Qstatus->bindInt(':orders_id', $orders_id);
        $Qstatus->bindInt(':orders_status_id', DEFAULT_ORDERS_STATUS_ID);
        $Qstatus->bindInt(':customer_notified', '0');
        $Qstatus->bindValue(':comments', '');
        $Qstatus->setLogging($_SESSION['module'], $orders_id);
        $Qstatus->execute();

        if ( $osC_Database->isError() ) {
          $error = true;
        }else{
          $Qtotal = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
          $Qtotal->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
          $Qtotal->bindInt(':orders_id', $orders_id);
          $Qtotal->bindValue(':title', 'Total:');
          $Qtotal->bindValue(':text', $osC_Currencies->format(0));
          $Qtotal->bindValue(':value', '0');
          $Qtotal->bindValue(':class', 'total');
          $Qtotal->bindValue(':sort_order', '100');
          $Qtotal->setLogging($_SESSION['module'], $orders_id);
          $Qtotal->execute();

          if ( $osC_Database->isError() ) {
            $error = true;
          }
        }
      }

      if ( $error === false ) {
        $osC_Database->commitTransaction();

        return $orders_id;
      }

      $osC_Database->rollbackTransaction();

      return false;
    }
  }

hope that helps.

c.

tocjack commented 10 years ago

We will check it.

Thx.