public function saveShipping() { $orderItemId = isset($_REQUEST['orderItemId']) ? $_REQUEST['orderItemId'] : null; $shipping = isset($_REQUEST['shipping']) ? $_REQUEST['shipping'] : null; if (!$this->isValidOrderItemId($orderItemId)) { $this->getResponse()->addHeader("HTTP/1.0 400 Bad request"); } else { $orderItem = OrderItemDAO::getInstance()->getOrderItem($orderItemId); $orderItem->setShippingCost($shipping); OrderItemDAO::getInstance()->saveOrderItem($orderItem, true); } $this->getResponse()->setOutput(''); }
private function validateDelete() { if (!$this->user->hasPermission('modify', 'catalog/product')) { $this->getSession()->data['notifications']['warning'] = $this->language->get('error_permission'); } elseif (!$this->parameters['confirm']) { foreach ($this->parameters['selectedItems'] as $productId) { $productsCount = OrderItemDAO::getInstance()->getOrderItemsCount(array("filterProductId" => $productId)); if ($productsCount) { $this->getSession()->data['notifications']['confirm']['text'] .= "{$productId} => {$productsCount}"; } } if (isset($this->getSession()->data['notifications']['confirm'])) { $this->getSession()->data['notifications']['confirm']['title'] = $this->language->get('TITLE_DELETION_CONFIRM'); $this->getSession()->data['notifications']['confirm']['urlYes'] = $this->selfUrl . '&confirm=1'; $this->getSession()->data['notifications']['confirm']['text'] = $this->language->get('DELETION_CONFIRM') . $this->getSession()->data['notifications']['confirm']['text']; } } if (empty($this->getSession()->data['notifications'])) { return true; } else { return false; } }
public function saveComment() { // $this->log->write(print_r($this->parameters, true)); if (!$this->isValidOrderItemId($this->parameters['orderItemId'])) { $this->getResponse()->addHeader("HTTP/1.0 400 Bad request"); } else { OrderItemDAO::getInstance()->setOrderItemComment($this->parameters['orderItemId'], $this->parameters['comment'], $this->parameters['private']); } $this->getResponse()->setOutput(''); }
/** * @return string */ public function getTimeModified() { if (!isset($this->timeModified)) { $this->timeModified = OrderItemDAO::getInstance()->getTimeModified($this->id); } return $this->timeModified; }
public function orderItemsHistory() { $orderItems = OrderItemDAO::getInstance()->getOrderItems(array('filterCustomerId' => array($this->parameters['customerId'])), null, true); $this->data = array(); $this->data['events'] = array(); foreach ($orderItems as $orderItem) { $orderItemHistory = OrderItemDAO::getInstance()->getOrderItemHistory($orderItem->getId()); // $this->log->write(print_r($orderItemHistory, true)); foreach ($orderItemHistory as $orderItemHistoryEntry) { $this->data['events'][] = array('orderId' => $orderItem->getOrderId(), 'orderItemId' => $orderItem->getId(), 'eventDate' => $orderItemHistoryEntry['date_added'], 'statusName' => $orderItemHistoryEntry['name']); } } $this->data['textOrderId'] = $this->language->get('ORDER_ID'); $this->data['textOrderItemId'] = $this->language->get('ORDER_ITEM_ID'); $this->data['textEventDate'] = $this->language->get('DATE'); $this->data['textStatusName'] = $this->language->get('STATUS'); $this->template = 'sale/customerOrderItemsHistory.php'; $result = $this->render(); $json = array('content' => $result); // $this->log->write(print_r($json, true)); $this->getResponse()->setOutput(json_encode($json)); }
public function updateOrderTotals($order_id) { $order = $this->getOrder($order_id); $orderItemStatusModel = $this->load->model('localisation/order_item_status'); $total_price = 0; $total_weight = 0; $orderItems = $this->getOrderProducts($order_id); foreach ($orderItems as $item) { $query = $this->getDb()->query("SELECT product_id FROM product WHERE product_id = '" . (int) $item['product_id'] . "'")->row['product_id']; if (empty($query)) { $deleted = 1; } } foreach ($orderItems as $order_item) { $orderItemStatus = $orderItemStatusModel->getOrderItemStatus($order_item['status_id']); if ($orderItemStatus['workflow_order'] != 1000) { $orderItem = OrderItemDAO::getInstance()->getOrderItem($order_item['order_product_id']); if (!empty($orderItem)) { $total_price += $order_item['total']; $total_weight += $this->weight->convert($orderItem->getWeight(), $orderItem->getWeightClassId(), $this->config->get('config_weight_class_id')) * $order_item['quantity']; } } } $shipping_cost = $this->getShippingCost($order['shipping_method'], $orderItems, array('weight' => $total_weight)); if ($order['total'] != $total_price + $shipping_cost && !$deleted) { $this->getDb()->query("UPDATE order_total SET value = {$total_price}, text = '" . $this->currency->format($total_price) . "' WHERE order_id = {$order_id} AND code = 'sub_total'"); $this->getDb()->query("UPDATE order_total SET value = {$shipping_cost}, text = '" . $this->currency->format($shipping_cost) . "' WHERE order_id = {$order_id} AND code = 'shipping'"); $this->getDb()->query("UPDATE order_total SET value = " . ($total_price + $shipping_cost) . ", text = '" . $this->currency->format($total_price + $shipping_cost) . "' WHERE order_id = {$order_id} AND code = 'total'"); $this->getDb()->query("UPDATE `order` SET total = " . ($total_price + $shipping_cost) . " WHERE order_id = {$order_id}"); } }
public function invoice() { $this->load->language('account/order'); $this->data['title'] = $this->language->get('heading_title'); if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { $this->data['base'] = HTTPS_SERVER; } else { $this->data['base'] = HTTP_SERVER; } $this->data['direction'] = $this->language->get('direction'); $this->data['language'] = $this->language->get('code'); $this->data['text_invoice'] = $this->language->get('text_invoice'); $this->data['text_order_id'] = $this->language->get('text_order_id'); $this->data['text_invoice_no'] = $this->language->get('text_invoice_no'); $this->data['text_invoice_date'] = $this->language->get('text_invoice_date'); $this->data['text_date_added'] = $this->language->get('text_date_added'); $this->data['text_telephone'] = $this->language->get('text_telephone'); $this->data['text_fax'] = $this->language->get('text_fax'); $this->data['text_to'] = $this->language->get('text_to'); $this->data['text_ship_to'] = $this->language->get('text_ship_to'); $this->data['column_product'] = $this->language->get('column_product'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['column_comment'] = $this->language->get('column_comment'); $this->load->model('account/order'); $this->load->model('setting/setting'); $this->data['orders'] = array(); $orders = array(); if (isset($this->request->get['order_id'])) { $order_id = $this->request->get['order_id']; } $order_info = $this->model_account_order->getOrder($order_id); if ($order_info) { $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']); if ($store_info) { $store_address = $store_info['config_address']; $store_email = $store_info['config_email']; $store_telephone = $store_info['config_telephone']; $store_fax = $store_info['config_fax']; } else { $store_address = $this->config->get('config_address'); $store_email = $this->config->get('config_email'); $store_telephone = $this->config->get('config_telephone'); $store_fax = $this->config->get('config_fax'); } if ($order_info['invoice_no']) { $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no']; } else { $invoice_no = ''; } if ($order_info['shipping_address_format']) { $format = $order_info['shipping_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']); $shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); if ($order_info['payment_address_format']) { $format = $order_info['payment_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']); $payment_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); $product_data = array(); // $products = $this->model_account_order->getOrderProducts($order_id); $orderItems = OrderItemDAO::getInstance()->getOrderItems(array('filterOrderId' => $order_id), null, true); foreach ($orderItems as $orderItem) { $option_data = array(); $options = $this->model_account_order->getOrderOptions($order_id, $orderItem->getId()); foreach ($options as $option) { if ($option['type'] != 'file') { $option_data[] = array('name' => $option['name'], 'value' => $option['value']); } else { $option_data[] = array('name' => $option['name'], 'value' => utf8_substr($option['value'], 0, strrpos($option['value'], '.'))); } } $product_data[] = array('name' => $orderItem->getName(), 'model' => $orderItem->getModel(), 'option' => $option_data, 'quantity' => $orderItem->getQuantity(), 'price' => $this->currency->format($orderItem->getPrice(true), $order_info['currency_code'], 1), 'total' => $this->currency->format($orderItem->getTotal(true), $order_info['currency_code'], 1)); } $total_data = $this->model_account_order->getOrderTotals($order_id); $this->data['orders'][] = array('order_id' => $order_id, 'invoice_no' => $invoice_no, 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])), 'store_name' => $order_info['store_name'], 'store_url' => rtrim($order_info['store_url'], '/'), 'store_address' => nl2br($store_address), 'store_email' => $store_email, 'store_telephone' => $store_telephone, 'store_fax' => $store_fax, 'email' => $order_info['email'], 'telephone' => $order_info['telephone'], 'shipping_address' => $shipping_address, 'payment_address' => $payment_address, 'product' => $product_data, 'total' => $total_data, 'comment' => nl2br($order_info['comment'])); } $templateFileName = '/template/account/order_invoice.tpl'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateFileName)) { $this->template = $this->config->get('config_template') . $templateFileName; } else { $this->template = 'default' . $templateFileName; } $this->getResponse()->setOutput($this->render()); }
/** * @param OrderItem $orderItem * @param array $localShipping * @return array */ private function calculateLocalShipping($orderItem, $localShipping) { if (array_key_exists($orderItem->getSupplierId(), $localShipping)) { $localShipping[$orderItem->getSupplierId()]['total'] += $orderItem->getTotal(); $orderItem->setShippingCost(0); OrderItemDAO::getInstance()->saveOrderItem($orderItem, true); } else { $localShipping[$orderItem->getSupplierId()]['orderItem'] = $orderItem; $localShipping[$orderItem->getSupplierId()]['total'] = $orderItem->getTotal(); $orderItem->setShippingCost($orderItem->getSupplier()->getShippingCost()); } return $localShipping; }
private function getList() { $ordersPerPage = 10; $this->data['orders'] = array(); $this->data['statuses'] = Status::getStatuses(GROUP_REPURCHASE_ORDER_ITEM_STATUS, $this->config->get('language_id'), true); $data = $this->parameters; $data['filterCustomerId'] = $this->getCurrentCustomer()->getId(); unset($data['page']); $data['start'] = ($this->parameters['page'] - 1) * $ordersPerPage; // $this->config->get("config_catalog_limit"); $data['limit'] = $ordersPerPage; // $this->config->get("config_catalog_limit"); $data['order'] = 'DESC'; foreach (RepurchaseOrderDAO::getInstance()->getOrders($data) as $repurchase_order) { if (file_exists(DIR_IMAGE . $repurchase_order['imagePath'])) { $imagePath = $this->load->model('tool/image')->resize($repurchase_order['imagePath'], 100, 100); $warningHint = ''; } else { $imagePath = $this->load->model('tool/image')->resize('no_image.jpg', 100, 100); $warningHint = $this->language->get('WARNING_HTML_PAGE_PROVIDED'); } if ($repurchase_order['status'] == REPURCHASE_ORDER_ITEM_STATUS_OFFER) { $textAccept = $this->language->get('ACCEPT'); } else { if ($repurchase_order['status'] == REPURCHASE_ORDER_ITEM_STATUS_WAITING) { $textAccept = $this->language->get('UNCONDITIONALLY_ACCEPT'); } else { $textAccept = null; } } $this->data['orders'][] = array('comment' => $repurchase_order['comment'], 'hint' => $warningHint, 'orderItemId' => $repurchase_order['orderItemId'], 'imagePath' => $imagePath, 'imageUrl' => $repurchase_order['imagePath'], 'itemUrl' => $repurchase_order['itemUrl'], 'options' => OrderItemDAO::getInstance()->getOptions($repurchase_order['orderItemId']), 'price' => $this->currency->format($repurchase_order['price']), 'quantity' => $repurchase_order['quantity'], 'shipping' => $this->currency->format($repurchase_order['shipping']), 'statusId' => $repurchase_order['status'], 'statusName' => Status::getStatus($repurchase_order['status'], $this->config->get('config_language_id'), true), 'timeAdded' => $repurchase_order['timeAdded'], 'subtotal' => $this->currency->format($repurchase_order['subtotal']), 'textAccept' => $textAccept, 'total' => $this->currency->format($repurchase_order['total'])); } // $this->log->write(print_r($this->data['orders'], true)); /// Set interface $this->setBreadcrumbs(); $this->data['textComment'] = $this->language->get('COMMENT'); $this->data['textFilter'] = $this->language->get('FILTER'); $this->data['textFilterBy'] = $this->language->get('FILTER_BY'); $this->data['textTimeAdded'] = $this->language->get('TIME_ADDED'); $this->data['textNoItems'] = $this->language->get('NO_ITEMS'); $this->data['textOrderItemId'] = $this->language->get('ORDER_ITEM_ID'); $this->data['textPrice'] = $this->language->get('PRICE'); $this->data['textQuantity'] = $this->language->get('QUANTITY'); $this->data['textReject'] = $this->language->get('REJECT'); $this->data['textShipping'] = $this->language->get('SHIPPING'); $this->data['textStatus'] = $this->language->get('STATUS'); $this->data['textSubtotal'] = $this->language->get('SUBTOTAL'); $this->data['textAddToCart'] = $this->language->get('ADDTOCART'); $this->data['textTotal'] = $this->language->get('TOTAL'); $this->data['urlRepurchaseOrders'] = $this->url->link('account/repurchaseOrders', '', 'SSL'); $template_name = '/template/account/repurchaseOrdersList.tpl.php'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $template_name)) { $this->template = $this->config->get('config_template') . $template_name; } else { $this->template = 'default' . $template_name; } $this->children = array('common/column_right', 'common/column_left', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $filterParams = array(); foreach ($this->parameters as $key => $value) { if (!(strpos($key, 'filter') === false)) { $filterParams[$key] = $value; } } $urlFilterParameters = $this->buildUrlParameterString($filterParams); $urlParameters = $urlFilterParameters . '&page=' . $this->parameters['page']; $pagination = new Pagination(); $pagination->total = RepurchaseOrderDAO::getInstance()->getOrdersCount($data); $pagination->page = $this->parameters['page']; $pagination->limit = $ordersPerPage; //$this->config->get("config_catalog_limit"); $pagination->text = $this->language->get('text_pagination'); $pagination->url = $this->url->link('account/repurchaseOrders', str_replace('page=' . $this->parameters['page'], 'page={page}', $urlParameters), 'SSL'); $this->data['pagination'] = $pagination->render(); $this->data = array_merge($this->data, $this->parameters); $this->getResponse()->setOutput($this->render()); }
/** * @param int $repurchaseOrderId * @param string $imagePath */ public function setImage($repurchaseOrderId, $imagePath) { $this->getDb()->query("\n UPDATE order_option\n SET value = :imagePath\n WHERE\n order_product_id = :orderProductId\n AND product_option_id = " . REPURCHASE_ORDER_IMAGE_URL_OPTION_ID, array(":imagePath" => $imagePath, ":orderProductId" => $repurchaseOrderId)); if (!$this->getDb()->countAffected()) { $orderItem = OrderItemDAO::getInstance()->getOrderItem($repurchaseOrderId); $this->getDb()->query("\n INSERT INTO order_option\n SET\n order_id = :orderId,\n order_product_id = :orderProductId,\n product_option_id = " . REPURCHASE_ORDER_IMAGE_URL_OPTION_ID . ",\n product_option_value_id = 0,\n name = 'Image URL',\n value = :imagePath,\n type = 'text'\n ", array(":orderProductId" => $repurchaseOrderId, ":orderId" => $orderItem->getOrderId(), ":imagePath" => $imagePath)); } }
public function showForm() { // $this->log->write(print_r($this->session, true)); if (is_null($this->getRequest()->getParam('invoiceId'))) { return; } $modelOrderItem = $this->load->model('account/order_item'); $modelReferenceAddress = $this->load->model('reference/address'); $invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId')); /// Initialize interface values $this->data['headingTitle'] = sprintf($this->language->get('INVOICE'), $invoice->getId()); $this->data['button_action'] = $this->language->get('button_close'); $this->data['submit_action'] = $this->url->link('account/invoice/close', '', 'SSL'); $this->data['textComment'] = $this->language->get('textComment'); $this->data['textConfirm'] = $this->language->get('CONFIRM'); $this->data['textDiscount'] = $this->language->get('DISCOUNT'); $this->data['textGrandTotal'] = $this->language->get('textGrandTotal'); $this->data['textItemImage'] = $this->language->get('textItemImage'); $this->data['textItemName'] = $this->language->get('textItemName'); $this->data['textOrderId'] = $this->language->get('textOrderId'); $this->data['textOrderItemId'] = $this->language->get('textOrderItemId'); $this->data['textPackageNumber'] = $this->language->get('PACKAGE_NUMBER'); $this->data['textPrice'] = $this->language->get('textPrice'); $this->data['textQuantity'] = $this->language->get('textQuantity'); $this->data['textShippingAddress'] = $this->language->get('textShippingAddress'); $this->data['textShippingCost'] = $this->language->get('textShippingCost'); $this->data['textShippingMethod'] = $this->language->get('textShippingMethod'); $this->data['textSubtotal'] = $this->language->get('SUBTOTAL'); $this->data['textTotal'] = $this->language->get('TOTAL'); $this->data['textWeight'] = $this->language->get('WEIGHT'); $temp = $invoice->getCustomer(); if ($temp['customer_id'] != $this->getCurrentCustomer()->getId()) { $invoice = null; $this->data['notifications']['error'] = $this->language->get('errorAccessDenied'); } else { /// Prepare list $subTotalCustomerCurrency = 0; foreach ($invoice->getOrderItems() as $orderItem) { $this->data['orderItems'][] = array('id' => $orderItem->getId(), 'comment' => $orderItem->getPublicComment(), 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem->getImagePath()), 'model' => $orderItem->getModel(), 'name' => $orderItem->getName(), 'options' => OrderItemDAO::getInstance()->getOrderItemOptionsString($orderItem->getId()), 'order_id' => $orderItem->getOrderId(), 'price' => $orderItem->getCurrency()->getString($orderItem->getPrice(true)), 'quantity' => $orderItem->getQuantity(), 'shipping' => $orderItem->getCurrency()->getString($orderItem->getShippingCost(true)), 'subtotal' => $orderItem->getCurrency()->getString($orderItem->getTotal(true))); $subTotalCustomerCurrency += $orderItem->getTotal(true); } // foreach ($this->data['orderItems'] as $item) { // $ids[] = $item['id']; // } // // $_invoice = InvoiceDAO::getInstance()->getInvoice($this->getRequest()->getParam('invoiceId')); // // foreach (InvoiceDAO::getInstance()->getInvoiceItems($_invoice->getId()) as $invoiceItem) { // if (!in_array($invoiceItem['order_item_id'], $ids)) { // $orderItem = $this->model_account_order->getOrderProduct($invoiceItem['order_item_id']); // // $this->data['orderItems'][] = array( // 'id' => $orderItem['order_product_id'], // 'comment' => $orderItem['public_comment'], // 'image_path' => $this->registry->get('model_tool_image')->getImage($orderItem['image_path']), // 'model' => $orderItem['model'], // 'name' => $orderItem['name'], // 'options' => $modelOrderItem->getOrderItemOptionsString($orderItem['order_product_id']), // 'order_id' => $orderItem['order_id'], // 'price' => $this->getCurrency()->format($orderItem['price']), // 'quantity' => $orderItem['quantity'], // 'subtotal' => $this->getCurrency()->format($orderItem['price'] * $orderItem['quantity']) // ); // } // } /// Set invoice data $this->data['invoiceId'] = $invoice->getId(); $this->data['comment'] = $invoice->getComment(); $this->data['discount'] = $this->getCurrency()->format($invoice->getDiscount(), $this->getCurrentCustomer()->getBaseCurrency()); $this->data['packageNumber'] = $invoice->getPackageNumber(); $this->data['shippingAddress'] = nl2br($modelReferenceAddress->toString($invoice->getShippingAddressId())); $this->data['shippingCost'] = $this->getCurrency()->format($invoice->getShippingCost()); $this->data['shippingMethod'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $invoice->getShippingMethod())[0])->getName(); $this->data['status'] = $this->load->model('localisation/invoice')->getInvoiceStatus($invoice->getStatusId(), $this->session->data['language_id']); $this->data['statusId'] = $invoice->getStatusId(); $this->data['total'] = $this->getCurrency()->format($subTotalCustomerCurrency, $this->getCurrentCustomer()->getBaseCurrency(), 1); $this->data['totalWeight'] = $invoice->getWeight(); $this->data['grandTotal'] = $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $this->getCurrentCustomer()->getBaseCurrency(), 1); } $templateName = '/template/account/invoiceForm.tpl.php'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateName)) { $this->template = $this->config->get('config_template') . $templateName; } else { $this->template = 'default' . $templateName; } $this->setBreadcrumbs(); $this->children = array('common/header', 'common/footer', 'common/content_top', 'common/content_bottom', 'common/column_left', 'common/column_right'); $this->getResponse()->setOutput($this->render()); }