Ejemplo n.º 1
0
 public static function insert()
 {
     $OSCOM_ShoppingCart = Registry::get('ShoppingCart');
     $OSCOM_Customer = Registry::get('Customer');
     $OSCOM_Currencies = Registry::get('Currencies');
     $OSCOM_PDO = Registry::get('PDO');
     $OSCOM_Tax = Registry::get('Tax');
     if (isset($_SESSION['prepOrderID'])) {
         $_prep = explode('-', $_SESSION['prepOrderID']);
         if ($_prep[0] == $OSCOM_ShoppingCart->getCartID()) {
             return $_prep[1];
             // order_id
         } else {
             if (self::getStatusID($_prep[1]) === 4) {
                 self::remove($_prep[1]);
             }
         }
     }
     if ($OSCOM_Customer->isLoggedOn()) {
         $customer_address = AddressBook::getEntry($OSCOM_Customer->getDefaultAddressID());
     } else {
         $customer_address = array('company' => $OSCOM_ShoppingCart->getShippingAddress('company'), 'street_address' => $OSCOM_ShoppingCart->getShippingAddress('street_address'), 'suburb' => $OSCOM_ShoppingCart->getShippingAddress('suburb'), 'city' => $OSCOM_ShoppingCart->getShippingAddress('city'), 'postcode' => $OSCOM_ShoppingCart->getShippingAddress('postcode'), 'state' => $OSCOM_ShoppingCart->getShippingAddress('state'), 'zone_id' => $OSCOM_ShoppingCart->getShippingAddress('zone_id'), 'country_id' => $OSCOM_ShoppingCart->getShippingAddress('country_id'), 'telephone' => $OSCOM_ShoppingCart->getShippingAddress('telephone'));
     }
     $Qorder = $OSCOM_PDO->prepare('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_state_code, 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_state_code, 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_state_code, :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_state_code, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)');
     $Qorder->bindInt(':customers_id', $OSCOM_Customer->getID());
     $Qorder->bindValue(':customers_name', $OSCOM_Customer->getName());
     $Qorder->bindValue(':customers_company', $customer_address['company']);
     $Qorder->bindValue(':customers_street_address', $customer_address['street_address']);
     $Qorder->bindValue(':customers_suburb', $customer_address['suburb']);
     $Qorder->bindValue(':customers_city', $customer_address['city']);
     $Qorder->bindValue(':customers_postcode', $customer_address['postcode']);
     $Qorder->bindValue(':customers_state', $customer_address['state']);
     $Qorder->bindValue(':customers_state_code', Address::getZoneCode($customer_address['zone_id']));
     $Qorder->bindValue(':customers_country', Address::getCountryName($customer_address['country_id']));
     $Qorder->bindValue(':customers_country_iso2', Address::getCountryIsoCode2($customer_address['country_id']));
     $Qorder->bindValue(':customers_country_iso3', Address::getCountryIsoCode3($customer_address['country_id']));
     $Qorder->bindValue(':customers_telephone', $customer_address['telephone']);
     $Qorder->bindValue(':customers_email_address', $OSCOM_Customer->getEmailAddress());
     $Qorder->bindValue(':customers_address_format', Address::getFormat($customer_address['country_id']));
     $Qorder->bindValue(':customers_ip_address', OSCOM::getIPAddress());
     $Qorder->bindValue(':delivery_name', $OSCOM_ShoppingCart->getShippingAddress('firstname') . ' ' . $OSCOM_ShoppingCart->getShippingAddress('lastname'));
     $Qorder->bindValue(':delivery_company', $OSCOM_ShoppingCart->getShippingAddress('company'));
     $Qorder->bindValue(':delivery_street_address', $OSCOM_ShoppingCart->getShippingAddress('street_address'));
     $Qorder->bindValue(':delivery_suburb', $OSCOM_ShoppingCart->getShippingAddress('suburb'));
     $Qorder->bindValue(':delivery_city', $OSCOM_ShoppingCart->getShippingAddress('city'));
     $Qorder->bindValue(':delivery_postcode', $OSCOM_ShoppingCart->getShippingAddress('postcode'));
     $Qorder->bindValue(':delivery_state', $OSCOM_ShoppingCart->getShippingAddress('state'));
     $Qorder->bindValue(':delivery_state_code', $OSCOM_ShoppingCart->getShippingAddress('zone_code'));
     $Qorder->bindValue(':delivery_country', $OSCOM_ShoppingCart->getShippingAddress('country_title'));
     $Qorder->bindValue(':delivery_country_iso2', $OSCOM_ShoppingCart->getShippingAddress('country_iso_code_2'));
     $Qorder->bindValue(':delivery_country_iso3', $OSCOM_ShoppingCart->getShippingAddress('country_iso_code_3'));
     $Qorder->bindValue(':delivery_address_format', $OSCOM_ShoppingCart->getShippingAddress('format'));
     $Qorder->bindValue(':billing_name', $OSCOM_ShoppingCart->getBillingAddress('firstname') . ' ' . $OSCOM_ShoppingCart->getBillingAddress('lastname'));
     $Qorder->bindValue(':billing_company', $OSCOM_ShoppingCart->getBillingAddress('company'));
     $Qorder->bindValue(':billing_street_address', $OSCOM_ShoppingCart->getBillingAddress('street_address'));
     $Qorder->bindValue(':billing_suburb', $OSCOM_ShoppingCart->getBillingAddress('suburb'));
     $Qorder->bindValue(':billing_city', $OSCOM_ShoppingCart->getBillingAddress('city'));
     $Qorder->bindValue(':billing_postcode', $OSCOM_ShoppingCart->getBillingAddress('postcode'));
     $Qorder->bindValue(':billing_state', $OSCOM_ShoppingCart->getBillingAddress('state'));
     $Qorder->bindValue(':billing_state_code', $OSCOM_ShoppingCart->getBillingAddress('zone_code'));
     $Qorder->bindValue(':billing_country', $OSCOM_ShoppingCart->getBillingAddress('country_title'));
     $Qorder->bindValue(':billing_country_iso2', $OSCOM_ShoppingCart->getBillingAddress('country_iso_code_2'));
     $Qorder->bindValue(':billing_country_iso3', $OSCOM_ShoppingCart->getBillingAddress('country_iso_code_3'));
     $Qorder->bindValue(':billing_address_format', $OSCOM_ShoppingCart->getBillingAddress('format'));
     $Qorder->bindValue(':payment_method', $OSCOM_ShoppingCart->getBillingMethod('title'));
     // HPDL verify payment module class
     $Qorder->bindValue(':payment_module', $OSCOM_ShoppingCart->getBillingMethod('id'));
     $Qorder->bindInt(':orders_status', 4);
     // HPDL move currencies to the products level
     $Qorder->bindValue(':currency', $OSCOM_Currencies->getCode());
     $Qorder->bindValue(':currency_value', $OSCOM_Currencies->value($OSCOM_Currencies->getCode()));
     $Qorder->execute();
     $insert_id = $OSCOM_PDO->lastInsertId();
     foreach ($OSCOM_ShoppingCart->getOrderTotals() as $module) {
         $Qtotals = $OSCOM_PDO->prepare('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
         $Qtotals->bindInt(':orders_id', $insert_id);
         $Qtotals->bindValue(':title', $module['title']);
         $Qtotals->bindValue(':text', $module['text']);
         $Qtotals->bindValue(':value', $module['value']);
         $Qtotals->bindValue(':class', $module['code']);
         $Qtotals->bindInt(':sort_order', $module['sort_order']);
         $Qtotals->execute();
     }
     $Qstatus = $OSCOM_PDO->prepare('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->bindInt(':orders_id', $insert_id);
     $Qstatus->bindInt(':orders_status_id', 4);
     $Qstatus->bindInt(':customer_notified', '0');
     $Qstatus->bindValue(':comments', isset($_SESSION['comments']) ? $_SESSION['comments'] : '');
     $Qstatus->execute();
     foreach ($OSCOM_ShoppingCart->getProducts() as $products) {
         $Qproducts = $OSCOM_PDO->prepare('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :products_tax, :products_quantity)');
         $Qproducts->bindInt(':orders_id', $insert_id);
         $Qproducts->bindInt(':products_id', Products::getProductID($products['id']));
         $Qproducts->bindValue(':products_model', $products['model']);
         $Qproducts->bindValue(':products_name', $products['name']);
         $Qproducts->bindValue(':products_price', $products['price']);
         $Qproducts->bindValue(':products_tax', $OSCOM_Tax->getTaxRate($products['tax_class_id']));
         $Qproducts->bindInt(':products_quantity', $products['quantity']);
         $Qproducts->execute();
         $order_products_id = $OSCOM_PDO->lastInsertId();
         if ($OSCOM_ShoppingCart->isVariant($products['item_id'])) {
             foreach ($OSCOM_ShoppingCart->getVariant($products['item_id']) as $variant) {
                 /* HPDL
                             if (DOWNLOAD_ENABLED == '1') {
                               $Qattributes = $OSCOM_PDO->prepare('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
                               $Qattributes->bindInt(':products_id', $products['id']);
                               $Qattributes->bindInt(':options_id', $attributes['options_id']);
                               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
                               $Qattributes->bindInt(':popt_language_id', $OSCOM_Language->getID());
                               $Qattributes->bindInt(':poval_language_id', $OSCOM_Language->getID());
                               $Qattributes->execute();
                             }
                 */
                 $Qvariant = $OSCOM_PDO->prepare('insert into :table_orders_products_variants (orders_id, orders_products_id, group_title, value_title) values (:orders_id, :orders_products_id, :group_title, :value_title)');
                 $Qvariant->bindInt(':orders_id', $insert_id);
                 $Qvariant->bindInt(':orders_products_id', $order_products_id);
                 $Qvariant->bindValue(':group_title', $variant['group_title']);
                 $Qvariant->bindValue(':value_title', $variant['value_title']);
                 $Qvariant->execute();
                 /*HPDL
                             if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {
                               $Qopd = $OSCOM_PDO->prepare('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');
                               $Qopd->bindInt(':orders_id', $insert_id);
                               $Qopd->bindInt(':orders_products_id', $order_products_id);
                               $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
                               $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
                               $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
                               $Qopd->execute();
                             }
                 */
             }
         }
     }
     $_SESSION['prepOrderID'] = $OSCOM_ShoppingCart->getCartID() . '-' . $insert_id;
     return $insert_id;
 }
Ejemplo n.º 2
0
 public function setBillingAddress($address)
 {
     $OSCOM_Customer = Registry::get('Customer');
     $OSCOM_PDO = Registry::get('PDO');
     $previous_address = false;
     if (isset($this->_billing_address['id'])) {
         $previous_address = $this->getBillingAddress();
     }
     if ($OSCOM_Customer->isLoggedOn() && is_numeric($address)) {
         $Qaddress = $OSCOM_PDO->prepare('select ab.*, z.zone_code, z.zone_name, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');
         $Qaddress->bindInt(':customers_id', $OSCOM_Customer->getID());
         $Qaddress->bindInt(':address_book_id', $address);
         $Qaddress->execute();
         if ($Qaddress->fetch() !== false) {
             $this->_billing_address = array('id' => (int) $address, 'firstname' => $Qaddress->valueProtected('entry_firstname'), 'lastname' => $Qaddress->valueProtected('entry_lastname'), 'gender' => $Qaddress->valueProtected('entry_gender'), 'company' => $Qaddress->valueProtected('entry_company'), 'street_address' => $Qaddress->valueProtected('entry_street_address'), 'suburb' => $Qaddress->valueProtected('entry_suburb'), 'city' => $Qaddress->valueProtected('entry_city'), 'postcode' => $Qaddress->valueProtected('entry_postcode'), 'state' => strlen($Qaddress->valueProtected('entry_state')) > 0 ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'), 'zone_id' => $Qaddress->valueInt('entry_zone_id'), 'zone_code' => $Qaddress->value('zone_code'), 'country_id' => $Qaddress->valueInt('entry_country_id'), 'country_title' => $Qaddress->valueProtected('countries_name'), 'country_iso_code_2' => $Qaddress->valueProtected('countries_iso_code_2'), 'country_iso_code_3' => $Qaddress->valueProtected('countries_iso_code_3'), 'format' => $Qaddress->value('address_format'), 'telephone' => $Qaddress->valueProtected('entry_telephone'), 'fax' => $Qaddress->valueProtected('entry_fax'));
         }
     } else {
         $this->_billing_address = array('id' => 0, 'firstname' => HTML::outputProtected($address['firstname']), 'lastname' => HTML::outputProtected($address['lastname']), 'gender' => HTML::outputProtected($address['gender']), 'company' => HTML::outputProtected($address['company']), 'street_address' => HTML::outputProtected($address['street_address']), 'suburb' => HTML::outputProtected($address['suburb']), 'city' => HTML::outputProtected($address['city']), 'postcode' => HTML::outputProtected($address['postcode']), 'state' => isset($address['state']) && !empty($address['state']) ? HTML::outputProtected($address['state']) : HTML::outputProtected(Address::getZoneName($address['zone_id'])), 'zone_id' => (int) $address['zone_id'], 'zone_code' => HTML::outputProtected(Address::getZoneCode($address['zone_id'])), 'country_id' => HTML::outputProtected($address['country_id']), 'country_title' => HTML::outputProtected(Address::getCountryName($address['country_id'])), 'country_iso_code_2' => HTML::outputProtected(Address::getCountryIsoCode2($address['country_id'])), 'country_iso_code_3' => HTML::outputProtected(Address::getCountryIsoCode3($address['country_id'])), 'format' => Address::getFormat($address['country_id']), 'telephone' => HTML::outputProtected($address['telephone']), 'fax' => HTML::outputProtected($address['fax']));
     }
     if (is_array($previous_address) && ($previous_address['id'] != $this->_billing_address['id'] || $previous_address['country_id'] != $this->_billing_address['country_id'] || $previous_address['zone_id'] != $this->_billing_address['zone_id'] || $previous_address['state'] != $this->_billing_address['state'] || $previous_address['postcode'] != $this->_billing_address['postcode'])) {
         $this->_calculate();
     }
 }