Skip to content

Instantly share code, notes, and snippets.

@alpharder
Created August 17, 2015 14:23
Show Gist options
  • Save alpharder/46ea04bc0984d0d5cd4f to your computer and use it in GitHub Desktop.
Save alpharder/46ea04bc0984d0d5cd4f to your computer and use it in GitHub Desktop.
diff --git a/app/controllers/frontend/orders.php b/app/controllers/frontend/orders.php
index ae83695..7d7f10a 100644
--- a/app/controllers/frontend/orders.php
+++ b/app/controllers/frontend/orders.php
@@ -501,6 +501,41 @@ function fn_reorder($order_id, &$cart, &$auth)
if ($amount = fn_check_amount_in_stock($v['product_id'], $v['amount'], $v['product_options'], $k, $_is_edp, 0, $cart)) {
$cart['products'][$k]['amount'] = $amount;
+ // Check if the product price with options modifiers equals to zero
+ $price = fn_get_product_price($v['product_id'], $amount, $auth);
+ $zero_price_action = db_get_field("SELECT zero_price_action FROM ?:products WHERE product_id = ?i", $v['product_id']);
+
+ if (!floatval($price) && $zero_price_action == 'A') {
+ if (isset($v['custom_user_price'])) {
+ $price = $v['custom_user_price'];
+ }
+ }
+
+ $price = fn_apply_options_modifiers($v['product_options'], $price, 'P', array(), array('product_data' => $v));
+
+ if (!floatval($price)) {
+ $data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
+
+ if (AREA == 'C'
+ && ($zero_price_action == 'R'
+ ||
+ ($zero_price_action == 'A' && floatval($data['price']) < 0)
+ )
+ ) {
+ if ($zero_price_action == 'A') {
+ fn_set_notification('E', __('error'), __('incorrect_price_warning'));
+ } else {
+ fn_set_notification('W', __('warning'), __('warning_zero_price_restricted_product', array(
+ '[product]' => $v['product']
+ )));
+ }
+
+ unset($cart['products'][$k]);
+
+ continue;
+ }
+ }
+
// Change the path of custom files
if (!empty($v['extra']['custom_files'])) {
foreach ($v['extra']['custom_files'] as $option_id => $_data) {
diff --git a/app/functions/fn.cart.php b/app/functions/fn.cart.php
index 4b97796..49303e0 100644
--- a/app/functions/fn.cart.php
+++ b/app/functions/fn.cart.php
@@ -200,7 +200,10 @@ function fn_get_cart_product_data($hash, &$product, $skip_promotion, &$cart, &$a
}
}
- $product['price'] = ($_pdata['zero_price_action'] == 'A' && isset($product['custom_user_price'])) ? $product['custom_user_price'] : floatval($_pdata['price']);
+ $product['price'] = ($_pdata['zero_price_action'] == 'A' && isset($product['custom_user_price']))
+ ? $product['custom_user_price']
+ : floatval($_pdata['price']);
+
$cart['products'][$hash]['price'] = $product['price'];
$_pdata['original_price'] = $product['price'];
@@ -4824,7 +4827,12 @@ function fn_add_product_to_cart($product_data, &$cart, &$auth, $update = false)
if (!floatval($price)) {
$data['price'] = isset($data['price']) ? fn_parse_price($data['price']) : 0;
- if (($zero_price_action == 'R' || ($zero_price_action == 'A' && floatval($data['price']) < 0)) && AREA == 'C') {
+ if (AREA == 'C'
+ && ($zero_price_action == 'R'
+ ||
+ ($zero_price_action == 'A' && floatval($data['price']) < 0)
+ )
+ ) {
if ($zero_price_action == 'A') {
fn_set_notification('E', __('error'), __('incorrect_price_warning'));
}
diff --git a/var/langs/en/core.po b/var/langs/en/core.po
index 5b0351d..599d9f4 100644
--- a/var/langs/en/core.po
+++ b/var/langs/en/core.po
@@ -15722,8 +15722,8 @@ msgid "Upgraded on"
msgstr "Upgraded on"
msgctxt "Languages::error_unable_to_create_thumbnail"
-msgid "Unable to create thumbnail for file "[file]": [error]"
-msgstr "Unable to create thumbnail for file "[file]": [error]"
+msgid "Unable to create thumbnail for file \"[file]\": [error]"
+msgstr "Unable to create thumbnail for file \"[file]\": [error]"
msgctxt "Languages::cookie_is_disabled"
msgid "For a complete shopping experience, please <a href=\"http://www.wikihow.com/Enable-Cookies-in-Your-Internet-Web-Browser\" target=\"_blank\">set your browser to accept cookies</a>"
@@ -15732,3 +15732,7 @@ msgstr "For a complete shopping experience, please <a href=\"http://www.wikihow.
msgctxt "Languages::uc_restore_email_subject"
msgid "Upgrade center: Store has been backed up and closed."
msgstr "Upgrade center: Store has been backed up and closed."
+
+msgctxt "Languages::warning_zero_price_restricted_product"
+msgid "Product <b>\"[product]\"</b> has not been added to the cart, because it doesn't have a price."
+msgstr "Product <b>\"[product]\"</b> has not been added to the cart, because it doesn't have a price."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment