public function processPayment($result, $orderId) { $gopay = new Gopay(); $gpErrors = ""; $history = new OrderHistory(); $history->id_order = $orderId; if ($result["code"] == GopayHelper::WAITING) { $gpErrors = $result["description"]; } else { if ($result["code"] == GopayHelper::PAYMENT_DONE) { if ($history->getLastOrderState($orderId)->id == intval(_PS_OS_GOPAY_)) { $history->changeIdOrderState(intval(_PS_OS_PAYMENT_), intval($orderId)); $history->addWithemail(); } } else { if ($result["code"] == GopayHelper::CANCELED || $result["code"] == GopayHelper::TIMEOUTED) { if ($history->getLastOrderState($orderId)->id == intval(_PS_OS_GOPAY_)) { $history->changeIdOrderState(intval(_PS_OS_CANCELED_), $orderId); $history->addWithemail(); } $gpErrors = $result["description"]; } } } return $gpErrors; }
public function changeIdOrderState($new_order_state = NULL, $id_order) { if ($new_order_state != NULL) { Hook::updateOrderStatus(intval($new_order_state), intval($id_order)); /* Best sellers */ $newOS = new OrderState(intval($new_order_state)); $oldOrderStatus = OrderHistory::getLastOrderState(intval($id_order)); $cart = Cart::getCartByOrderId($id_order); $isValidated = $this->isValidated(); if (Validate::isLoadedObject($cart)) { foreach ($cart->getProducts() as $product) { /* If becoming logable => adding sale */ if ($newOS->logable and (!$oldOrderStatus or !$oldOrderStatus->logable)) { ProductSale::addProductSale($product['id_product'], $product['cart_quantity']); } elseif (!$newOS->logable and ($oldOrderStatus and $oldOrderStatus->logable)) { ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']); } if (!$isValidated and $newOS->logable and isset($oldOrderStatus) and $oldOrderStatus and $oldOrderStatus->id == _PS_OS_ERROR_) { Product::updateQuantity($product); Hook::updateQuantity($product, $order); } } } $this->id_order_state = intval($new_order_state); /* Change invoice number of order ? */ $newOS = new OrderState(intval($new_order_state)); $order = new Order(intval($id_order)); if (!Validate::isLoadedObject($newOS) or !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } /* The order is valid only if the invoice is available and the order is not cancelled */ $order->valid = $newOS->logable; $order->update(); if ($newOS->invoice and !$order->invoice_number) { $order->setInvoice(); } if ($newOS->delivery and !$order->delivery_number) { $order->setDelivery(); } Hook::postUpdateOrderStatus(intval($new_order_state), intval($id_order)); } }
public function changeOrderStatusSub($id_order) { Log::DEBUG("change:1." . $id_order); if ($id_order) { Log::DEBUG("change:2." . $id_order); $lastHistory = OrderHistory::getLastOrderState($id_order); if ($lastHistory->id == Configuration::get('PS_OS_PAYMENT')) { Log::DEBUG("change:2.1." . $id_order); return true; } $history = new OrderHistory(); $history->id_order = (int) $id_order; $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), (int) $id_order); Log::DEBUG("change:3." . $id_order); if ($history->addWithemail()) { Log::DEBUG("change:4." . $id_order); return true; } } return false; }
/** * Checks a payment status of order in shop */ public function initContent() { $cookie = new Cookie('lastOrder'); if ($cookie->orderId != null) { $lastOrderState = OrderHistory::getLastOrderState($cookie->orderId); switch ($lastOrderState->id) { case $this->config->getDotpayNewStatusId(): if (Tools::getValue('lastRequest') === true) { $cookie->logout(); } die('0'); case _PS_OS_PAYMENT_: $cookie->logout(); die('1'); default: die('-1'); } } else { die('NO'); } }
public function cron($jobname, $params, &$message, &$errorcount) { switch ($jobname) { case 'set_shipping_completed': $this->setOrderShippingCompleted($message, $errorcount); break; case 'cancel_orders': $this->log("cron executed job '" . $jobname . "'", ShopgateLogger::LOGTYPE_DEBUG); $cancellationStatus = ConfigurationCore::get('SG_CANCELLATION_STATUS'); $select = sprintf('SELECT ' . (version_compare(_PS_VERSION_, '1.5.0', '>=') ? ' o.current_state, ' : ' o.id_order, ') . ' so.id_shopgate_order from %sshopgate_order as so JOIN %sorders as o on so.id_order=o.id_order WHERE so.is_cancellation_sent_to_shopgate = 0', _DB_PREFIX_, _DB_PREFIX_); $result = Db::getInstance()->ExecuteS($select); if (empty($result)) { $this->log('no orders to cancel found for shop:' . $this->config->getShopNumber(), ShopgateLogger::LOGTYPE_DEBUG); return; } foreach ($result as $order) { $sgOrder = new ShopgateOrderPrestashop($order['id_shopgate_order']); if (is_string($sgOrder->order_number)) { $sgOrder->order_number = (int) $sgOrder->order_number; } if (version_compare(_PS_VERSION_, '1.5.0', '>=')) { $state = $order['current_state']; } else { $stateObject = OrderHistory::getLastOrderState($order['id_order']); $state = $stateObject->id; } if ($state == $cancellationStatus) { $sgOrder->cancelOrder($message); } else { $sgOrder->cancelOrder($message, true); } } break; default: $this->log("job '" . $jobname . "' not found", ShopgateLogger::LOGTYPE_ERROR); throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_CRON_UNSUPPORTED_JOB, 'Job name: "' . $jobname . '"', true); } }
private function isAbandonedOrder($reference) { if (strpos($reference, Configuration::get('PAGSEGURO_ID')) !== false) { $initiated = Util::getPagSeguroStatusName(0); $decReference = (int) EncryptionIdPagSeguro::decrypt($reference); $orderState = OrderHistory::getLastOrderState($decReference); if (strcmp($orderState->name, $initiated) != 0) { return false; } } else { return false; } return true; }
public function hookAdminOrder($params) { if (Tools::isSubmit('submitPayPalCapture')) { $this->_doCapture($params['id_order']); } elseif (Tools::isSubmit('submitPayPalRefund')) { $this->_doTotalRefund($params['id_order']); } $adminTemplates = array(); if ($this->isPayPalAPIAvailable()) { if ($this->_needValidation((int) $params['id_order'])) { $adminTemplates[] = 'validation'; } if ($this->_needCapture((int) $params['id_order'])) { $adminTemplates[] = 'capture'; } if ($this->_canRefund((int) $params['id_order'])) { $adminTemplates[] = 'refund'; } } if (count($adminTemplates) > 0) { $order = new Order((int) $params['id_order']); if (version_compare(_PS_VERSION_, '1.5', '>=')) { $order_state = $order->current_state; } else { $order_state = OrderHistory::getLastOrderState($order->id); } $this->context->smarty->assign(array('authorization' => (int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), 'base_url' => _PS_BASE_URL_ . __PS_BASE_URI__, 'module_name' => $this->name, 'order_state' => $order_state, 'params' => $params, 'ps_version' => _PS_VERSION_)); foreach ($adminTemplates as $adminTemplate) { $this->_html .= $this->fetchTemplate('/views/templates/admin/admin_order/' . $adminTemplate . '.tpl'); $this->_postProcess(); $this->_html .= '</fieldset>'; } } return $this->_html; }
public function hookAdminOrder($params) { if (Tools::isSubmit('paypal')) { switch (Tools::getValue('paypal')) { case 'captureOk': $message = $this->l('Funds have been recovered.'); break; case 'captureError': $message = $this->l('Recovery of funds request unsuccessful. Please see log message!'); break; case 'validationOk': $message = $this->l('Validation successful. Please see log message!'); break; case 'refundOk': $message = $this->l('Refund has been made.'); break; case 'refundError': $message = $this->l('Refund request unsuccessful. Please see log message!'); break; } if (isset($message) && $message) { $this->_html .= ' <br /> <div class="module_confirmation conf confirm" style="width: 400px;"> <img src="' . _PS_IMG_ . 'admin/ok.gif" alt="" title="" /> ' . Tools::safeOutput($message) . ' </div>'; } } $adminTemplates = array(); if ($this->isPayPalAPIAvailable()) { if ($this->_needValidation((int) $params['id_order'])) { $adminTemplates[] = 'validation'; } if ($this->_needCapture((int) $params['id_order'])) { $adminTemplates[] = 'capture'; } if ($this->_canRefund((int) $params['id_order'])) { $adminTemplates[] = 'refund'; } } if (count($adminTemplates) > 0) { if (_PS_VERSION_ >= '1.5') { $order_state = OrderHistory::getLastOrderState((int) $params['id_order'])->id; } else { $order = new Order((int) $params['id_order']); $order_state = $order->current_state->id; } $this->context->smarty->assign(array('authorization' => (int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), 'base_url' => _PS_BASE_URL_ . __PS_BASE_URI__, 'module_name' => $this->name, 'order_state' => $order_state, 'params' => $params)); foreach ($adminTemplates as $adminTemplate) { $this->_html .= $this->fetchTemplate('/views/templates/back/admin_order/', $adminTemplate); $this->_postProcess(); $this->_html .= '</fieldset>'; } } return $this->_html; }
Result is "uploads/filename.extension" */ $target_path = $target_path . basename($_FILES['orders']['name']); if (move_uploaded_file($_FILES['orders']['tmp_name'], $target_path)) { $f = fopen($target_path, 'r'); if ($f) { $count = 0; while ($line = fgetcsv($f)) { if (!is_numeric($line[0])) { continue; } $id_order = (int) $line[0]; $order = new Order($id_order); $history = new OrderHistory(); $history->id_order = $id_order; $history->id_employee = (int) $cookie->id_employee; if ($history->getLastOrderState($id_order) == _PS_OS_DELIVERED_) { continue; } $history->changeIdOrderState(_PS_OS_DELIVERED_, $id_order); $history->addWithemail(true, false); $count++; echo $history->id_order; echo '<br>'; } fclose($f); echo 'Total ' . $count . ' orders marked delivered successfully. Thanks for your attention.'; } else { // error } } else { echo "There was an error uploading the file, please try again!";
public function hookAdminOrder($params) { if (Tools::isSubmit('paypal')) { switch (Tools::getValue('paypal')) { case 'captureOk': $message = $this->l('Funds have been recovered.'); break; case 'captureError': $message = $this->l('Recovery of funds request unsuccessful. Please see log message!'); break; case 'validationOk': $message = $this->l('Validation successful. Please see log message!'); break; case 'refundOk': $message = $this->l('Refund has been made.'); break; case 'refundError': $message = $this->l('Refund request unsuccessful. Please see log message!'); break; } if (isset($message) and $message) { $this->_html .= ' <br /> <div class="module_confirmation conf confirm" style="width: 400px;"> <img src="' . _PS_IMG_ . 'admin/ok.gif" alt="" title="" /> ' . $message . ' </div>'; } } if ($this->_needValidation((int) $params['id_order']) and $this->_isPayPalAPIAvailable()) { $this->_html .= '<br /> <fieldset style="width:400px;"> <legend><img src="' . _MODULE_DIR_ . $this->name . '/logo.gif" alt="" /> ' . $this->l('PayPal Validation') . '</legend> <p><b>' . $this->l('Information:') . '</b> ' . (OrderHistory::getLastOrderState((int) $params['id_order'])->id == (int) Configuration::get('PAYPAL_OS_AUTHORIZATION') ? $this->l('Pending Capture - No shipping') : $this->l('Pending Payment - No shipping')) . '</p> <form method="post" action="' . htmlentities($_SERVER['REQUEST_URI']) . '"> <input type="hidden" name="id_order" value="' . (int) $params['id_order'] . '" /> <p class="center"><input type="submit" class="button" name="submitPayPalValidation" value="' . $this->l('Get payment status') . '" /></p> </form>'; $this->_postProcess(); $this->_html .= '</fieldset>'; } if ($this->_needCapture((int) $params['id_order']) and $this->_isPayPalAPIAvailable()) { $this->_html .= '<br /> <fieldset style="width:400px;"> <legend><img src="' . _MODULE_DIR_ . $this->name . '/logo.gif" alt="" /> ' . $this->l('PayPal Capture') . '</legend> <p><b>' . $this->l('Information:') . '</b> ' . $this->l('Funds ready to be captured before shipping.') . '</p> <form method="post" action="' . htmlentities($_SERVER['REQUEST_URI']) . '"> <input type="hidden" name="id_order" value="' . (int) $params['id_order'] . '" /> <p class="center"><input type="submit" class="button" name="submitPayPalCapture" value="' . $this->l('Get the money.') . '" /></p> </form>'; $this->_postProcess(); $this->_html .= '</fieldset>'; } if ($this->_canRefund((int) $params['id_order']) and $this->_isPayPalAPIAvailable()) { $this->_html .= '<br /> <fieldset style="width:400px;"> <legend><img src="' . _MODULE_DIR_ . $this->name . '/logo.gif" alt="" /> ' . $this->l('PayPal Refund') . '</legend> <p><b>' . $this->l('Information:') . '</b> ' . $this->l('Payment accepted') . '</p> <p><b>' . $this->l('Information:') . '</b> ' . $this->l('When you refund a product, a partial refund is made unless you select "Generate a voucher".') . '</p> <form method="post" action="' . htmlentities($_SERVER['REQUEST_URI']) . '"> <input type="hidden" name="id_order" value="' . (int) $params['id_order'] . '" /> <p class="center"><input type="submit" class="button" name="submitPayPalRefund" value="' . $this->l('Refund total transaction') . '" onclick="if (!confirm(\'' . $this->l('Are you sure?') . '\'))return false;" /></p> </form>'; $this->_postProcess(); $this->_html .= '</fieldset>'; } return $this->_html; }
public static function printPDFIcons($id_order, $tr) { $order = new Order($id_order); $orderState = OrderHistory::getLastOrderState($id_order); if (!Validate::isLoadedObject($orderState) or !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid objects!')); } echo '<span style="width:20px; margin-right:5px;">'; if (($orderState->invoice or $order->invoice_number) and intval($tr['product_number'])) { echo '<a href="pdf.php?id_order=' . intval($order->id) . '&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>'; } else { echo ' '; } echo '</span>'; echo '<span style="width:20px;">'; if ($orderState->delivery or $order->delivery_number) { echo '<a href="pdf.php?id_delivery=' . intval($order->delivery_number) . '"><img src="../img/admin/delivery.gif" alt="delivery" /></a>'; } else { echo ' '; } echo '</span>'; }
FROM `' . _DB_PREFIX_ . 'mr_selected` ms LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_cart` = ms.`id_cart`) WHERE `exp_number` != 0'); if (empty($expeditions)) { exit; } $params = array('Enseigne' => Configuration::get('MR_ENSEIGNE_WEBSERVICE'), 'Langue' => 'FR'); require_once 'kit_mondialrelay/tools/nusoap/lib/nusoap.php'; $client_mr = new nusoap_client("http://www.mondialrelay.fr/webservice/Web_Services.asmx?WSDL", true); $client_mr->soap_defencoding = 'UTF-8'; $client_mr->decode_utf8 = false; foreach ($expeditions as $expedition) { if ($expedition['id_order'] == NULL) { continue; } if (OrderHistory::getLastOrderState((int) $expedition['id_order'])->id == _PS_OS_DELIVERED_) { continue; } $params['Expedition'] = $expedition['exp_number']; $params['Security'] = strtoupper(md5($params['Enseigne'] . $params['Expedition'] . 'FR' . Configuration::get('MR_KEY_WEBSERVICE'))); $is_delivered = 0; $result_mr = $client_mr->call('WSI2_TracingColisDetaille', $params, 'http://www.mondialrelay.fr/webservice/', 'http://www.mondialrelay.fr/webservice/WSI2_TracingColisDetaille'); if (isset($result_mr['WSI2_TracingColisDetailleResult']['Tracing']['ret_WSI2_sub_TracingColisDetaille'])) { foreach ($result_mr['WSI2_TracingColisDetailleResult']['Tracing']['ret_WSI2_sub_TracingColisDetaille'] as $result) { if (isset($result['Libelle']) and $result['Libelle'] == 'COLIS LIVRÉ') { $is_delivered = 1; } } } if ($is_delivered == 1) { $history = new OrderHistory();
/** * @return mixed */ private function getCurrentPrestaOrderState() { if (version_compare(_PS_VERSION_, '1.5', 'lt')) { $order_state = OrderHistory::getLastOrderState($this->order->id); $order_state_id = $order_state->id; return $order_state_id; } else { $order_state_id = $this->order->current_state; } return $order_state_id; }
public function ajaxCall() { if (Tools::getIsset('rangargs')) { $reference = Tools::getValue('rangargs'); $orders = Order::getByReference($reference); if ($orders) { $isOK = true; foreach ($orders as $obj) { $status = OrderHistory::getLastOrderState($obj->id); if ($status->id != Configuration::get('PS_OS_PAYMENT')) { $isOK &= false; break; } } if ($isOK) { die(Tools::jsonEncode(array('status' => 1))); } } } sleep(1); die(Tools::jsonEncode(array('status' => 0, 'id_order' => $reference, 'id' => $status->id))); }
<?php include dirname(__FILE__) . '/../../config/config.inc.php'; include dirname(__FILE__) . '/../../init.php'; require_once dirname(__FILE__) . '/paymentwall.php'; $orderStatus = OrderHistory::getLastOrderState($_GET['orderId']); if ($orderStatus) { echo $orderStatus->id; } else { echo 0; }
function sendOrderStatusMail() { // Select all Orders which are not in (4,5,6,10) state // Select id_order, payment and is_queued atleast once $sql = "select \n o.id_order, \n o.payment, \n position('3' IN group_concat(oh.id_order_state)) as is_queued \n from \n ps_orders o \n inner join ps_order_history oh \n on oh.id_order = o.id_order \n inner join ps_order_history h \n on h.id_order = o.id_order \n inner join \n (select id_order, max(date_add) max_date_add from ps_order_history group by id_order) t2 \n on (h.id_order = t2.id_order and h.date_add = t2.max_date_add) \n where \n h.id_order_state not in (4,5,6,10,20,34) \n group by \n o.id_order"; $total_orders = $not_shipped = $in_sourcing = $in_cust = $on_track = 0; $result = Db::getInstance()->ExecuteS($sql); $reports = array(); foreach ($result as $order) { $total_orders++; $id_order = (int) $order['id_order']; $payment = (string) $order['payment']; $is_queued = (int) $order['is_queued'] === 0 ? false : true; if ($payment === 'Bank Wire' && $is_queued === false) { continue; } $order = new Order($id_order); $orderHistory = new OrderHistory(); $orderStateObj = $orderHistory->getLastOrderState($id_order); $customer = new Customer($order->id_customer); $cart = new Cart($order->id_cart); $products = $cart->getProducts(); $order_placed_date = date_create((string) $order->date_add); $actual_expected_shipping_date = date_create((string) $order->actual_expected_shipping_date); $current_expected_shipping_date = date_create((string) $order->expected_shipping_date); $status_updated_date = date_create((string) $orderStateObj->date_add); $curr_date = new Datetime(); $same_order = false; foreach ($products as $product) { $reportObject = array(); $reportObject['id_order'] = $id_order; $reportObject["name"] = $product['name']; $reportObject["reference"] = $product['reference']; $reportObject['customer_name'] = (string) $customer->firstname . ' ' . (string) $customer->lastname; $reportObject['email'] = (string) $customer->email; $reportObject['total_paid'] = (double) $order->total_paid; $reportObject['order_state'] = (string) $orderStateObj->name; $reportObject['order_placed_date'] = (string) $order_placed_date->format('Y-m-d'); $reportObject['actual_expected_shipping_date'] = (string) $actual_expected_shipping_date->format('Y-m-d'); $reportObject['current_expected_shipping_date'] = (string) $current_expected_shipping_date->format('Y-m-d'); $reportObject['status_updated_date'] = (string) $status_updated_date->format('Y-m-d'); $reportObject['flags'] = array(); if ($actual_expected_shipping_date < $curr_date || $current_expected_shipping_date < $curr_date) { if (!$same_order) { $not_shipped++; } array_push($reportObject['flags'], "not shipped"); } if ($reportObject['order_state'] === 'Customization in Progress' && $status_updated_date->add(new DateInterval('P5D')) < $curr_date) { if (!$same_order) { $in_cust++; } array_push($reportObject['flags'], "> 5days in cust"); } //(DATEDIFF(o.expected_shipping_date, o.date_add)/2 > DATEDIFF(o.expected_shipping_date, t1.date_add)) if ($reportObject['order_state'] === 'Sourcing in Progress') { $sourcing_flag = false; if ($current_expected_shipping_date > $curr_date) { $total_days_avail = (int) $current_expected_shipping_date->diff($order_placed_date)->days; $curr_days_avail = (int) $curr_date->diff($current_expected_shipping_date)->days; if ($total_days_avail / 2 > $curr_days_avail) { $sourcing_flag = true; } } else { $sourcing_flag = true; } if ($sourcing_flag) { if (!$same_order) { $in_sourcing++; } array_push($reportObject['flags'], "in sourcing"); } } if (empty($reportObject['flags'])) { if (!$same_order) { $on_track++; } $reportObject['flags'] = 'on track'; } else { $reportObject['flags'] = implode(",", $reportObject['flags']); } array_push($reports, $reportObject); $same_order = true; } } $headers = array(array("order_id", "40px"), array("pname", "100px"), array("pcode", "40px"), array("customer_name", "100px"), array("customer_email", "100px"), array("total_paid", "40px"), array("current_status", "100px"), array("placed_date", "50px"), array("original_shipping_date", "50px"), array("current_shipping_date", "50px"), array("order_status_updated_date", "50px"), array("urgency_level", "40px")); global $smarty; $smarty->assign("headers", $headers); $smarty->assign("total_orders", $total_orders); $smarty->assign("not_shipped", $not_shipped); $smarty->assign("in_cust", $in_cust); $smarty->assign("in_sourcing", $in_sourcing); $smarty->assign("on_track", $on_track); $smarty->assign("result", $reports); $line = ''; foreach ($headers as $header) { $value = str_replace('"', '""', $header[0]); $value = '"' . $value . '"' . ","; $line .= $value; } $data = trim($line) . "\n"; foreach ($reports as $row) { $line = ''; foreach ($row as $value) { if (!isset($value) || $value == "") { $value = ","; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . ","; } $line .= $value; } $data .= trim($line) . "\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\nNo Records Found!\n"; } $fileAttachment['content'] = $data; $fileAttachment['name'] = 'IndusdivaOrderDailyStatus' . date("d-m-Y") . '.csv'; $fileAttachment['mime'] = 'text/csv'; $templateVars = array(); $templateVars['{today_date}'] = date('d-m-y'); $templateVars['{report_summary}'] = $smarty->fetch(_PS_THEME_DIR_ . 'order-daily-summary.tpl'); $templateVars['{report_content}'] = $smarty->fetch(_PS_THEME_DIR_ . 'order-daily-status.tpl'); $to = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); $subject = "Order Daily Status - " . date('d-m-y'); @Mail::Send(1, 'order_daily_status', $subject, $templateVars, $to, null, '*****@*****.**', 'Indusdiva.com', $fileAttachment, NULL, _PS_MAIL_DIR_, false); }
public function hookAdminOrder($params) { if (Tools::isSubmit('submitPayPalCapture')) { if ($capture_amount = Tools::getValue('totalCaptureMoney')) { if ($capture_amount = PaypalCapture::parsePrice($capture_amount)) { if (Validate::isFloat($capture_amount)) { $capture_amount = Tools::ps_round($capture_amount, '6'); $ord = new Order((int) $params['id_order']); $cpt = new PaypalCapture(); if ($capture_amount > Tools::ps_round(0, '6') && Tools::ps_round($cpt->getRestToPaid($ord), '6') >= $capture_amount) { $complete = false; if ($capture_amount > Tools::ps_round((double) $ord->total_paid, '6')) { $capture_amount = Tools::ps_round((double) $ord->total_paid, '6'); $complete = true; } if ($capture_amount == Tools::ps_round($cpt->getRestToPaid($ord), '6')) { $complete = true; } $this->_doCapture($params['id_order'], $capture_amount, $complete); } } } } } elseif (Tools::isSubmit('submitPayPalRefund')) { $this->_doTotalRefund($params['id_order']); } $admin_templates = array(); if ($this->isPayPalAPIAvailable()) { if ($this->_needValidation((int) $params['id_order'])) { $admin_templates[] = 'validation'; } if ($this->_needCapture((int) $params['id_order'])) { $admin_templates[] = 'capture'; } if ($this->_canRefund((int) $params['id_order'])) { $admin_templates[] = 'refund'; } } if (count($admin_templates) > 0) { $order = new Order((int) $params['id_order']); $currency = new Currency($order->id_currency); $cpt = new PaypalCapture(); $cpt->id_order = (int) $order->id; if (version_compare(_PS_VERSION_, '1.5', '>=')) { $order_state = $order->current_state; } else { $order_state = OrderHistory::getLastOrderState($order->id); } $this->context->smarty->assign(array('authorization' => (int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), 'base_url' => _PS_BASE_URL_ . __PS_BASE_URI__, 'module_name' => $this->name, 'order_state' => $order_state, 'params' => $params, 'id_currency' => $currency->getSign(), 'rest_to_capture' => Tools::ps_round($cpt->getRestToPaid($order), '6'), 'list_captures' => $cpt->getListCaptured(), 'ps_version' => _PS_VERSION_)); foreach ($admin_templates as $admin_template) { $this->_html .= $this->fetchTemplate('/views/templates/admin/admin_order/' . $admin_template . '.tpl'); $this->_postProcess(); $this->_html .= '</fieldset>'; } } return $this->_html; }
/** * Function which is used to making refunds */ private function makeRefund() { $api = $this->api; $statusName = $this->api->getOperationStatusName(); if ($statusName != $api::operationCompleted && $statusName != $api::operationRejected) { die('OK'); } $order = new Order((int) $this->getDotControl(Tools::getValue('control'))); $currency = new Currency($order->id_currency); $payments = OrderPayment::getByOrderId($order->id); $foundPaymet = false; $sumOfPayments = 0.0; foreach ($payments as $payment) { $currency = Currency::getCurrency($order->id_currency); if ($payment->transaction_id == $this->api->getOperationNumber()) { die('PrestaShop - PAYMENT ' . $this->api->getOperationNumber() . ' IS ALREADY SAVED'); } else { if ($payment->transaction_id == $this->api->getRelatedOperationNumber()) { $foundPaymet = true; } } if ($payment->payment_method == $this->module->displayName) { $sumOfPayments += (double) $payment->amount; } } if (!$foundPaymet) { die('PrestaShop - PAYMENT ' . $this->api->getRelatedOperationNumber() . ' IS NOT SAVED'); } $receivedAmount = floatval($this->api->getTotalAmount()); if ($receivedAmount - $sumOfPayments >= 0.01) { die('PrestaShop - NO MATCH OR WRONG AMOUNT - ' . $receivedAmount . ' > ' . $sumOfPayments); } $lastOrderState = OrderHistory::getLastOrderState($order->id); if ($lastOrderState->id != $this->config->getDotpayWaitingRefundStatusId()) { die('PrestaShop - REFUND HAVEN\'T BEEN SUBMITTED'); } if ($this->api->getOperationStatusName() == $api::operationCompleted) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->amount = (double) ('-' . Tools::getValue('operation_original_amount')); $payment->id_currency = $order->id_currency; $payment->conversion_rate = 1; $payment->transaction_id = $this->api->getOperationNumber(); $payment->payment_method = $this->module->displayName; $payment->date_add = new \DateTime(); $payment->add(); if ($receivedAmount < $sumOfPayments) { $state = $this->config->getDotpayPartialRefundStatusId(); } else { $state = $this->config->getDotpayTotalRefundStatusId(); } $history = new OrderHistory(); $history->id_order = $order->id; $history->changeIdOrderState($state, $history->id_order); $history->addWithemail(true); } else { if ($this->api->getOperationStatusName() == $api::operationRejected) { $state = $this->config->getDotpayFailedRefundStatusId(); $history = new OrderHistory(); $history->id_order = $order->id; $history->changeIdOrderState($state, $history->id_order); $history->addWithemail(true); } } die('OK'); }
public static function reEvaluateOrder() { $sender = new fianet_sender(); if (Configuration::get('SAC_PRODUCTION')) { $sender->mode = 'production'; } $result = $sender->get_reevaluated_order(); foreach ($result as $row) { if ($row['eval'] > 0) { if (OrderHistory::getLastOrderState($row['refid']) == Configuration::get('SAC_ID_WAITING')) { $orderHistory = new OrderHistory(); $orderHistory->id_order = (int) $row['refid']; $orderHistory->id_order_state = _PS_OS_PAYMENT_; $orderHistory->save(); } } } return true; }
public function viewDetails() { global $currentIndex, $cookie, $link; $irow = 0; if (!($order = $this->loadObject())) { return; } $customer = new Customer($order->id_customer); $customerStats = $customer->getStats(); $addressInvoice = new Address($order->id_address_invoice, (int) $cookie->id_lang); if (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } $addressDelivery = new Address($order->id_address_delivery, (int) $cookie->id_lang); if (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } $carrier = new Carrier($order->id_carrier); $history = $order->getHistory($cookie->id_lang); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $discounts = $order->getDiscounts(); $messages = Message::getMessagesByOrderId($order->id, true); $states = OrderState::getOrderStates((int) $cookie->id_lang); $currency = new Currency($order->id_currency); $currentLanguage = new Language((int) $cookie->id_lang); $currentState = OrderHistory::getLastOrderState($order->id); $sources = ConnectionsSource::getOrderSources($order->id); $cart = Cart::getCartByOrderId($order->id); $row = array_shift($history); if ($prevOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order < ' . (int) $order->id . ' ORDER BY id_order DESC')) { $prevOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $prevOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-left.png" /></a>'; } if ($nextOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order > ' . (int) $order->id . ' ORDER BY id_order ASC')) { $nextOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $nextOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-right.png" /></a>'; } if ($order->total_paid != $order->total_paid_real) { echo '<center><span class="warning" style="font-size: 16px">' . $this->l('Warning:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false) . ' ' . $this->l('paid instead of') . ' ' . Tools::displayPrice($order->total_paid, $currency, false) . ' !</span></center><div class="clear"><br /><br /></div>'; } // display bar code if module enabled $hook = Module::hookExec('invoice', array('id_order' => $order->id)); if ($hook !== false) { echo '<div style="float: right; margin: -40px 40px 10px 0;">'; echo $hook; echo '</div><br class="clear" />'; } // display order header echo ' <div style="float:left" style="width:440px">'; echo '<h2> ' . $prevOrder . ' ' . (Validate::isLoadedObject($customer) ? $customer->firstname . ' ' . $customer->lastname . ' - ' : '') . $this->l('Order #') . sprintf('%06d', $order->id) . ' ' . $nextOrder . ' </h2> <div style="width:429px"> ' . ((($currentState->invoice or $order->invoice_number) and count($products)) ? '<a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" alt="' . $this->l('View invoice') . '" /> ' . $this->l('View invoice') . '</a>' : '<img src="../img/admin/charged_ko.gif" alt="' . $this->l('No invoice') . '" /> ' . $this->l('No invoice')) . ' - ' . (($currentState->delivery or $order->delivery_number) ? '<a href="pdf.php?id_delivery=' . $order->delivery_number . '"><img src="../img/admin/delivery.gif" alt="' . $this->l('View delivery slip') . '" /> ' . $this->l('View delivery slip') . '</a>' : '<img src="../img/admin/delivery_ko.gif" alt="' . $this->l('No delivery slip') . '" /> ' . $this->l('No delivery slip')) . ' - <a href="javascript:window.print()"><img src="../img/admin/printer.gif" alt="' . $this->l('Print order') . '" title="' . $this->l('Print order') . '" /> ' . $this->l('Print page') . '</a> </div> <div class="clear"> </div>'; /* Display current status */ echo ' <table cellspacing="0" cellpadding="0" class="table" style="width: 429px"> <tr> <th>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</th> <th><img src="../img/os/' . $row['id_order_state'] . '.gif" /></th> <th>' . stripslashes($row['ostate_name']) . '</th> <th>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</th> </tr>'; /* Display previous status */ foreach ($history as $row) { echo ' <tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</td> <td><img src="../img/os/' . $row['id_order_state'] . '.gif" /></td> <td>' . stripslashes($row['ostate_name']) . '</td> <td>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</td> </tr>'; } echo ' </table> <br />'; /* Display status form */ echo ' <form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="text-align:center;"> <select name="id_order_state">'; $currentStateTab = $order->getCurrentStateFull($cookie->id_lang); foreach ($states as $state) { echo '<option value="' . $state['id_order_state'] . '"' . ($state['id_order_state'] == $currentStateTab['id_order_state'] ? ' selected="selected"' : '') . '>' . stripslashes($state['name']) . '</option>'; } echo ' </select> <input type="hidden" name="id_order" value="' . $order->id . '" /> <input type="submit" name="submitState" value="' . $this->l('Change') . '" class="button" /> </form>'; /* Display customer information */ if (Validate::isLoadedObject($customer)) { echo '<br /> <fieldset style="width: 400px"> <legend><img src="../img/admin/tab-customers.gif" /> ' . $this->l('Customer information') . '</legend> <span style="font-weight: bold; font-size: 14px;"><a href="?tab=AdminCustomers&id_customer=' . $customer->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee) . '"> ' . $customer->firstname . ' ' . $customer->lastname . '</a></span> (' . $this->l('#') . $customer->id . ')<br /> (<a href="mailto:' . $customer->email . '">' . $customer->email . '</a>)<br /><br />'; if ($customer->isGuest()) { echo ' ' . $this->l('This order has been placed by a') . ' <b>' . $this->l('guest') . '</b>'; if (!Customer::customerExists($customer->email)) { echo '<form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '"> <input type="hidden" name="id_lang" value="' . (int) $order->id_lang . '" /> <p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p> ' . $this->l('This feature will generate a random password and send an e-mail to the customer') . ' </form>'; } else { echo '<div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b></div>'; } } else { echo $this->l('Account registered:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Valid orders placed:') . ' <b>' . $customerStats['nb_orders'] . '</b><br /> ' . $this->l('Total paid since registration:') . ' <b>' . Tools::displayPrice(Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2), $currency, false) . '</b><br />'; } echo '</fieldset>'; } /* Display sources */ if (sizeof($sources)) { echo '<br /> <fieldset style="width: 400px;"><legend><img src="../img/admin/tab-stats.gif" /> ' . $this->l('Sources') . '</legend><ul ' . (sizeof($sources) > 3 ? 'style="height: 200px; overflow-y: scroll; width: 360px;"' : '') . '>'; foreach ($sources as $source) { echo '<li> ' . Tools::displayDate($source['date_add'], (int) $cookie->id_lang, true) . '<br /> <b>' . $this->l('From:') . '</b> <a href="' . $source['http_referer'] . '">' . preg_replace('/^www./', '', parse_url($source['http_referer'], PHP_URL_HOST)) . '</a><br /> <b>' . $this->l('To:') . '</b> ' . $source['request_uri'] . '<br /> ' . ($source['keywords'] ? '<b>' . $this->l('Keywords:') . '</b> ' . $source['keywords'] . '<br />' : '') . '<br /> </li>'; } echo '</ul></fieldset>'; } // display hook specified to this page : AdminOrder if (($hook = Module::hookExec('adminOrder', array('id_order' => $order->id))) !== false) { echo $hook; } echo ' </div> <div style="float: left; margin-left: 40px">'; /* Display invoice information */ echo '<fieldset style="width: 400px">'; if (($currentState->invoice or $order->invoice_number) and count($products)) { echo '<legend><a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" /> ' . $this->l('Invoice') . '</a></legend> <a href="pdf.php?id_order=' . $order->id . '&pdf">' . $this->l('Invoice #') . '<b>' . Configuration::get('PS_INVOICE_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->invoice_number) . '</b></a> <br />' . $this->l('Created on:') . ' ' . Tools::displayDate($order->invoice_date, (int) $cookie->id_lang, true); } else { echo '<legend><img src="../img/admin/charged_ko.gif" />' . $this->l('Invoice') . '</legend> ' . $this->l('No invoice yet.'); } echo '</fieldset><br />'; /* Display shipping infos */ echo ' <fieldset style="width:400px"> <legend><img src="../img/admin/delivery.gif" /> ' . $this->l('Shipping information') . '</legend> ' . $this->l('Total weight:') . ' <b>' . number_format($order->getTotalWeight(), 3) . ' ' . Configuration::get('PS_WEIGHT_UNIT') . '</b><br /> ' . $this->l('Carrier:') . ' <b>' . ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name) . '</b><br /> ' . (($currentState->delivery or $order->delivery_number) ? '<br /><a href="pdf.php?id_delivery=' . $order->delivery_number . '">' . $this->l('Delivery slip #') . '<b>' . Configuration::get('PS_DELIVERY_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->delivery_number) . '</b></a><br />' : ''); if ($order->shipping_number) { echo $this->l('Tracking number:') . ' <b>' . $order->shipping_number . '</b> ' . (!empty($carrier->url) ? '(<a href="' . str_replace('@', $order->shipping_number, $carrier->url) . '" target="_blank">' . $this->l('Track the shipment') . '</a>)' : ''); } /* Carrier module */ if ($carrier->is_module == 1) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { echo call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } /* Display shipping number field */ if ($carrier->url && $order->hasBeenShipped()) { echo ' <form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="margin-top:10px;"> <input type="text" name="shipping_number" value="' . $order->shipping_number . '" /> <input type="hidden" name="id_order" value="' . $order->id . '" /> <input type="submit" name="submitShippingNumber" value="' . $this->l('Set shipping number') . '" class="button" /> </form>'; } echo ' </fieldset>'; /* Display summary order */ echo ' <br /> <fieldset style="width: 400px"> <legend><img src="../img/admin/details.gif" /> ' . $this->l('Order details') . '</legend> <label>' . $this->l('Original cart:') . ' </label> <div style="margin: 2px 0 1em 190px;"><a href="?tab=AdminCarts&id_cart=' . $cart->id . '&viewcart&token=' . Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee) . '">' . $this->l('Cart #') . sprintf('%06d', $cart->id) . '</a></div> <label>' . $this->l('Payment mode:') . ' </label> <div style="margin: 2px 0 1em 190px;">' . Tools::substr($order->payment, 0, 32) . ' ' . ($order->module ? '(' . $order->module . ')' : '') . '</div> <div style="margin: 2px 0 1em 50px;"> <table class="table" width="300px;" cellspacing="0" cellpadding="0"> <tr><td width="150px;">' . $this->l('Products') . '</td><td align="right">' . Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency, false) . '</td></tr> ' . ($order->total_discounts > 0 ? '<tr><td>' . $this->l('Discounts') . '</td><td align="right">-' . Tools::displayPrice($order->total_discounts, $currency, false) . '</td></tr>' : '') . ' ' . ($order->total_wrapping > 0 ? '<tr><td>' . $this->l('Wrapping') . '</td><td align="right">' . Tools::displayPrice($order->total_wrapping, $currency, false) . '</td></tr>' : '') . ' <tr><td>' . $this->l('Shipping') . '</td><td align="right">' . Tools::displayPrice($order->total_shipping, $currency, false) . '</td></tr> <tr style="font-size: 20px"><td>' . $this->l('Total') . '</td><td align="right">' . Tools::displayPrice($order->total_paid, $currency, false) . ($order->total_paid != $order->total_paid_real ? '<br /><font color="red">(' . $this->l('Paid:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false, false) . ')</font>' : '') . '</td></tr> </table> </div> <div style="float: left; margin-right: 10px; margin-left: 42px;"> <span class="bold">' . $this->l('Recycled package:') . '</span> ' . ($order->recyclable ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . ' </div> <div style="float: left; margin-right: 10px;"> <span class="bold">' . $this->l('Gift wrapping:') . '</span> ' . ($order->gift ? '<img src="../img/admin/enabled.gif" /> </div> <div style="clear: left; margin: 0px 42px 0px 42px; padding-top: 2px;"> ' . (!empty($order->gift_message) ? '<div style="border: 1px dashed #999; padding: 5px; margin-top: 8px;"><b>' . $this->l('Message:') . '</b><br />' . nl2br2($order->gift_message) . '</div>' : '') : '<img src="../img/admin/disabled.gif" />') . ' </div> </fieldset>'; echo '</div> <div class="clear"> </div>'; /* Display adresses : delivery & invoice */ echo '<div class="clear"> </div> <div style="float: left"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/delivery.gif" alt="' . $this->l('Shipping address') . '" />' . $this->l('Shipping address') . '</legend> <div style="float: right"> <a href="?tab=AdminAddresses&id_address=' . $addressDelivery->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=1' : '') . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '"><img src="../img/admin/edit.gif" /></a> <a href="http://maps.google.com/maps?f=q&hl=' . $currentLanguage->iso_code . '&geocode=&q=' . $addressDelivery->address1 . ' ' . $addressDelivery->postcode . ' ' . $addressDelivery->city . ($addressDelivery->id_state ? ' ' . $deliveryState->name : '') . '" target="_blank"><img src="../img/admin/google.gif" alt="" class="middle" /></a> </div> ' . $this->displayAddressDetail($addressDelivery) . (!empty($addressDelivery->other) ? '<hr />' . $addressDelivery->other . '<br />' : '') . '</fieldset> </div> <div style="float: left; margin-left: 40px"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/invoice.gif" alt="' . $this->l('Invoice address') . '" />' . $this->l('Invoice address') . '</legend> <div style="float: right"><a href="?tab=AdminAddresses&id_address=' . $addressInvoice->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=2' : '') . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '"><img src="../img/admin/edit.gif" /></a></div> ' . $this->displayAddressDetail($addressInvoice) . (!empty($addressInvoice->other) ? '<hr />' . $addressInvoice->other . '<br />' : '') . '</fieldset> </div> <div class="clear"> </div>'; // List of products echo ' <a name="products"><br /></a> <form action="' . $currentIndex . '&submitCreditSlip&vieworder&token=' . $this->token . '" method="post" onsubmit="return orderDeleteProduct(\'' . $this->l('Cannot return this product') . '\', \'' . $this->l('Quantity to cancel is greater than quantity available') . '\');"> <input type="hidden" name="id_order" value="' . $order->id . '" /> <fieldset style="width: 868px; "> <legend><img src="../img/admin/cart.gif" alt="' . $this->l('Products') . '" />' . $this->l('Products') . '</legend> <div style="float:left;"> <table style="width: 868px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts"> <tr> <th align="center" style="width: 60px"> </th> <th>' . $this->l('Product') . '</th> <th style="width: 80px; text-align: center">' . $this->l('UP') . ' <sup>*</sup></th> <th style="width: 20px; text-align: center">' . $this->l('Qty') . '</th> ' . ($order->hasBeenPaid() ? '<th style="width: 20px; text-align: center">' . $this->l('Refunded') . '</th>' : '') . ' ' . ($order->hasBeenDelivered() ? '<th style="width: 20px; text-align: center">' . $this->l('Returned') . '</th>' : '') . ' <th style="width: 30px; text-align: center">' . $this->l('Stock') . '</th> <th style="width: 90px; text-align: center">' . $this->l('Total') . ' <sup>*</sup></th> <th colspan="2" style="width: 120px;"><img src="../img/admin/delete.gif" alt="' . $this->l('Products') . '" /> ' . ($order->hasBeenDelivered() ? $this->l('Return') : ($order->hasBeenPaid() ? $this->l('Refund') : $this->l('Cancel'))) . '</th>'; echo ' </tr>'; $tokenCatalog = Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee); foreach ($products as $k => $product) { if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $product_price = $product['product_price'] + $product['ecotax']; } else { $product_price = $product['product_price_wt']; } $image = array(); if (isset($product['product_attribute_id']) and (int) $product['product_attribute_id']) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['product_attribute_id']); } if (!isset($image['id_image']) or !$image['id_image']) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['product_id'] . ' AND cover = 1'); } $stock = Db::getInstance()->getRow(' SELECT ' . ($product['product_attribute_id'] ? 'pa' : 'p') . '.quantity FROM ' . _DB_PREFIX_ . 'product p ' . ($product['product_attribute_id'] ? 'LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON p.id_product = pa.id_product' : '') . ' WHERE p.id_product = ' . (int) $product['product_id'] . ' ' . ($product['product_attribute_id'] ? 'AND pa.id_product_attribute = ' . (int) $product['product_attribute_id'] : '')); if (isset($image['id_image'])) { $target = _PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg'; if (file_exists($target)) { $products[$k]['image_size'] = getimagesize($target); } } // Customization display $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $k); // Normal display if ($product['product_quantity'] > $product['customizationQuantityTotal']) { $quantity = $product['product_quantity'] - $product['customizationQuantityTotal']; $imageObj = new Image($image['id_image']); echo ' <tr' . ((isset($image['id_image']) and isset($products[$k]['image_size'])) ? ' height="' . ($products[$k]['image_size'][1] + 7) . '"' : '') . '> <td align="center">' . (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_ . 'p/' . $imageObj->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg', 45, 'jpg') : '--') . '</td> <td><a href="index.php?tab=AdminCatalog&id_product=' . $product['product_id'] . '&updateproduct&token=' . $tokenCatalog . '"> <span class="productName">' . $product['product_name'] . '</span><br /> ' . ($product['product_reference'] ? $this->l('Ref:') . ' ' . $product['product_reference'] . '<br />' : '') . ($product['product_supplier_reference'] ? $this->l('Ref Supplier:') . ' ' . $product['product_supplier_reference'] : '') . '</a></td> <td align="center">' . Tools::displayPrice($product_price, $currency, false) . '</td> <td align="center" class="productQuantity" ' . ($quantity > 1 ? 'style="font-weight:700;font-size:1.1em;color:red"' : '') . '>' . (int) $quantity . '</td> ' . ($order->hasBeenPaid() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_refunded'] . '</td>' : '') . ' ' . ($order->hasBeenDelivered() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_return'] . '</td>' : '') . ' <td align="center" class="productQuantity">' . (int) $stock['quantity'] . '</td> <td align="center">' . Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int) $product['product_quantity'] - $product['customizationQuantityTotal']), $currency, false) . '</td> <td align="center" class="cancelCheck"> <input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="' . (int) $product['product_quantity_return'] . '" /> <input type="hidden" name="totalQty" id="totalQty" value="' . (int) $product['product_quantity'] . '" /> <input type="hidden" name="productName" id="productName" value="' . $product['product_name'] . '" />'; if ((!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) and (int) $product['product_quantity_return'] < (int) $product['product_quantity']) { echo ' <input type="checkbox" name="id_order_detail[' . $k . ']" id="id_order_detail[' . $k . ']" value="' . $product['id_order_detail'] . '" onchange="setCancelQuantity(this, ' . (int) $product['id_order_detail'] . ', ' . (int) ($product['product_quantity_in_stock'] - $product['customizationQuantityTotal'] - $product['product_quantity_reinjected']) . ')" ' . ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity'] ? 'disabled="disabled" ' : '') . '/>'; } else { echo '--'; } echo ' </td> <td class="cancelQuantity">'; if ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity']) { echo '<input type="hidden" name="cancelQuantity[' . $k . ']" value="0" />'; } elseif (!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="text" id="cancelQuantity_' . (int) $product['id_order_detail'] . '" name="cancelQuantity[' . $k . ']" size="2" onclick="selectCheckbox(this);" value="" /> '; } echo $this->getCancelledProductNumber($order, $product) . ' </td> </tr>'; } } echo ' </table> <div style="float:left; width:280px; margin-top:15px;"><sup>*</sup> ' . $this->l('According to the group of this customer, prices are printed:') . ' ' . ($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')) . (!Configuration::get('PS_ORDER_RETURN') ? '<br /><br />' . $this->l('Merchandise returns are disabled') : '') . '</div>'; if (sizeof($discounts)) { echo ' <div style="float:right; width:280px; margin-top:15px;"> <table cellspacing="0" cellpadding="0" class="table" style="width:100%;"> <tr> <th><img src="../img/admin/coupon.gif" alt="' . $this->l('Discounts') . '" />' . $this->l('Discount name') . '</th> <th align="center" style="width: 100px">' . $this->l('Value') . '</th> </tr>'; foreach ($discounts as $discount) { echo ' <tr> <td>' . $discount['name'] . '</td> <td align="center">' . ($discount['value'] != 0.0 ? '- ' : '') . Tools::displayPrice($discount['value'], $currency, false) . '</td> </tr>'; } echo ' </table></div>'; } echo ' </div>'; // Cancel product echo ' <div style="clear:both; height:15px;"> </div> <div style="float: right; width: 160px;">'; if ($order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="checkbox" id="reinjectQuantities" name="reinjectQuantities" class="button" /> <label for="reinjectQuantities" style="float:none; font-weight:normal;">' . $this->l('Re-stock products') . '</label><br />'; } if (!$order->hasBeenDelivered() and $order->hasBeenPaid() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="checkbox" id="generateCreditSlip" name="generateCreditSlip" class="button" onclick="toogleShippingCost(this)" /> <label for="generateCreditSlip" style="float:none; font-weight:normal;">' . $this->l('Generate a credit slip') . '</label><br /> <input type="checkbox" id="generateDiscount" name="generateDiscount" class="button" onclick="toogleShippingCost(this)" /> <label for="generateDiscount" style="float:none; font-weight:normal;">' . $this->l('Generate a voucher') . '</label><br /> <span id="spanShippingBack" style="display:none;"><input type="checkbox" id="shippingBack" name="shippingBack" class="button" /> <label for="shippingBack" style="float:none; font-weight:normal;">' . $this->l('Repay shipping costs') . '</label><br /></span>'; } if (!$order->hasBeenDelivered() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <div style="text-align:center; margin-top:5px;"><input type="submit" name="cancelProduct" value="' . ($order->hasBeenDelivered() ? $this->l('Return products') : ($order->hasBeenPaid() ? $this->l('Refund products') : $this->l('Cancel products'))) . '" class="button" style="margin-top:8px;" /></div>'; } echo ' </div>'; echo ' </fieldset> </form> <div class="clear" style="height:20px;"> </div>'; /* Display send a message to customer & returns/credit slip*/ $returns = OrderReturn::getOrdersReturn($order->id_customer, $order->id); $slips = OrderSlip::getOrdersSlip($order->id_customer, $order->id); echo ' <div style="float: left"> <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\'' . $this->l('Do you want to send this message to the customer?', __CLASS__, true, false) . '\');"> <fieldset style="width: 400px;"> <legend style="cursor: pointer;" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><img src="../img/admin/email_edit.gif" /> ' . $this->l('New message') . '</legend> <div id="message_m" style="display: ' . (Tools::getValue('message') ? 'none' : 'block') . '; overflow: auto; width: 400px;"> <a href="#" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><b>' . $this->l('Click here') . '</b> ' . $this->l('to add a comment or send a message to the customer') . '</a> </div> <div id="message" style="display: ' . (Tools::getValue('message') ? 'block' : 'none') . '"> <select name="order_message" id="order_message" onchange="orderOverwriteMessage(this, \'' . $this->l('Do you want to overwrite your existing message?') . '\')"> <option value="0" selected="selected">-- ' . $this->l('Choose a standard message') . ' --</option>'; $orderMessages = OrderMessage::getOrderMessages((int) $order->id_lang); foreach ($orderMessages as $orderMessage) { echo ' <option value="' . htmlentities($orderMessage['message'], ENT_COMPAT, 'UTF-8') . '">' . $orderMessage['name'] . '</option>'; } echo ' </select><br /><br /> <b>' . $this->l('Display to consumer?') . '</b> <input type="radio" name="visibility" id="visibility" value="0" /> ' . $this->l('Yes') . ' <input type="radio" name="visibility" value="1" checked="checked" /> ' . $this->l('No') . ' <p id="nbchars" style="display:inline;font-size:10px;color:#666;"></p><br /><br /> <textarea id="txt_msg" name="message" cols="50" rows="8" onKeyUp="var length = document.getElementById(\'txt_msg\').value.length; if (length > 600) length = \'600+\'; document.getElementById(\'nbchars\').innerHTML = \'' . $this->l('600 chars max') . ' (\' + length + \')\';">' . htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8') . '</textarea><br /><br /> <input type="hidden" name="id_order" value="' . (int) $order->id . '" /> <input type="hidden" name="id_customer" value="' . (int) $order->id_customer . '" /> <input type="submit" class="button" name="submitMessage" value="' . $this->l('Send') . '" /> </div> </fieldset> </form>'; /* Display list of messages */ if (sizeof($messages)) { echo ' <br /> <fieldset style="width: 400px;"> <legend><img src="../img/admin/email.gif" /> ' . $this->l('Messages') . '</legend>'; foreach ($messages as $message) { echo '<div style="overflow:auto; width:400px;" ' . ($message['is_new_for_me'] ? 'class="new_message"' : '') . '>'; if ($message['is_new_for_me']) { echo '<a class="new_message" title="' . $this->l('Mark this message as \'viewed\'') . '" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '&messageReaded=' . (int) $message['id_message'] . '"><img src="../img/admin/enabled.gif" alt="" /></a>'; } echo $this->l('At') . ' <i>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true); echo '</i> ' . $this->l('from') . ' <b>' . ($message['elastname'] ? $message['efirstname'] . ' ' . $message['elastname'] : $message['cfirstname'] . ' ' . $message['clastname']) . '</b>'; echo (int) $message['private'] == 1 ? '<span style="color:red; font-weight:bold;">' . $this->l('Private:') . '</span>' : ''; echo '<p>' . nl2br2($message['message']) . '</p>'; echo '</div>'; echo '<br />'; } echo '<p class="info">' . $this->l('When you read a message, please click on the green check.') . '</p>'; echo '</fieldset>'; } echo '</div>'; /* Display return product */ echo '<div style="float: left; margin-left: 40px"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/return.gif" alt="' . $this->l('Merchandise returns') . '" />' . $this->l('Merchandise returns') . '</legend>'; if (!sizeof($returns)) { echo $this->l('No merchandise return for this order.'); } else { foreach ($returns as $return) { $state = new OrderReturnState($return['state']); echo '(' . Tools::displayDate($return['date_upd'], $cookie->id_lang) . ') : <b><a href="index.php?tab=AdminReturn&id_order_return=' . $return['id_order_return'] . '&updateorder_return&token=' . Tools::getAdminToken('AdminReturn' . (int) Tab::getIdFromClassName('AdminReturn') . (int) $cookie->id_employee) . '">' . $this->l('#') . sprintf('%06d', $return['id_order_return']) . '</a></b> - ' . $state->name[$cookie->id_lang] . '<br />'; } } echo '</fieldset>'; /* Display credit slip */ echo ' <br /> <fieldset style="width: 400px;"> <legend><img src="../img/admin/slip.gif" alt="' . $this->l('Credit slip') . '" />' . $this->l('Credit slip') . '</legend>'; if (!sizeof($slips)) { echo $this->l('No slip for this order.'); } else { foreach ($slips as $slip) { echo '(' . Tools::displayDate($slip['date_upd'], $cookie->id_lang) . ') : <b><a href="pdf.php?id_order_slip=' . $slip['id_order_slip'] . '">' . $this->l('#') . sprintf('%06d', $slip['id_order_slip']) . '</a></b><br />'; } } echo '</fieldset> </div>'; echo '<div class="clear"> </div>'; echo '<br /><br /><a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to list') . '</a><br />'; }
FROM `' . _DB_PREFIX_ . 'mr_selected` ms LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_cart` = ms.`id_cart`) WHERE `exp_number` != 0'); if (empty($expeditions)) { exit; } $params = array('Enseigne' => $account_shop['MR_ENSEIGNE_WEBSERVICE'], 'Langue' => 'FR'); require_once dirname(__FILE__) . '/lib/nusoap/nusoap.php'; $client_mr = new nusoap_client("http://www.mondialrelay.fr/webservice/Web_Services.asmx?WSDL", true); $client_mr->soap_defencoding = 'UTF-8'; $client_mr->decode_utf8 = false; foreach ($expeditions as $expedition) { if ($expedition['id_order'] == NULL) { continue; } if (OrderHistory::getLastOrderState((int) $expedition['id_order'])->id == Configuration::get('PS_OS_DELIVERED')) { continue; } $params['Expedition'] = $expedition['exp_number']; $params['Security'] = strtoupper(md5($params['Enseigne'] . $params['Expedition'] . 'FR' . $account_shop['MR_KEY_WEBSERVICE'])); $is_delivered = 0; $result_mr = $client_mr->call('WSI2_TracingColisDetaille', $params, 'http://www.mondialrelay.fr/webservice/', 'http://www.mondialrelay.fr/webservice/WSI2_TracingColisDetaille'); if (isset($result_mr['WSI2_TracingColisDetailleResult']['Tracing']['ret_WSI2_sub_TracingColisDetaille'])) { foreach ($result_mr['WSI2_TracingColisDetailleResult']['Tracing']['ret_WSI2_sub_TracingColisDetaille'] as $result) { if (isset($result['Libelle']) and $result['Libelle'] == 'COLIS LIVRÉ') { $is_delivered = 1; } } } if ($is_delivered == 1) { $history = new OrderHistory();
public function validateOrderAbandoned($params) { $isValidated = true; if (strpos($params['reference'], Configuration::get('PAGSEGURO_ID')) !== false) { $initiated = Util::getStatusCMS(0); $order_state = OrderHistory::getLastOrderState((int) EncryptionIdPagSeguro::decrypt($params['reference'])); if (strcmp($order_state->name, $initiated) != 0) { $isValidated = false; } } else { $isValidated = false; } return $isValidated; }
public static function printPDFIcons($id_order, $tr) { $order = new Order($id_order); $orderState = OrderHistory::getLastOrderState($id_order); if (!Validate::isLoadedObject($orderState) or !Validate::isLoadedObject($order)) { echo ' '; return false; } echo '<span style="width:20px; margin-right:5px;">'; if ($orderState->invoice and $order->invoice_number and (int) $tr['product_number']) { echo '<a href="pdf.php?id_order=' . (int) $order->id . '&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>'; } else { echo ' '; } echo '</span>'; echo '<span style="width:20px;">'; if ($orderState->delivery and $order->delivery_number) { echo '<a href="pdf.php?id_delivery=' . (int) $order->delivery_number . '"><img src="../img/admin/delivery.gif" alt="delivery" /></a>'; } else { echo ' '; } echo '</span>'; }
private function _getOrderData($order) { if (!Validate::isLoadedObject($order)) { return false; } $conversion_rate = 1; if ($order->id_currency != Configuration::get('PS_CURRENCY_DEFAULT')) { $currency = new Currency(intval($order->id_currency)); $conversion_rate = floatval($currency->conversion_rate); } $products = $order->getProducts(); $products_array = array(); foreach ($products as $product) { $product_id = $product['product_id']; if ($product['product_attribute_id']) { $product_id .= 'c' . $product['product_attribute_id']; } $products_array[] = array('product_id' => $product_id, 'qnt' => addslashes(intval($product['product_quantity'])), 'product_name' => addslashes($product['product_name']), 'price' => Tools::ps_round(floatval($product['product_price_wt']) / floatval($conversion_rate), 2)); } $revenue = Tools::ps_round(floatval($order->total_paid) / floatval($conversion_rate), 2); //$shipping = Tools::ps_round(floatval($order->total_shipping) / floatval($conversion_rate), 2); $ret = new stdClass(); $ret->order_id = strval($order->id); $ret->revenue = $revenue; $ret->items = $products_array; $ret->state = OrderHistory::getLastOrderState($order->id); return $ret; }