Skip to content

Commit

Permalink
https://github.com/opencart/opencart/issues/11458
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Oct 29, 2024
1 parent 7f49281 commit 5ccf34e
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 166 deletions.
8 changes: 4 additions & 4 deletions upload/catalog/controller/account/address.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function save(): void {
}

if (isset($this->request->get['address_id']) && ($this->customer->getAddressId() == $this->request->get['address_id']) && !$this->request->post['default']) {
$json['error'] = $this->language->get('error_default');
$json['error']['warning'] = $this->language->get('error_default');
}
}

Expand All @@ -386,6 +386,8 @@ public function save(): void {
$this->model_account_address->addAddress($this->customer->getId(), $this->request->post);

$this->session->data['success'] = $this->language->get('text_add');

$json['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}

// Edit Address
Expand All @@ -412,10 +414,8 @@ public function save(): void {
unset($this->session->data['payment_methods']);
}

$this->session->data['success'] = $this->language->get('text_edit');
$json['success'] = $this->language->get('text_edit');
}

$json['redirect'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}

$this->response->addHeader('Content-Type: application/json');
Expand Down
4 changes: 1 addition & 3 deletions upload/catalog/controller/account/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function save(): void {
// Update customer in db
$this->model_account_customer->editCustomer($this->customer->getId(), $this->request->post);

$this->session->data['success'] = $this->language->get('text_success');
$json['success'] = $this->language->get('text_success');

// Update customer session details
$this->session->data['customer'] = [
Expand All @@ -176,8 +176,6 @@ public function save(): void {
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);

$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
}

$this->response->addHeader('Content-Type: application/json');
Expand Down
4 changes: 1 addition & 3 deletions upload/catalog/controller/account/newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public function save(): void {

$this->model_account_customer->editNewsletter($this->customer->getId(), $this->request->post['newsletter']);

$this->session->data['success'] = $this->language->get('text_success');

$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
$json['success'] = $this->language->get('text_success');
}

$this->response->addHeader('Content-Type: application/json');
Expand Down
81 changes: 45 additions & 36 deletions upload/catalog/controller/account/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ public function getHistory(): string {
public function reorder(): void {
$this->load->language('account/order');

$json = [];

if (isset($this->request->get['order_id'])) {
$order_id = (int)$this->request->get['order_id'];
} else {
Expand All @@ -462,9 +464,9 @@ public function reorder(): void {
}

if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
$this->session->data['redirect'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language'));
$this->session->data['redirect'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language'));

$this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
$json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
}

$this->load->model('account/order');
Expand All @@ -475,49 +477,56 @@ public function reorder(): void {
$order_product_info = $this->model_account_order->getProduct($order_id, $order_product_id);

if ($order_product_info) {
$this->load->model('catalog/product');

$product_info = $this->model_catalog_product->getProduct($order_product_info['product_id']);

if ($product_info) {
$option_data = [];

$order_options = $this->model_account_order->getOptions($order_id, $order_product_id);

foreach ($order_options as $order_option) {
if ($order_option['type'] == 'select' || $order_option['type'] == 'radio' || $order_option['type'] == 'image') {
$option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'checkbox') {
$option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
} elseif ($order_option['type'] == 'file') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
}
}

$subscription_info = $this->model_account_order->getSubscription($order_id, $order_product_id);
if (!$product_info) {
$json['error'] = $this->language->get('error_product');
}
} else {
$json['error'] = $this->language->get('error_product');
}
} else {
$json['error'] = $this->language->get('error_order');
}

if ($subscription_info) {
$subscription_plan_id = $subscription_info['subscription_plan_id'];
} else {
$subscription_plan_id = 0;
}
if (!$json) {
$this->load->model('catalog/product');

$this->cart->add($order_product_info['product_id'], $order_product_info['quantity'], $option_data, $subscription_plan_id);
$option_data = [];

$this->session->data['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_info['product_id']), $product_info['name'], $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language')));
$order_options = $this->model_account_order->getOptions($order_id, $order_product_id);

unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
} else {
$this->session->data['error'] = sprintf($this->language->get('error_reorder'), $order_product_info['name']);
foreach ($order_options as $order_option) {
if ($order_option['type'] == 'select' || $order_option['type'] == 'radio' || $order_option['type'] == 'image') {
$option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'checkbox') {
$option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
} elseif ($order_option['type'] == 'file') {
$option_data[$order_option['product_option_id']] = $order_option['value'];
}
}

$subscription_info = $this->model_account_order->getSubscription($order_id, $order_product_id);

if ($subscription_info) {
$subscription_plan_id = $subscription_info['subscription_plan_id'];
} else {
$subscription_plan_id = 0;
}

$this->cart->add($order_product_info['product_id'], $order_product_info['quantity'], $option_data, $subscription_plan_id);

$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product_info['product_id']), $product_info['name'], $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language')));

unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
}

$this->response->redirect($this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $order_id, true));
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
4 changes: 1 addition & 3 deletions upload/catalog/controller/account/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public function save(): void {

$this->model_account_customer->editPassword($this->customer->getEmail(), $this->request->post['password']);

$this->session->data['success'] = $this->language->get('text_success');

$json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
$json['success'] = $this->language->get('text_success');
}

$this->response->addHeader('Content-Type: application/json');
Expand Down
13 changes: 6 additions & 7 deletions upload/catalog/language/en-gb/account/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$_['text_payment_address'] = 'Payment Address';
$_['text_shipping_method'] = 'Shipping Method';
$_['text_payment_method'] = 'Payment Method';
$_['text_model'] = 'Model';
$_['text_subscription'] = 'Subscription';
$_['text_subscription_trial'] = '%s every %d %s(s) for %d payment(s) then ';
$_['text_subscription_duration'] = '%s every %d %s(s) for %d payment(s)';
Expand All @@ -22,27 +23,25 @@
$_['text_month'] = 'month';
$_['text_year'] = 'year';
$_['text_points'] = 'Reward Points';

$_['text_comment'] = 'Order Comments';
$_['text_history'] = 'Order History';
$_['text_success'] = 'Success: You have added <a href="%s">%s</a> to your <a href="%s">shopping cart</a>!';

$_['text_no_results'] = 'You have not made any previous orders!';
$_['text_error'] = 'The order you requested could not be found!';

// Column
$_['column_order_id'] = 'Order ID';
$_['column_customer'] = 'Customer';
$_['column_product'] = 'No. of Products';
$_['column_total'] = 'No. of Products';
$_['column_product'] = 'Product';
$_['column_status'] = 'Status';
$_['column_total'] = 'Total';
$_['column_date_added'] = 'Date Added';
$_['column_name'] = 'Product Name';
$_['column_model'] = 'Model';
$_['column_quantity'] = 'Quantity';
$_['column_price'] = 'Price';
$_['column_comment'] = 'Comment';

$_['column_action'] = 'Action';

// Error
$_['error_reorder'] = '%s is not currently available to be reordered.';
$_['error_order'] = 'Warning: Order could not be found!';
$_['error_product'] = 'Warning: Product could not be found!';
8 changes: 4 additions & 4 deletions upload/catalog/language/en-gb/checkout/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
$_['text_remove'] = 'Success: You have removed an item from your shopping cart!';
$_['text_login'] = 'Attention: You must <a href="%s">login</a> or <a href="%s">create an account</a> to view prices!';
$_['text_no_results'] = 'Your shopping cart is empty!';
$_['text_next'] = 'What would you like to do next?';
$_['text_next_choice'] = 'Choose if you have a discount code or reward points you want to use or would like to estimate your delivery cost.';
$_['text_points'] = 'Reward Points';
$_['text_model'] = 'Model';
$_['text_subscription'] = 'Subscription';
$_['text_subscription_trial'] = '%s every %d %s(s) for %d payment(s) then ';
$_['text_subscription_duration'] = '%s every %d %s(s) for %d payment(s)';
Expand All @@ -20,11 +18,13 @@
$_['text_semi_month'] = 'half-month';
$_['text_month'] = 'month';
$_['text_year'] = 'year';
$_['text_points'] = 'Reward Points';
$_['text_next'] = 'What would you like to do next?';
$_['text_next_choice'] = 'Choose if you have a discount code or reward points you want to use or would like to estimate your delivery cost.';

// Column
$_['column_image'] = 'Image';
$_['column_name'] = 'Product Name';
$_['column_model'] = 'Model';
$_['column_quantity'] = 'Quantity';
$_['column_price'] = 'Unit Price';
$_['column_total'] = 'Total';
Expand Down
14 changes: 7 additions & 7 deletions upload/catalog/language/en-gb/checkout/confirm.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
// Text
$_['text_points'] = 'Reward Points';
$_['text_subscription'] = 'Subscription';
$_['text_model'] = 'Model';
$_['text_subscription'] = 'Subscription';
$_['text_points'] = 'Reward Points';

// Column
$_['column_name'] = 'Product Name';
$_['column_model'] = 'Model';
$_['column_quantity'] = 'Quantity';
$_['column_price'] = 'Unit Price';
$_['column_total'] = 'Total';
$_['column_product'] = 'Product';
$_['column_quantity'] = 'Quantity';
$_['column_price'] = 'Unit Price';
$_['column_total'] = 'Total';
4 changes: 2 additions & 2 deletions upload/catalog/language/en-gb/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
$_['button_login'] = 'Login';
$_['button_update'] = 'Update';
$_['button_remove'] = 'Remove';
$_['button_reorder'] = 'Reorder';
$_['button_return'] = 'Return';
$_['button_reorder'] = 'Buy Again';
$_['button_return'] = 'Return Item';
$_['button_shopping'] = 'Continue Shopping';
$_['button_search'] = 'Search';
$_['button_submit'] = 'Submit';
Expand Down
Loading

0 comments on commit 5ccf34e

Please sign in to comment.