public function output($step = 0)
 {
     global $temp_orders_id;
     $html = '';
     if (isset(Checkout::$errors[$this->type])) {
         $html .= '<div class="alert alert-error"><strong>' . Translate('Opgelet!') . '</strong> ' . Translate(Checkout::$errors[$this->type]) . '</div>';
         unset(Checkout::$errors[$this->type]);
     }
     //select payment method if orders_id is known
     //also get billing country
     if (!empty($temp_orders_id)) {
         $selected_query = tep_db_query('SELECT payment_method, billing_country FROM temp_orders WHERE orders_id = "' . $temp_orders_id . '"');
         $selected = tep_db_fetch_array($selected_query);
     }
     foreach ($this->instances as $id => $data) {
         if ($data['status'] == 'true') {
             //check is active for zones and choosen shipping module
             if (parent::checkZone($data['zone'], $selected['billing_country']) && parent::checkShippingMethod($data['shipping_module'])) {
                 if (isset(Checkout::$errors[$id])) {
                     $html .= '<div class="alert alert-error"><strong>' . Translate('Opgelet!') . '</strong> ' . Translate(Checkout::$errors[$id]) . '</div>';
                 }
                 $html .= '<label class="control-label" for="' . $this->type . '_' . $id . '" style="display:block;">';
                 $html .= '<div class="' . $this->type . '_item clearfix">';
                 $html .= '<input type="radio" name="' . $this->type . '" value="' . $id . '" id="' . $this->type . '_' . $id . '"' . ($selected['payment_method'] == $id ? ' checked=checked' : '') . ' />';
                 $html .= '<div class="' . $this->type . '_title">&nbsp; ' . Translate($data['title']) . '</div>';
                 if (!empty($data['description'])) {
                     $html .= '<div class="' . $this->type . '_description">&nbsp; ' . Translate($data['description']) . '</div>';
                 }
                 $html .= '</div>';
                 $html .= '</label>';
             }
         }
     }
     return $html;
 }
 public function output($step = 0)
 {
     global $temp_orders_id;
     $html = '';
     if (isset(Checkout::$errors[$this->type])) {
         $html .= '<div class="alert alert-error"><strong>' . Translate('Opgelet!') . '</strong> ' . Translate(Checkout::$errors[$this->type]) . '</div>';
         unset(Checkout::$errors[$this->type]);
     }
     foreach ($this->instances as $id => $data) {
         if ($data['status'] == 'true') {
             //check is active for zones and choosen shipping module
             if (parent::checkZone($data['zone'], $this->temp_data[$temp_orders_id]['orders']['billing_country']) && parent::checkShippingMethod($data['shipping_module'])) {
                 if (isset(Checkout::$errors[$id])) {
                     $html .= '<div class="alert alert-error"><strong>' . Translate('Opgelet!') . '</strong> ' . Translate(Checkout::$errors[$id]) . '</div>';
                 }
                 $html .= '<label class="control-label" for="' . $this->type . '_' . $id . '" style="display:block;">';
                 $html .= '<div class="' . $this->type . '_item clearfix">';
                 $html .= '<input type="radio" name="' . $this->type . '" value="' . $id . '" id="' . $this->type . '_' . $id . '"' . ($this->temp_data[$temp_orders_id]['orders']['payment_method'] == $id ? ' checked=checked' : '') . ' />';
                 $paymentMethods = array();
                 foreach ($this->paymentmethods as $name => $value) {
                     $payment = new $value();
                     //Store the issuers for this paymentmethod into an array
                     $issuers = $payment->getSupportedIssuers();
                     foreach ($issuers as $issuer => $issuerData) {
                         if (isset($issuerData['name'])) {
                             $paymentMethods[] = array('value' => $value . '__' . $issuer, 'name' => $issuerData['name']);
                         } else {
                             $paymentMethods[] = array('value' => $value . '__' . $issuer, 'name' => $name);
                         }
                     }
                 }
                 if (count($paymentMethods) > 1) {
                     $html .= '<select name="' . $this->type . '_paymentmethod">';
                     foreach ($paymentMethods as $key => $value) {
                         $html .= '<option value="' . $value['value'] . '">' . $value['name'] . '</option>';
                     }
                     $html .= '</select>';
                 } else {
                     $html .= '<input type="hidden" name="' . $this->type . '_paymentmethod" value="' . $paymentMethods[0]['value'] . '" />';
                 }
                 $html .= '<div class="' . $this->type . '_title">&nbsp; ' . $data['title'] . '</div>';
                 if (!empty($data['description'])) {
                     $html .= '<div class="' . $this->type . '_description">&nbsp; ' . $data['description'] . '</div>';
                 }
                 $html .= '</div>';
                 $html .= '</label>';
             }
         }
     }
     return $html;
 }
 public function output_array($country = 0)
 {
     global $currencies, $temp_orders_id;
     $array = array();
     foreach ($this->instances as $id => $data) {
         if ($data['status'] == 'true') {
             if (parent::checkZone($data['zone'], $country)) {
                 $array[] = array('title' => Translate($data['title']), 'description' => Translate($data['description']), 'quote' => $data['quote']);
             }
         }
     }
     return $array;
 }
 public function calculate_credit($amount)
 {
     global $temp_orders_id, $currencies, $currency;
     $return = array();
     $return['coupon_amount'] = 0;
     $return['coupon_text'] = '';
     $temp_data = Checkout::get_all_data_from_temp_db($temp_orders_id);
     foreach ($temp_data[$temp_orders_id]['orders_total'] as $key => $data) {
         if ($data['class'] == 'shipping') {
             $shipping_cost = $data['value'];
         }
         if ($data['class'] == 'order_total') {
             $order_total = $data['value'];
         }
     }
     if (isset($temp_data[$temp_orders_id]['orders']['coupon_id']) && $temp_data[$temp_orders_id]['orders']['coupon_id'] > 0) {
         $coupon_query = tep_db_query("select coupon_code, coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, restrict_to_zones, coupon_type from coupons where coupon_id = '" . $temp_data[$temp_orders_id]['orders']['coupon_id'] . "'");
         $coupon_result = tep_db_fetch_array($coupon_query);
         //percent
         if ($coupon_result['coupon_type'] == 'P' && ($coupon_result['restrict_to_products'] != '' || $coupon_result['restrict_to_categories'] != '')) {
             $coupon_result['coupon_amount'] = substr($coupon_result['coupon_amount'], 0, -1);
             $return['coupon_text'] = number_format($coupon_result['coupon_amount']) . '% ' . Translate('op') . ' ';
         } else {
             if ($coupon_result['coupon_type'] == 'P') {
                 $coupon_result['coupon_amount'] = substr($coupon_result['coupon_amount'], 0, -1);
                 $return['coupon_text'] = number_format($coupon_result['coupon_amount']) . '%';
             } else {
                 if ($coupon_result['restrict_to_products'] != '' || $coupon_result['restrict_to_categories'] != '') {
                     $return['coupon_text'] = ' ' . Translate('op') . ' ';
                 }
             }
         }
         if ($coupon_result['coupon_minimum_order'] <= $order_total) {
             if ($coupon_result['restrict_to_products'] != '' || $coupon_result['restrict_to_categories'] != '' || $coupon_result['restrict_to_zones'] != '') {
                 $used_restricted_categories = array();
                 foreach ($temp_data[$temp_orders_id]['orders_products'] as $order_products_id => $products_data) {
                     if ($coupon_result['restrict_to_categories'] != '') {
                         /****************************/
                         /*	RESTRICT TO CATEGORIES	*/
                         /****************************/
                         $cat_ids = preg_split("/[,]/", $coupon_result['restrict_to_categories']);
                         $my_path = tep_get_product_path($products_data['products_id']);
                         $sub_cat_ids = preg_split("/[_]/", $my_path);
                         for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {
                             //loop through all category IDs from the product
                             for ($ii = 0; $ii < count($cat_ids); $ii++) {
                                 //Loop through all restricted category IDs
                                 if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {
                                     //Check if there are similar category IDs
                                     if ($coupon_result['coupon_type'] == 'P') {
                                         //Percent
                                         $pr_c = $products_data['final_price'] * $products_data['products_quantity'];
                                         $pod_amount = round($pr_c * 10) / 10 * $coupon_result['coupon_amount'] / 100;
                                         $return['coupon_amount'] = $return['coupon_amount'] + $pod_amount;
                                         $used_restricted_categories[] = $cat_ids[$ii];
                                         continue 2;
                                     } else {
                                         //Fixed amount
                                         $return['coupon_amount'] = $coupon_result['coupon_amount'];
                                         //No shipping costs
                                         if ($coupon_result['coupon_type'] == 'S') {
                                             $return['coupon_text'] = Translate('Gratis verzending');
                                             $return['coupon_amount'] = $shipping_cost;
                                         }
                                         if ($coupon_result['coupon_type'] == 'S' && $coupon_result['coupon_amount'] > 0) {
                                             $return['coupon_amount'] = $shipping_cost + $coupon_result['coupon_amount'];
                                         }
                                         continue 2;
                                     }
                                 }
                             }
                         }
                     }
                     if ($coupon_result['restrict_to_products'] != '') {
                         /****************************/
                         /*	RESTRICT TO PRODUCTS	*/
                         /****************************/
                         $pr_ids = preg_split("/[,]/", $coupon_result['restrict_to_products']);
                         for ($ii = 0; $ii < count($pr_ids); $ii++) {
                             //Loop through restricted products_ids
                             if ($pr_ids[$ii] == $products_data['products_id']) {
                                 if ($coupon_result['coupon_type'] == 'P') {
                                     //Percent
                                     $pr_c = $products_data['final_price'] * $products_data['products_quantity'];
                                     $pod_amount = round($pr_c * 10) / 10 * $coupon_result['coupon_amount'] / 100;
                                     $return['coupon_amount'] = $return['coupon_amount'] + $pod_amount;
                                     $return['coupon_text'] .= $products_data['products_name'] . ', ';
                                 } else {
                                     //fixed amount
                                     $return['coupon_text'] .= $products_data['products_name'] . ', ';
                                     $return['coupon_amount'] = $coupon_result['coupon_amount'];
                                     //No shipping costs
                                     if ($coupon_result['coupon_type'] == 'S') {
                                         $return['coupon_text'] = Translate('Gratis verzending');
                                         $return['coupon_amount'] = $shipping_cost;
                                     }
                                     if ($coupon_result['coupon_type'] == 'S' && $coupon_result['coupon_amount'] > 0) {
                                         $return['coupon_amount'] = $shipping_cost + $coupon_result['coupon_amount'];
                                     }
                                 }
                             }
                         }
                     }
                     if ($coupon_result['restrict_to_zones'] != '') {
                         /************************/
                         /*	RESTRICT TO ZONES	*/
                         /************************/
                         $zones_ids = preg_split("/[,]/", $coupon_result['restrict_to_zones']);
                         for ($ii = 0; $ii < count($zones_ids); $ii++) {
                             //Loop through restricted zone_ids
                             if (parent::checkZone($zones_ids[$ii], $temp_data[$temp_orders_id]['orders']['delivery_country'])) {
                                 if ($coupon_result['coupon_type'] == 'P') {
                                     //Percent
                                     $pr_c = $products_data['final_price'] * $products_data['products_quantity'];
                                     $pod_amount = round($pr_c * 10) / 10 * $coupon_result['coupon_amount'] / 100;
                                     $return['coupon_amount'] = $return['coupon_amount'] + $pod_amount;
                                 } else {
                                     //fixed amount
                                     $return['coupon_amount'] = $coupon_result['coupon_amount'];
                                     //No shipping costs
                                     if ($coupon_result['coupon_type'] == 'S') {
                                         $return['coupon_text'] = Translate('Gratis verzending');
                                         $return['coupon_amount'] = $shipping_cost;
                                     }
                                     if ($coupon_result['coupon_type'] == 'S' && $coupon_result['coupon_amount'] > 0) {
                                         $return['coupon_amount'] = $shipping_cost + $coupon_result['coupon_amount'];
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $used_restricted_categories = array_unique($used_restricted_categories);
                 foreach ($used_restricted_categories as $cat_id) {
                     $return['coupon_text'] .= tep_get_categories_name($cat_id) . ', ';
                 }
             } else {
                 //not restricted to products, categories or zones
                 //percent
                 if ($coupon_result['coupon_type'] == 'P') {
                     $return['coupon_amount'] = $amount * ($coupon_result['coupon_amount'] / 100);
                 }
                 //No shipping costs
                 if ($coupon_result['coupon_type'] == 'S') {
                     $return['coupon_text'] = Translate('Gratis verzending');
                     $return['coupon_amount'] = $shipping_cost;
                 }
                 if ($coupon_result['coupon_type'] == 'S' && $coupon_result['coupon_amount'] > 0) {
                     $return['coupon_amount'] = $shipping_cost + $coupon_result['coupon_amount'];
                 }
                 //fixed amount
                 if ($coupon_result['coupon_type'] == 'G') {
                     $return['coupon_amount'] = $amount;
                 }
             }
             if ($coupon_result['coupon_type'] == 'P' && ($coupon_result['restrict_to_products'] || $coupon_result['restrict_to_categories'])) {
                 $return['coupon_text'] = substr($return['coupon_text'], 0, -2);
             } else {
                 if (strlen($return['coupon_text']) > 2 && ($coupon_result['restrict_to_products'] || $coupon_result['restrict_to_categories'])) {
                     $return['coupon_text'] = substr($return['coupon_text'], 0, -2);
                 }
             }
         } else {
             //coupon minimum order is more then order total
             $return['errors'] = Translate('Om de kortingscode te gebruiken moet uw bestelling een minimum bedrag hebben van') . ' ' . $currencies->format($coupon_result['coupon_minimum_order']);
         }
         if ($coupon_result['coupon_type'] != 'S') {
             if ($return['coupon_amount'] > $amount) {
                 $return['coupon_amount'] = $amount;
             }
         }
     }
     $return['coupon_amount'] = tep_round($return['coupon_amount'], $currencies->currencies[$currency]['decimal_places']);
     return $return;
 }