示例#1
0
 public function getTotal(&$total_data, &$total, &$taxes)
 {
     if (isset($this->session->data['coupon']) && $this->config->get('coupon_status')) {
         $promotion = new APromotion();
         $coupon = $promotion->getCouponData($this->session->data['coupon']);
         if ($coupon) {
             $discount_total = 0;
             if (!$coupon['product']) {
                 $coupon_total = $this->cart->getSubTotal();
             } else {
                 $coupon_total = 0;
                 foreach ($this->cart->getProducts() as $product) {
                     if (in_array($product['product_id'], $coupon['product'])) {
                         $coupon_total += $product['total'];
                     }
                 }
             }
             if ($coupon['type'] == 'F') {
                 $coupon['discount'] = min($coupon['discount'], $coupon_total);
             }
             foreach ($this->cart->getProducts() as $product) {
                 $discount = 0;
                 if (!$coupon['product']) {
                     $status = TRUE;
                 } else {
                     if (in_array($product['product_id'], $coupon['product'])) {
                         $status = TRUE;
                     } else {
                         $status = FALSE;
                     }
                 }
                 if ($status) {
                     if ($coupon['type'] == 'F') {
                         $discount = $coupon['discount'] * ($product['total'] / $coupon_total);
                     } elseif ($coupon['type'] == 'P') {
                         $discount = $product['total'] / 100 * $coupon['discount'];
                     }
                     if ($product['tax_class_id']) {
                         $taxes[$product['tax_class_id']]['total'] -= $discount;
                         $taxes[$product['tax_class_id']]['tax'] -= $this->tax->calcTotalTaxAmount($product['total'], $product['tax_class_id']) - $this->tax->calcTotalTaxAmount($product['total'] - $discount, $product['tax_class_id']);
                     }
                 }
                 $discount_total += $discount;
             }
             $ship_data = $this->session->data['shipping_method'];
             if ($coupon['shipping'] && isset($ship_data)) {
                 if (isset($ship_data['tax_class_id']) && $ship_data['tax_class_id']) {
                     $taxes[$ship_data['tax_class_id']]['total'] -= $ship_data['cost'];
                     $taxes[$ship_data['tax_class_id']]['tax'] -= $this->tax->calcTotalTaxAmount($ship_data['cost'], $ship_data['tax_class_id']);
                 }
                 $discount_total += $ship_data['cost'];
             }
             $total_data[] = array('id' => 'coupon', 'title' => $coupon['name'] . ':', 'text' => '-' . $this->currency->format($discount_total), 'value' => -$discount_total, 'sort_order' => $this->config->get('coupon_sort_order'), 'total_type' => $this->config->get('coupon_total_type'));
             $total -= $discount_total;
         }
     }
 }
示例#2
0
 private function _validateCoupon()
 {
     $this->loadLanguage('checkout/payment');
     $promotion = new APromotion();
     $coupon = $promotion->getCouponData($this->request->post['coupon']);
     if (!$coupon) {
         $this->error['warning'] = $this->language->get('error_coupon');
     }
     $this->extensions->hk_ValidateData($this);
     if (!$this->error) {
         return true;
     } else {
         return false;
     }
 }
 public function onControllerPagesCheckoutGuestStep2_InitData()
 {
     $error = false;
     $that = $this->baseObject;
     if (isset($that->request->post['shipping_method'])) {
         $shipping = explode('.', $that->request->post['shipping_method']);
         $that->session->data['shipping_method'] = $that->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
     }
     if ($that->request->get['mode'] == 'edit') {
         unset($that->session->data['pp_express_checkout']);
     }
     // if coupon code was submited
     if (has_value($that->request->post['coupon'])) {
         $promotion = new APromotion();
         $coupon = $promotion->getCouponData($that->request->post['coupon']);
         // rebuild order data if coupon applied
         $order = new AOrder(Registry::getInstance());
         $this->data = $order->buildOrderData($that->session->data);
         $order->saveOrder();
         if ($coupon) {
             $that->session->data['coupon'] = $that->request->post['coupon'];
         } else {
             $error = true;
         }
     }
     if (!$error && $that->request->server['REQUEST_METHOD'] == 'POST' && ($that->request->post['payment_method'] == 'default_pp_express' || $that->session->data['payment_method']['id'] == 'default_pp_express')) {
         if (!has_value($that->session->data['pp_express_checkout']['token']) || !has_value($that->session->data['pp_express_checkout']['PayerID'])) {
             // rebuild order data if coupon applied
             $order = new AOrder(Registry::getInstance());
             $this->data = $order->buildOrderData($that->session->data);
             $order->saveOrder();
             $redirect_url = $that->html->getSecureURL('checkout/guest_step_3');
             header('Location: ' . $that->html->getSecureURL('r/extension/default_pp_express/set_pp', '&to_confirm=1&redirect_to=' . urlencode($redirect_url)));
             exit;
         }
     }
 }
 private function _validateCoupon($coupon)
 {
     $promotion = new APromotion();
     $coupon = $promotion->getCouponData($coupon);
     if (!$coupon) {
         $this->error['warning'] = $this->language->get('error_coupon');
     }
     if (!$this->error) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
示例#5
0
 /**
  * @param array $indata : Session data array
  * @return array 
  * NOTE: method to create an order based on provided data array. 
  */
 public function buildOrderData($indata)
 {
     $order_info = array();
     if (empty($indata)) {
         return array();
     }
     $total_data = array();
     $total = 0;
     $taxes = $this->cart->getTaxes();
     $this->load->model('checkout/extension');
     $sort_order = array();
     $results = $this->model_checkout_extension->getExtensions('total');
     foreach ($results as $key => $value) {
         $sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
     }
     array_multisort($sort_order, SORT_ASC, $results);
     foreach ($results as $result) {
         $this->load->model('total/' . $result['key']);
         $this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes, $indata);
     }
     $sort_order = array();
     foreach ($total_data as $key => $value) {
         $sort_order[$key] = $value['sort_order'];
     }
     array_multisort($sort_order, SORT_ASC, $total_data);
     $order_info['store_id'] = $this->config->get('config_store_id');
     $order_info['store_name'] = $this->config->get('store_name');
     $order_info['store_url'] = $this->config->get('config_url');
     //prepare data with customer details.
     if ($this->customer->getId()) {
         $order_info['customer_id'] = $this->customer->getId();
         $order_info['customer_group_id'] = $this->customer->getCustomerGroupId();
         $order_info['firstname'] = $this->customer->getFirstName();
         $order_info['lastname'] = $this->customer->getLastName();
         $order_info['email'] = $this->customer->getEmail();
         $order_info['telephone'] = $this->customer->getTelephone();
         $order_info['fax'] = $this->customer->getFax();
         $this->load->model('account/address');
         if ($this->cart->hasShipping()) {
             $ship_address_id = $indata['shipping_address_id'];
             $ship_address = $this->model_account_address->getAddress($ship_address_id);
             $order_info['shipping_firstname'] = $ship_address['firstname'];
             $order_info['shipping_lastname'] = $ship_address['lastname'];
             $order_info['shipping_company'] = $ship_address['company'];
             $order_info['shipping_address_1'] = $ship_address['address_1'];
             $order_info['shipping_address_2'] = $ship_address['address_2'];
             $order_info['shipping_city'] = $ship_address['city'];
             $order_info['shipping_postcode'] = $ship_address['postcode'];
             $order_info['shipping_zone'] = $ship_address['zone'];
             $order_info['shipping_zone_id'] = $ship_address['zone_id'];
             $order_info['shipping_country'] = $ship_address['country'];
             $order_info['shipping_country_id'] = $ship_address['country_id'];
             $order_info['shipping_address_format'] = $ship_address['address_format'];
         } else {
             $order_info['shipping_firstname'] = '';
             $order_info['shipping_lastname'] = '';
             $order_info['shipping_company'] = '';
             $order_info['shipping_address_1'] = '';
             $order_info['shipping_address_2'] = '';
             $order_info['shipping_city'] = '';
             $order_info['shipping_postcode'] = '';
             $order_info['shipping_zone'] = '';
             $order_info['shipping_zone_id'] = '';
             $order_info['shipping_country'] = '';
             $order_info['shipping_country_id'] = '';
             $order_info['shipping_address_format'] = '';
             $order_info['shipping_method'] = '';
         }
         $pay_address_id = $indata['payment_address_id'];
         $pay_address = $this->model_account_address->getAddress($pay_address_id);
         $order_info['payment_firstname'] = $pay_address['firstname'];
         $order_info['payment_lastname'] = $pay_address['lastname'];
         $order_info['payment_company'] = $pay_address['company'];
         $order_info['payment_address_1'] = $pay_address['address_1'];
         $order_info['payment_address_2'] = $pay_address['address_2'];
         $order_info['payment_city'] = $pay_address['city'];
         $order_info['payment_postcode'] = $pay_address['postcode'];
         $order_info['payment_zone'] = $pay_address['zone'];
         $order_info['payment_zone_id'] = $pay_address['zone_id'];
         $order_info['payment_country'] = $pay_address['country'];
         $order_info['payment_country_id'] = $pay_address['country_id'];
         $order_info['payment_address_format'] = $pay_address['address_format'];
     } else {
         if (isset($indata['guest'])) {
             //this is a guest order
             $order_info['customer_id'] = 0;
             $order_info['customer_group_id'] = $this->config->get('config_customer_group_id');
             $order_info['firstname'] = $indata['guest']['firstname'];
             $order_info['lastname'] = $indata['guest']['lastname'];
             $order_info['email'] = $indata['guest']['email'];
             $order_info['telephone'] = $indata['guest']['telephone'];
             $order_info['fax'] = $indata['guest']['fax'];
             if ($this->cart->hasShipping()) {
                 if (isset($indata['guest']['shipping'])) {
                     $order_info['shipping_firstname'] = $indata['guest']['shipping']['firstname'];
                     $order_info['shipping_lastname'] = $indata['guest']['shipping']['lastname'];
                     $order_info['shipping_company'] = $indata['guest']['shipping']['company'];
                     $order_info['shipping_address_1'] = $indata['guest']['shipping']['address_1'];
                     $order_info['shipping_address_2'] = $indata['guest']['shipping']['address_2'];
                     $order_info['shipping_city'] = $indata['guest']['shipping']['city'];
                     $order_info['shipping_postcode'] = $indata['guest']['shipping']['postcode'];
                     $order_info['shipping_zone'] = $indata['guest']['shipping']['zone'];
                     $order_info['shipping_zone_id'] = $indata['guest']['shipping']['zone_id'];
                     $order_info['shipping_country'] = $indata['guest']['shipping']['country'];
                     $order_info['shipping_country_id'] = $indata['guest']['shipping']['country_id'];
                     $order_info['shipping_address_format'] = $indata['guest']['shipping']['address_format'];
                 } else {
                     $order_info['shipping_firstname'] = $indata['guest']['firstname'];
                     $order_info['shipping_lastname'] = $indata['guest']['lastname'];
                     $order_info['shipping_company'] = $indata['guest']['company'];
                     $order_info['shipping_address_1'] = $indata['guest']['address_1'];
                     $order_info['shipping_address_2'] = $indata['guest']['address_2'];
                     $order_info['shipping_city'] = $indata['guest']['city'];
                     $order_info['shipping_postcode'] = $indata['guest']['postcode'];
                     $order_info['shipping_zone'] = $indata['guest']['zone'];
                     $order_info['shipping_zone_id'] = $indata['guest']['zone_id'];
                     $order_info['shipping_country'] = $indata['guest']['country'];
                     $order_info['shipping_country_id'] = $indata['guest']['country_id'];
                     $order_info['shipping_address_format'] = $indata['guest']['address_format'];
                 }
             } else {
                 $order_info['shipping_firstname'] = '';
                 $order_info['shipping_lastname'] = '';
                 $order_info['shipping_company'] = '';
                 $order_info['shipping_address_1'] = '';
                 $order_info['shipping_address_2'] = '';
                 $order_info['shipping_city'] = '';
                 $order_info['shipping_postcode'] = '';
                 $order_info['shipping_zone'] = '';
                 $order_info['shipping_zone_id'] = '';
                 $order_info['shipping_country'] = '';
                 $order_info['shipping_country_id'] = '';
                 $order_info['shipping_address_format'] = '';
                 $order_info['shipping_method'] = '';
             }
             $order_info['payment_firstname'] = $indata['guest']['firstname'];
             $order_info['payment_lastname'] = $indata['guest']['lastname'];
             $order_info['payment_company'] = $indata['guest']['company'];
             $order_info['payment_address_1'] = $indata['guest']['address_1'];
             $order_info['payment_address_2'] = $indata['guest']['address_2'];
             $order_info['payment_city'] = $indata['guest']['city'];
             $order_info['payment_postcode'] = $indata['guest']['postcode'];
             $order_info['payment_zone'] = $indata['guest']['zone'];
             $order_info['payment_zone_id'] = $indata['guest']['zone_id'];
             $order_info['payment_country'] = $indata['guest']['country'];
             $order_info['payment_country_id'] = $indata['guest']['country_id'];
             $order_info['payment_address_format'] = $indata['guest']['address_format'];
         } else {
             return array();
         }
     }
     if (isset($indata['shipping_method']['title'])) {
         $order_info['shipping_method'] = $indata['shipping_method']['title'];
         $order_info['shipping_method_key'] = $indata['shipping_method']['id'];
         // note - id by mask method_txt_id.method_option_id. for ex. default_weight.default_weight_1
     } else {
         $order_info['shipping_method'] = '';
         $order_info['shipping_method_key'] = '';
     }
     if (isset($indata['payment_method']['title'])) {
         $order_info['payment_method'] = $indata['payment_method']['title'];
         preg_match('/^([^.]+)/', $indata['payment_method']['id'], $matches);
         $order_info['payment_method_key'] = $matches[1];
     } else {
         $order_info['payment_method'] = '';
     }
     $product_data = array();
     foreach ($this->cart->getProducts() as $product) {
         $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $product['option'], 'download' => $product['download'], 'quantity' => $product['quantity'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->calcTotalTaxAmount($product['total'], $product['tax_class_id']), 'stock' => $product['stock'], 'sku' => $product['sku']);
     }
     $order_info['products'] = $product_data;
     $order_info['totals'] = $total_data;
     $order_info['comment'] = $indata['comment'];
     $order_info['total'] = $total;
     $order_info['language_id'] = $this->config->get('storefront_language_id');
     $order_info['currency_id'] = $this->currency->getId();
     $order_info['currency'] = $this->currency->getCode();
     $order_info['value'] = $this->currency->getValue($this->currency->getCode());
     if (isset($indata['coupon'])) {
         $promotion = new APromotion();
         $coupon = $promotion->getCouponData($indata['coupon']);
         if ($coupon) {
             $order_info['coupon_id'] = $coupon['coupon_id'];
         } else {
             $order_info['coupon_id'] = 0;
         }
     } else {
         $order_info['coupon_id'] = 0;
     }
     $order_info['ip'] = $this->request->server['REMOTE_ADDR'];
     $this->order_data = $order_info;
     return $this->order_data;
 }
 private function _validateCoupon()
 {
     $this->loadLanguage('checkout/payment');
     $promotion = new APromotion();
     $coupon = $promotion->getCouponData($this->request->post['coupon']);
     if (!$coupon) {
         $this->error['warning'] = $this->language->get('error_coupon');
     }
     if (!$this->error) {
         return TRUE;
     } else {
         return FALSE;
     }
 }