예제 #1
0
 public function forSelection()
 {
     $term = $this->input->get('q', null, 'default');
     $key = new \MongoRegex('/' . $term . '/i');
     $results = \Shop\Models\Coupons::forSelection(array('title' => $key));
     $response = new \stdClass();
     $response->more = false;
     $response->term = $term;
     $response->results = $results;
     return $this->outputJson($response);
 }
예제 #2
0
파일: Carts.php 프로젝트: dioscouri/f3-shop
 /**
  * Gets the automatic coupons from the cart
  *
  * @return multitype:
  */
 public function autoCoupons($shipping = null)
 {
     if (empty($this->auto_coupons)) {
         return array();
     }
     $coupons = array();
     foreach ($this->auto_coupons as $coupon) {
         $gives_shipping_discount = \Shop\Models\Coupons::givesShippingDiscount($coupon);
         if ($shipping === false) {
             // only the non-shipping coupons
             if ($gives_shipping_discount) {
                 continue;
             } else {
                 $coupons[] = $coupon;
             }
         } elseif ($shipping === true) {
             // only the shipping ones
             if ($gives_shipping_discount) {
                 $coupons[] = $coupon;
             }
         } else {
             // $shipping = null, so give me all of the user coupons
             $coupons[] = $coupon;
         }
     }
     return $coupons;
 }
예제 #3
0
 public function countUsedCodes()
 {
     $result = \Shop\Models\Coupons::collection()->aggregate(array('$match' => array('_id' => new \MongoId((string) $this->id))), array('$unwind' => '$codes.list'), array('$group' => array('_id' => '$title', 'used_codes' => array('$sum' => '$codes.list.used'))));
     if (count($result['result'])) {
         return $result['result'][0]['used_codes'];
     } else {
         return 0;
     }
 }
예제 #4
0
            data: function (term, page) {
                return {
                    q: term
                };
            },
            results: function (data, page) {
                return {results: data.results};
            }
        }
        <?php 
if ($flash->old('required_coupons')) {
    ?>
        , initSelection : function (element, callback) {
            var data = <?php 
    echo json_encode(\Shop\Models\Coupons::forSelection(array('_id' => array('$in' => array_map(function ($input) {
        return new \MongoId($input);
    }, (array) $flash->old('required_coupons'))))));
    ?>
;
            callback(data);            
        }
        <?php 
}
?>
    });

    jQuery("#required_collections").select2({
        allowClear: true, 
        placeholder: "Search...",
        multiple: true,
        minimumInputLength: 3,
예제 #5
0
 /**
  * Displays an order confirmation page
  */
 public function confirmation()
 {
     $just_completed_order_id = \Dsc\System::instance()->get('session')->get('shop.just_completed_order_id');
     if (!empty($just_completed_order_id)) {
         try {
             $order = (new \Shop\Models\Orders())->load(array('_id' => new \MongoId((string) $just_completed_order_id)));
             if (empty($order->id)) {
                 throw new \Exception();
             }
             /**
              * Start Activity Tracking
              */
             $properties = array('order_id' => (string) $order->id, 'order_number' => (string) $order->number, 'Grand Total' => (string) $order->grand_total, 'Credit Total' => (string) $order->credit_total, 'Products' => array(), 'Coupons' => \Dsc\ArrayHelper::getColumn((array) $order->coupons, 'code'), 'Auto Coupons' => \Dsc\ArrayHelper::getColumn((array) $order->auto_coupons, 'code'));
             $identity = $this->getIdentity();
             if ($identity->guest) {
                 $properties['guest'] = true;
             }
             foreach ($order->items as $item) {
                 $product = array();
                 $product['Product Name'] = \Dsc\ArrayHelper::get($item, 'product.title');
                 if (\Dsc\ArrayHelper::get($item, 'attribute_title')) {
                     $product['Variant'] = \Dsc\ArrayHelper::get($item, 'attribute_title');
                 }
                 $properties['Products'][] = $product;
             }
             \Shop\Models\Activities::track('Completed Checkout', $properties);
             $abandoned_cart = \Dsc\System::instance()->get('session')->get('shop.notification_email');
             if ($abandoned_cart == 1) {
                 // checkedout abandoned cart
                 \Shop\Models\Activities::track('Completed Checkout Abandoned Email');
                 \Dsc\System::instance()->get('session')->set('shop.notification_email', 0);
             }
             /**
              * END Activity Tracking
              */
             // check coupons and discard used generated codes
             if (count($order->coupons)) {
                 foreach ($order->coupons as $coupon) {
                     if (!empty($coupon['generated_code'])) {
                         \Shop\Models\Coupons::collection()->update(array('_id' => new \MongoId((string) $coupon['_id']), 'codes.list.code' => (string) $coupon['generated_code']), array('$set' => array('codes.list.$.used' => 1)));
                     }
                 }
             }
             if (count($order->auto_coupons)) {
                 foreach ($order->auto_coupons as $coupon) {
                     if (!empty($coupon['generated_code'])) {
                         \Shop\Models\Coupons::collection()->update(array('_id' => new \MongoId((string) $coupon['_id']), 'codes.list.code' => (string) $coupon['generated_code']), array('$set' => array('codes.list.$.used' => 1)));
                     }
                 }
             }
         } catch (\Exception $e) {
             // TODO Handle when it's an invalid order
         }
         if (!empty($order->id)) {
             \Base::instance()->set('order', $order);
         }
     }
     $this->app->set('meta.title', 'Order Confirmation | Checkout');
     $view = \Dsc\System::instance()->get('theme');
     echo $view->render('Shop/Site/Views::confirmation/index.php');
     \Dsc\System::instance()->get('session')->set('shop.just_completed_order', false);
     \Dsc\System::instance()->get('session')->set('shop.just_completed_order_id', null);
 }
예제 #6
0
 public function deleteCode()
 {
     $id = $this->inputfilter->clean($this->app->get("PARAMS.id"), 'ALNUM');
     $code = $this->inputfilter->clean($this->app->get('PARAMS.code'), 'CMD');
     if (empty($id) || empty($code)) {
         \Dsc\System::addMessage('Missing coupon ID', 'error');
         $this->app->reroute('/admin/shop/coupons');
         return;
     }
     try {
         \Shop\Models\Coupons::collection()->update(array('_id' => new \MongoId((string) $id)), array('$pull' => array('codes.list' => array('code' => $code))), array("upset" => true));
         \Dsc\System::addMessage('Codes was successfuly deleted.');
     } catch (\Exception $e) {
         \Dsc\System::addMessage($e->getMessage(), 'error');
     }
     $this->app->reroute('/admin/shop/coupon/' . $id . '/codes');
 }