Exemple #1
0
 public function submitGiftCard()
 {
     //get the giftcards from the database
     $giftCard = \CI::GiftCards()->getGiftCard(\CI::input()->post('gift_card'));
     if (!$giftCard) {
         echo json_encode(['error' => lang('gift_card_not_exist')]);
     } else {
         //does the giftcard have any value left?
         if (\CI::GiftCards()->isValid($giftCard)) {
             $message = \GC::addGiftCard($giftCard);
             if ($message['success']) {
                 \GC::saveCart();
                 echo json_encode(['message' => lang('gift_card_balance_applied')]);
             } else {
                 echo json_encode($message);
             }
         } else {
             echo json_encode(['error' => lang('gift_card_zero_balance')]);
         }
     }
 }
Exemple #2
0
 public function setShippingMethod()
 {
     $rates = \GC::getShippingMethodOptions();
     $hash = \CI::input()->post('method');
     foreach ($rates as $key => $rate) {
         $test = md5(json_encode(['key' => $key, 'rate' => $rate]));
         if ($hash == $test) {
             \GC::setShippingMethod($key, $rate, $hash);
             //save the cart
             \GC::saveCart();
             echo json_encode(['success' => true]);
             return false;
         }
     }
     echo json_encode(['error' => lang('shipping_method_is_no_longer_valid')]);
 }