Skip to content

Instantly share code, notes, and snippets.

@edavydova
Last active March 19, 2020 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edavydova/81c268fdd94a242a4202ec1d25e44b30 to your computer and use it in GitHub Desktop.
Save edavydova/81c268fdd94a242a4202ec1d25e44b30 to your computer and use it in GitHub Desktop.
diff --git a/app/addons/rma/func.php b/app/addons/rma/func.php
index b72f699cb2..f0ee3cb824 100644
--- a/app/addons/rma/func.php
+++ b/app/addons/rma/func.php
@@ -1194,3 +1194,30 @@ function fn_rma_get_returns($params, $items_per_page = 0, $lang_code = CART_LANG
return array($return_requests, $params);
}
+
+/**
+ * The "form_cart_pre_fill" hook handler.
+ *
+ * Actions performed:
+ * - Removes info about returns if order is copied
+ *
+ * @see fn_form_cart()
+ */
+function fn_rma_form_cart_pre_fill($order_id, $cart, $auth, &$order_info, $copy)
+{
+ if (!$copy || empty($order_info['products'])) {
+ return;
+ }
+
+ foreach ($order_info['products'] as &$product) {
+ if (empty($product['returns_info'])) {
+ continue;
+ }
+
+ unset($product['returns_info']);
+ if (!empty($product['extra']['returns'])) {
+ unset($product['extra']['returns']);
+ }
+ }
+ unset($product);
+}
\ No newline at end of file
diff --git a/app/addons/rma/init.php b/app/addons/rma/init.php
index 1fe2ce8054..4a9ff3dca3 100644
--- a/app/addons/rma/init.php
+++ b/app/addons/rma/init.php
@@ -25,5 +25,6 @@ fn_register_hooks(
'get_status_params_definition',
'delete_order',
'paypal_get_ipn_order_ids',
- 'reorder_product'
+ 'reorder_product',
+ 'form_cart_pre_fill'
);
diff --git a/app/functions/fn.cart.php b/app/functions/fn.cart.php
index 457b3d37ed..f2ca576bf8 100644
--- a/app/functions/fn.cart.php
+++ b/app/functions/fn.cart.php
@@ -6121,10 +6121,13 @@ function fn_add_product_to_cart($product_data, &$cart, &$auth, $update = false)
/**
* Forms cart based on order
- * @param integer $order_id order ID
- * @param array &$cart cart
- * @param array &$auth auth info
- * @param boolean $copy if true, create new order, otherwise edit
+ *
+ * @param integer $order_id Order ID
+ * @param array $cart Cart
+ * @param array $auth Auth info
+ * @param bool $copy True if creating new order, otherwise edit
+ *
+ * @return bool True if success, false otherwise
*/
function fn_form_cart($order_id, &$cart, &$auth, $copy = false)
{
@@ -6143,8 +6146,9 @@ function fn_form_cart($order_id, &$cart, &$auth, $copy = false)
* @param array $cart Cart data
* @param array $auth Auth information
* @param array $order_info Order info
+ * @param bool $copy If true, create new order, otherwise edit
*/
- fn_set_hook('form_cart_pre_fill', $order_id, $cart, $auth, $order_info);
+ fn_set_hook('form_cart_pre_fill', $order_id, $cart, $auth, $order_info, $copy);
// Fill the cart
foreach ($order_info['products'] as $_id => $item) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment