protected function _getPaymentMethods() { if (!$this->isOpcModuleActive()) { return parent::_getPaymentMethods(); } if ($this->context->cart->OrderExists()) { $ret = '<p class="warning">' . Tools::displayError('Error: this order has already been validated') . '</p>'; return array("orig_hook" => $ret, "parsed_content" => $ret); } $ret = ""; $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = $this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice); if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { $ret = '<p class="warning">' . Tools::displayError('Error: please choose an address') . '</p>'; } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { $ret .= '<p class="warning">' . Tools::displayError('Error: There are no carriers available that deliver to some of your addresses') . '</p>'; } else { $ret .= '<p class="warning">' . Tools::displayError('Error: There are no carriers available that deliver to this address') . '</p>'; } } if (!$this->context->cart->getDeliveryOption(null, false) && !$this->context->cart->isVirtualCart()) { $ret = '<p class="warning">' . Tools::displayError('Error: please choose a carrier') . '</p>'; } if (!$this->context->cart->id_currency) { $ret .= '<p class="warning">' . Tools::displayError('Error: no currency has been selected') . '</p>'; } if (!$this->context->cart->checkQuantities()) { $ret .= '<p class="warning">' . Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order.') . '</p>'; } $currency = Currency::getCurrency((int) $this->context->cart->id_currency); $minimalPurchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) { $ret .= '<p class="warning">' . sprintf(Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'), Tools::displayPrice($minimalPurchase, $currency)) . '</p>'; } if (trim($ret) != "") { return array("orig_hook" => $ret, "parsed_content" => $ret); } $opc_config = $this->context->smarty->tpl_vars["opc_config"]->value; $tmp_customer_id_1 = isset($opc_config) && isset($opc_config["payment_customer_id"]) ? intval($opc_config["payment_customer_id"]) : 0; $reset_id_customer = false; if (!$this->context->cookie->id_customer) { $simulated_customer_id = $tmp_customer_id_1 > 0 ? $tmp_customer_id_1 : Customer::getFirstCustomerId(); $this->context->cookie->id_customer = $simulated_customer_id; $reset_id_customer = true; if (!$this->context->customer->id) { $this->context->customer->id = $simulated_customer_id; } } $orig_context_country = $this->context->country; if (isset($address_invoice) && $address_invoice != null) { $this->context->country = new Country($address_invoice->id_country); } if ($this->context->cart->getOrderTotal() <= 0) { $return = $this->context->smarty->fetch($this->opc_templates_path . '/free-order-payment.tpl'); } else { $ship2pay_support = isset($opc_config) && isset($opc_config["ship2pay"]) && $opc_config["ship2pay"] == "1" ? true : false; if ($ship2pay_support) { $orig_id_carrier = $this->context->cart->id_carrier; $selected_carrier = Cart::desintifier($this->context->cart->simulateCarrierSelectedOutput()); $selected_carrier = explode(",", $selected_carrier); $selected_carrier = $selected_carrier[0]; $this->context->cart->id_carrier = $selected_carrier; $this->context->cart->update(); $return = Hook::exec('displayPayment'); } else { $return = Hook::exec('displayPayment'); } } $this->context->country = $orig_context_country; # restore cookie's id_customer if ($reset_id_customer) { unset($this->context->cookie->id_customer); $this->context->customer->id = null; } # fix Moneybookers relative path to images $return = preg_replace('/src="modules\\//', 'src="' . __PS_BASE_URI__ . 'modules/', $return); # OPCKT fix Paypal relative path to redirect script $return = preg_replace('/href="modules\\//', 'href="' . __PS_BASE_URI__ . 'modules/', $return); if (!$return) { $ret = '<p class="warning">' . Tools::displayError('No payment method is available') . '</p>'; return array("orig_hook" => $ret, "parsed_content" => $ret); } $parsed_content = ""; $parse_payment_methods = isset($opc_config) && isset($opc_config["payment_radio_buttons"]) && $opc_config["payment_radio_buttons"] == "1" ? true : false; if ($parse_payment_methods) { $content = $return; $payment_methods = array(); $i = 0; preg_match_all('/<a.*?>[^>]*?<img[^>]*?src="(.*?)".*?\\/?>(.*?)<\\/a>/ms', $content, $matches1, PREG_SET_ORDER); $tmp_return = preg_replace_callback('/(<(a))([^>]*?>[^>]*?<img.*?src)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return == NULL) { echo "ERRoR!"; } if ($tmp_return != null) { // NULL can be returned on backtrace limit exhaustion $return = $tmp_return; } preg_match_all('/<input [^>]*?type="image".*?src="(.*?)".*?>.*?<span.*?>(.*?)<\\/span>/ms', $content, $matches2, PREG_SET_ORDER); $tmp_return = preg_replace_callback('/(<(input)[^>]*?type="image")(.*?<span.)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return != null) { $return = $tmp_return; } preg_match_all('/<a[^>]*?class="(.*?)".*?>(.*?)<\\/a>/ms', $content, $matches3, PREG_SET_ORDER); $tmp_return = preg_replace_callback('/(<a[^>]*?class="(.*?)")([^>]*?>)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return != null) { $return = $tmp_return; } for ($k = 0; $k < count($matches3); $k++) { $matches3[$k][3] = $matches3[$k][1]; // IMG class of original module $matches3[$k][1] = preg_replace('/.*?themes\\//', 'themes/', _THEME_IMG_DIR_) . $matches3[$k][1] . ".png"; } $matches = array_merge($matches1, $matches2, $matches3); foreach ($matches as $match) { $payment_methods[$i]['img'] = preg_replace('/(\\r)?\\n/m', " ", trim($match[1])); $payment_methods[$i]['desc'] = preg_replace('/\\s/m', " ", trim($match[2])); // fixed for Auriga payment $payment_methods[$i]['link'] = "opc_pid_{$i}"; if (isset($match[3])) { $payment_methods[$i]['class'] = trim($match[3]); } $i++; } $this->context->smarty->assign("payment_methods", $payment_methods); $parsed_content = $this->context->smarty->fetch($this->opc_templates_path . "/payment-methods.tpl"); $parsed_content = str_replace("&", "&", $parsed_content); } return array("orig_hook" => $return, "parsed_content" => $parsed_content); }
protected function _getPaymentMethods() { if (!$this->isOpcModuleActive()) { return parent::_getPaymentMethods(); } if ($this->context->cart->OrderExists()) { $ret = '<p class="warning">' . Tools::displayError('Error: this order has already been validated') . '</p>'; return array("orig_hook" => $ret, "parsed_content" => $ret); } $ret = ""; $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = $this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice); if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { $ret = '<p class="warning">' . Tools::displayError('Error: please choose an address') . '</p>'; } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { $ret .= '<p class="warning">' . Tools::displayError('Error: There are no carriers available that deliver to some of your addresses') . '</p>'; } else { $ret .= '<p class="warning">' . Tools::displayError('Error: There are no carriers available that deliver to this address') . '</p>'; } } if (!$this->context->cart->getDeliveryOption(null, false) && !$this->context->cart->isVirtualCart()) { $ret = '<p class="warning">' . Tools::displayError('Error: please choose a carrier') . '</p>'; } if (!$this->context->cart->id_currency) { $ret .= '<p class="warning">' . Tools::displayError('Error: no currency has been selected') . '</p>'; } //if (!$this->context->cookie->checkedTOS && Configuration::get('PS_CONDITIONS')) // return '<p class="warning">'.Tools::displayError('Please accept the Terms of Service').'</p>'; /* If some products have disappear */ if (!$this->context->cart->checkQuantities()) { $ret .= '<p class="warning">' . Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order.') . '</p>'; } /* Check minimal amount */ $currency = Currency::getCurrency((int) $this->context->cart->id_currency); $minimalPurchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) { $ret .= '<p class="warning">' . sprintf(Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'), Tools::displayPrice($minimalPurchase, $currency)) . '</p>'; } /* Bypass payment step if total is 0 */ //if ($this->context->cart->getOrderTotal() <= 0) // $ret .= '<p class="center"><input type="button" class="exclusive_large" name="confirmOrder" id="confirmOrder" value="' . Tools::displayError('I confirm my order') . '" onclick="confirmFreeOrder();" /></p>'; if (trim($ret) != "") { return array("orig_hook" => $ret, "parsed_content" => $ret); } $opc_config = $this->context->smarty->tpl_vars["opc_config"]->value; $tmp_customer_id_1 = isset($opc_config) && isset($opc_config["payment_customer_id"]) ? intval($opc_config["payment_customer_id"]) : 0; $reset_id_customer = false; if (!$this->context->cookie->id_customer) { // if no customer set yet, use OPCKT default customer - created during installation $simulated_customer_id = $tmp_customer_id_1 > 0 ? $tmp_customer_id_1 : Customer::getFirstCustomerId(); $this->context->cookie->id_customer = $simulated_customer_id; $reset_id_customer = true; if (!$this->context->customer->id) { $this->context->customer->id = $simulated_customer_id; } } $orig_context_country = $this->context->country; if (isset($address_invoice) && $address_invoice != null) { $this->context->country = new Country($address_invoice->id_country); } /* Bypass payment step if total is 0 */ if ($this->context->cart->getOrderTotal() <= 0) { $return = $this->context->smarty->fetch($this->opc_templates_path . '/free-order-payment.tpl'); } else { $ship2pay_support = isset($opc_config) && isset($opc_config["ship2pay"]) && $opc_config["ship2pay"] == "1" ? true : false; if ($ship2pay_support) { $orig_id_carrier = $this->context->cart->id_carrier; $selected_carrier = Cart::desintifier($this->context->cart->simulateCarrierSelectedOutput()); $selected_carrier = explode(",", $selected_carrier); $selected_carrier = $selected_carrier[0]; $this->context->cart->id_carrier = $selected_carrier; $this->context->cart->update(); //$return = $this->_hookExecPaymentShip2pay($tmp_id_carrier); $return = Hook::exec('displayPayment'); //$this->context->cart->id_carrier = $orig_id_carrier; } else { $return = Hook::exec('displayPayment'); } //$return = Module::hookExecPayment(); } $this->context->country = $orig_context_country; # restore cookie's id_customer if ($reset_id_customer) { unset($this->context->cookie->id_customer); $this->context->customer->id = null; } # fix Moneybookers relative path to images $return = preg_replace('/src="modules\\//', 'src="' . __PS_BASE_URI__ . 'modules/', $return); # OPCKT fix Paypal relative path to redirect script $return = preg_replace('/href="modules\\//', 'href="' . __PS_BASE_URI__ . 'modules/', $return); if (!$return) { $ret = '<p class="warning">' . Tools::displayError('No payment method is available') . '</p>'; return array("orig_hook" => $ret, "parsed_content" => $ret); } // if radio buttons as payment turned on, parse payment methods, generate radio buttons and // hide original buttons; add large green checkout / submit button and also ensure on onepage.js // that after clicking that button appropriate payment button is pressed. $parsed_content = ""; $parse_payment_methods = isset($opc_config) && isset($opc_config["payment_radio_buttons"]) && $opc_config["payment_radio_buttons"] == "1" ? true : false; if ($parse_payment_methods) { $content = $return; $payment_methods = array(); $i = 0; // regular payment modules preg_match_all('/<a.*?>[^>]*?<img[^>]*?src="(.*?)".*?\\/?>(.*?)<\\/a>/ms', $content, $matches1, PREG_SET_ORDER); // Mark original payment modules with special id $tmp_return = preg_replace_callback('/(<(a))([^>]*?>[^>]*?<img.*?src)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return == NULL) { echo "ERRoR!"; } if ($tmp_return != null) { // NULL can be returned on backtrace limit exhaustion $return = $tmp_return; } // moneybookers preg_match_all('/<input [^>]*?type="image".*?src="(.*?)".*?>.*?<span.*?>(.*?)<\\/span>/ms', $content, $matches2, PREG_SET_ORDER); // Mark original payment modules with special id $tmp_return = preg_replace_callback('/(<(input)[^>]*?type="image")(.*?<span.)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return != null) { $return = $tmp_return; } // PS 1.6 bootstrap payments preg_match_all('/<a[^>]*?class="(.*?)".*?>(.*?)<\\/a>/ms', $content, $matches3, PREG_SET_ORDER); // Mark original payment modules with special id $tmp_return = preg_replace_callback('/(<a[^>]*?class="(.*?)")([^>]*?>)/ms', array($this, "_genPaymentModId"), $return); if ($tmp_return != null) { $return = $tmp_return; } // set class + special class name, then in JS handler get all such styles and set CSS background from original payments for ($k = 0; $k < count($matches3); $k++) { $matches3[$k][3] = $matches3[$k][1]; // IMG class of original module $matches3[$k][1] = preg_replace('/.*?themes\\//', 'themes/', _THEME_IMG_DIR_) . $matches3[$k][1] . ".png"; } $matches = array_merge($matches1, $matches2, $matches3); //print_r($matches); foreach ($matches as $match) { $payment_methods[$i]['img'] = preg_replace('/(\\r)?\\n/m', " ", trim($match[1])); $payment_methods[$i]['desc'] = preg_replace('/\\s/m', " ", trim($match[2])); // fixed for Auriga payment $payment_methods[$i]['link'] = "opc_pid_{$i}"; if (isset($match[3])) { $payment_methods[$i]['class'] = trim($match[3]); } $i++; } //$tmp_return = preg_replace('/(<a.*?)(onclick="(.*?)")(.*?)(href="(.*?)")/', '2:-\2-3:-\3-4:-\4-5:-\5-', $tmp_return); $this->context->smarty->assign("payment_methods", $payment_methods); $parsed_content = $this->context->smarty->fetch($this->opc_templates_path . "/payment-methods.tpl"); $parsed_content = str_replace("&", "&", $parsed_content); } return array("orig_hook" => $return, "parsed_content" => $parsed_content); // $return = Hook::exec('displayPayment'); // if (!$return) // return '<p class="warning">'.Tools::displayError('No payment method is available').'</p>'; // return $return; }