opnh Posted October 5, 2016 Share Posted October 5, 2016 I have created a voucher from only customer group access in prestashop 1.6 and we credited the account with rs.5000 and each time the customer places an order 10% discount amount has to be deducted from 5000 and it should be work respectively I have done with the functionality by developing the custom module and it is working now. But when the credit amount 5000 becomes 0(zero) rupees the voucher has to be disabled to the particular customer SO how to give the condition in order to disable the voucher for the particular customer using id_cart_rule Below is the code public static function gcashId() { $name = $_POST['name']; $gcashId= json_encode($name); $new_Ids = Db::getInstance()->executeS('SELECT cr.id_cart_rule FROM '._DB_PREFIX_.'cart_rule cr WHERE cr.code = '.$gcashId.''); if (!empty($new_Ids) AND is_array($new_Ids)) { foreach ($new_Ids AS $key => $new_Id) { $new_Ids[$key]['id_cart_rule']; } $idget_gcash= json_encode((int)$new_Ids[$key]['id_cart_rule']); } $ordergcashs = Db::getInstance()->executeS(' SELECT ocr.id_order FROM '._DB_PREFIX_.'order_cart_rule ocr WHERE ocr.id_cart_rule = '.$idget_gcash.''); foreach ($ordergcashs as $ordergcash) { // $ordergcashs[$key]['id_order']; } if(Context::getContext()->customer->isLogged()) { $customer = Context::getContext()->customer; $quantityUsed = (int) Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'orders p JOIN ' . _DB_PREFIX_ . 'order_cart_rule od ON p.id_order = od.id_order WHERE p.id_customer = ' . $customer->id .' AND od.id_cart_rule = ' . $idget_gcash . ''); //echo json_encode($quantityUsed); $voucher_Used= json_encode($quantityUsed); //echo $voucher_Used; $getDisamont = Db::getInstance()->executeS(' SELECT oq.total_discounts,oq.id_order FROM '._DB_PREFIX_.'orders oq JOIN ' . _DB_PREFIX_ . 'order_cart_rule roc ON oq.id_order = roc.id_order WHERE oq.id_customer = ' . $customer->id .' AND roc.id_cart_rule = '.$idget_gcash.''); //echo json_encode($getDisamont); $amountneed= json_encode($getDisamont); //echo $amountneed; foreach($getDisamont as $product){ // echo $product['total_discounts']; //will print each product handle // $product_handles[] = $product['handle'] //will create array of product handles } //echo $product['total_discounts']; $min_discount=$product['total_discounts']; $mini_order_id= $product['id_order']; //echo $min_discount; $deduction=5000.00000-$min_discount; //echo $deduction; if($voucher_Used==1) { Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'loyalty SET points = "'.$deduction.'" WHERE id_customer = ' . $customer->id .''); } //$getabc=Db::getInstance()->Affected_Rows(); // echo json_encode($getabc); else if($voucher_Used>1) { $last_discountid = Db::getInstance()->executeS(' SELECT d.points,d.id_order FROM '._DB_PREFIX_.'loyalty d WHERE d.id_customer = '.$customer->id .' ORDER BY d.id_loyalty DESC LIMIT 1, 1'); foreach($last_discountid as $getdis){ } $discount_bomb=$getdis['points']; //$discount_bomb=$getdis['points']; $new_update= $discount_bomb-$min_discount; $getlastid_order= Db::getInstance()->executeS(' SELECT e.points FROM '._DB_PREFIX_.'loyalty e WHERE e.id_customer = '.$customer->id .''); foreach($getlastid_order as $newgetid){ } $xyzc=$newgetid['points']; Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'loyalty SET points = "'.$new_update.'" WHERE id_customer = ' . $customer->id .' AND id_order = ' . $mini_order_id .''); } if($xyzc==0) { $cartrule_id = Db::getInstance()->executeS(' SELECT tm.code FROM '._DB_PREFIX_.'cart_rule tm WHERE tm.id_cart_rule = '.$idget_gcash .''); foreach($cartrule_id as $partgcash){ } $dynamic_part=$partgcash['code']; } } echo $dynamic_part; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now