Skip to content

Commit

Permalink
store data in aprpriate datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
habibillah committed Jun 15, 2016
1 parent 5cd7706 commit 3be31bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 18 additions & 5 deletions assets/js/admin-woofix.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ jQuery(document).ready(function($) {
var inputWoofixSelector = 'input[name="_woofix"]';

var regenerateData = function() {
var data = $(woofixPriceTableSelector + ' :input').serializeJSON();
var data = $(woofixPriceTableSelector + ' :input').serializeJSON({
"customTypes": {
"woodecimal": function (value) {
return window.accounting.unformat(value, woocommerce_admin.mon_decimal_point);
}
}
});
$(inputWoofixSelector).val(JSON.stringify(data));
};

var regenerateIndex = function() {
$(woofixPriceTableSelector).find('tbody tr').each(function(index) {
$(this).find('[data-name]').each(function() {
var inputName = 'woofix[' + index + '][' + $(this).data('name') + ']';
var name = $(this).data('name');
var inputName = 'woofix[' + index + '][' + name + ']';
if (name === "woofix_disc" || name === "woofix_price")
inputName += ":woodecimal";

if (name === "woofix_qty")
inputName += ":number";

$(this).attr('name', inputName);
$(this).attr('id', inputName);
});
Expand Down Expand Up @@ -76,8 +89,8 @@ jQuery(document).ready(function($) {
var row = $('#woofix_template').find('tr').clone();
row.find('input[data-name="woofix_desc"]').val(value['woofix_desc']);
row.find('input[data-name="woofix_qty"]').val(value['woofix_qty']);
row.find('input[data-name="woofix_disc"]').val(value['woofix_disc']);
row.find('input[data-name="woofix_price"]').val(value['woofix_price']);
row.find('input[data-name="woofix_disc"]').val(formatNumberTosave(value['woofix_disc']));
row.find('input[data-name="woofix_price"]').val(formatNumberTosave(value['woofix_price']));
row.appendTo('#woofix_price_table tbody');
});

Expand Down Expand Up @@ -127,7 +140,7 @@ jQuery(document).ready(function($) {
$(woofixPriceTableSelector).on('change', 'input[name*="woofix_qty"]', function() {
var newVal = $(this).val();
if (newVal == "" || isNaN(newVal) || parseInt(newVal) < 0) {
newVal = 0;
newVal = 1;
}

$(this).val(parseInt(newVal));
Expand Down
10 changes: 5 additions & 5 deletions classes/client-fixed-quantity-price.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function filter_woocommerce_cart_item_quantity($input_html, $cart_item_ke
$input_html = '<select name="cart[' . $cart_item_key . '][qty]" class="input-text qty text woofix_qty_on_cart">';
foreach ($fixedPriceData['woofix'] as $item) {

$woofix_price = wc_format_decimal($item['woofix_price']);
$woofix_price = $item['woofix_price'];
$woofix_qty = $item['woofix_qty'];
$woofix_desc = empty($item['woofix_desc'])? '' : $item['woofix_desc'];

Expand Down Expand Up @@ -142,7 +142,7 @@ public function filter_item_price($price, $cart_item, $cart_item_key)
$discount = 0;
foreach ($fixedPriceData['woofix'] as $disc) {
if ($disc['woofix_qty'] == $cart_item['quantity']) {
$discount = wc_format_decimal($disc['woofix_disc']);
$discount = $disc['woofix_disc'];
}
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public function action_before_calculate_totals(WC_Cart $cart)
if ($fixedPriceData !== false) {
foreach ($fixedPriceData['woofix'] as $data) {
if ($data['woofix_qty'] == $cart_item['quantity']) {
$cart_item['data']->set_price(floatval(wc_format_decimal($data['woofix_price'])));
$cart_item['data']->set_price(floatval($data['woofix_price']));
}
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public function filter_subtotal_price($price, $cart_item)

foreach ($fixedPriceData['woofix'] as $disc) {
if ($disc['woofix_qty'] == $cart_item['quantity']) {
$discount = wc_format_decimal($disc['woofix_disc']);
$discount = $disc['woofix_disc'];
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ public function order_formatted_line_subtotal($price, $product)

foreach ($fixedPriceData['woofix'] as $disc) {
if ($disc['woofix_qty'] == $product['qty']) {
$discount = wc_format_decimal($disc['woofix_disc']);
$discount = $disc['woofix_disc'];
}
}

Expand Down

0 comments on commit 3be31bd

Please sign in to comment.