Merge branch 'ticket-fidelite' into develop

This commit is contained in:
Marion Muszynski 2016-04-22 16:21:48 +02:00
commit bb15d1e81b
2 changed files with 23 additions and 24 deletions

View File

@ -206,9 +206,9 @@ class LoyaltyModule extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.id_order = o.id_order)
LEFT JOIN `'._DB_PREFIX_.'loyalty_state_lang` fsl ON (f.id_loyalty_state = fsl.id_loyalty_state AND fsl.id_lang = '.(int)($id_lang).')
WHERE f.id_customer = '.(int)($id_customer).'
AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
'.(($onlyValidate)?'':' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId());
if ($onlyValidate) {
$query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getValidationId();
$query .= ' AND (f.id_loyalty_state = '.(int)LoyaltyStateModule::getCancelId().' OR f.id_loyalty_state = '.(int)LoyaltyStateModule::getValidationId().')';
} elseif ($onlyDefault){
$query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getDefaultId();
}

View File

@ -514,15 +514,20 @@ class Loyalty extends Module
FROM '._DB_PREFIX_.'order_detail od
WHERE id_order_detail = '.(int)($detail['id_order_detail']));
$totalPrice += number_format($price_wt, 2, '.', '') * $detail['product_quantity'];
$totalPrice += number_format($price_wt, 2, '.', '') * ($detail['product_quantity'] - $detail['product_quantity_refunded']);
}
$id_loyalty = LoyaltyModule::getByOrderId((int)($params['orderReturn']->id));
if ($id_loyalty) {
$loyalty = new LoyaltyModule((int)$id_loyalty);
$loyalty->discount_value = LoyaltyModule::getDiscountValueByPrice($totalPrice);
echo "<pre>";var_dump('hookorderreturn',$loyalty->discount_value);echo "</pre>";die();
if ($loyalty->discount_value<=0) {
$loyalty->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
}
$loyalty->id_order = (int)$params['orderReturn']->id_order;
$loyalty->id_customer = (int)$params['orderReturn']->id_customer;
$loyalty->save();
}
$loyaltyNew = new LoyaltyModule();
$loyaltyNew->discount_value = -1 * (LoyaltyModule::getDiscountValueByPrice($totalPrice));
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
$loyaltyNew->id_order = (int)$params['orderReturn']->id_order;
$loyaltyNew->id_customer = (int)$params['orderReturn']->id_customer;
$loyaltyNew->save();
}
/* Hook display on shopping cart summary */
@ -615,10 +620,10 @@ class Loyalty extends Module
die(Tools::displayError('Incorrect object Customer.'));
$details = LoyaltyModule::getAllByIdCustomer((int)$params['id_customer'], (int)$params['cookie']->id_lang);
//$valid_orders = LoyaltyModule::getAllByIdCustomerCustom((int)$params['id_customer'], (int)$params['cookie']->id_lang, true, false, $nb = 10, $page = 1, false);
$valid_orders = LoyaltyModule::getAllByIdCustomerCustom((int)$params['id_customer'], (int)$params['cookie']->id_lang, true, false, $nb = 10, $page = 1, false);
if (!empty($details)) {
$discount_value = LoyaltyModule::getVoucherValueByPercentOfOrder($details, (int)Configuration::get('PS_CURRENCY_DEFAULT'));
if (!empty($valid_orders)) {
$discount_value = LoyaltyModule::getVoucherValueByPercentOfOrder($valid_orders, (int)Configuration::get('PS_CURRENCY_DEFAULT'));
} else {
$discount_value = 0;
}
@ -675,20 +680,14 @@ class Loyalty extends Module
return false;
}
$loyaltyNew = new LoyaltyModule();
$price = ($params['order']->total_paid - $params['order']->total_shipping) - (number_format($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100), 2, '.', '') * $orderDetail->product_quantity);
$price = (number_format($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100), 2, '.', '') * ($orderDetail->product_quantity - $orderDetail->product_quantity_refunded));
if ($price>0) {
$loyaltyNew->discount_value = -1 * LoyaltyModule::getDiscountValueByPrice($price);
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getDefaultId();
$loyalty->discount_value = LoyaltyModule::getDiscountValueByPrice($price);
} else {
$loyaltyNew->discount_value = 0;
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
$loyalty->discount_value = 0;
$loyalty->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
}
$loyaltyNew->id_order = (int)$params['order']->id;
$loyaltyNew->id_customer = (int)$loyalty->id_customer;
$loyaltyNew->add();
$loyalty->save();
return;
}