Exemple #1
0
    ?>
                                
                    <form action="./shop/cart/add" method="post">
                        <div id="validation-cart-add" class="validation-message"></div>
                        
                        <div class="buttons">
                            <div class="row">
                                <?php 
    if (!empty($item->variantsInStock()) && count($item->variantsInStock()) > 1) {
        ?>
                                <div class="col-sm-8">
                                    
                                    <select name="variant_id" class="chosen-select select-variant variant_id" data-callback="Shop.selectVariant">
                                        <?php 
        foreach ($variantsInStock as $key => $variant) {
            $wishlist_state = \Shop\Models\Wishlists::hasAddedVariant($variant['id'], (string) $this->auth->getIdentity()->id) ? '0' : '1';
            ?>
                                            <option value="<?php 
            echo $variant['id'];
            ?>
" data-variant='<?php 
            echo htmlspecialchars(json_encode(array('id' => $variant['id'], 'key' => $variant['key'], 'image' => $variant['image'], 'quantity' => $variant['quantity'], 'price' => \Shop\Models\Currency::format($item->price($variant['id'])))));
            ?>
'
                                            	data-wishlist="<?php 
            echo $wishlist_state;
            ?>
"><?php 
            echo $variant['attribute_title'] ? $variant['attribute_title'] : $item->title;
            ?>
 </option>
Exemple #2
0
 /**
  * Remove an item from the wishlist
  */
 public function remove()
 {
     $f3 = \Base::instance();
     // -----------------------------------------------------
     // Start: validation
     // -----------------------------------------------------
     // TODO validate the POST values
     // min: wishlistitem_hash
     $wishlistitem_hash = $this->inputfilter->clean($f3->get('PARAMS.wishlistitem_hash'), 'cmd');
     // TODO if validation fails, respond appropriately
     if ($f3->get('AJAX')) {
     } else {
     }
     // -----------------------------------------------------
     // End: validation
     // -----------------------------------------------------
     // get the current user's wishlist, either based on session_id (visitor) or user_id (logged-in)
     $wishlist = \Shop\Models\Wishlists::fetch();
     // remove the item
     try {
         $wishlist->removeItem($wishlistitem_hash);
     } catch (\Exception $e) {
         // TODO respond appropriately with failure message
         // return;
     }
     //echo \Dsc\Debug::dump( $wishlist );
     // TODO respond appropriately
     // ajax?  send response object
     // otherwise redirect to wishlist
     if ($f3->get('AJAX')) {
     } else {
         \Dsc\System::addMessage('Item removed from wishlist');
         $f3->reroute('/shop/wishlist');
     }
 }
Exemple #3
0
 /**
  * Get the current user's cart
  *
  * @return \Shop\Models\Carts
  */
 public static function fetchForUser()
 {
     $cart = new static();
     $identity = \Dsc\System::instance()->get('auth')->getIdentity();
     $session_id = \Dsc\System::instance()->get('session')->id();
     if (!empty($identity->id)) {
         $cart->load(array('user_id' => new \MongoId((string) $identity->id)));
         $cart->user_id = $identity->id;
         $session_cart = static::fetchForSession();
         // if there was a user cart and there is a session cart, push all products in user cart to their wishlist
         if (!empty($session_cart->items) && !empty($cart->id) && $session_cart->id != $cart->id) {
             $wishlist = \Shop\Models\Wishlists::fetch();
             $wishlist->merge($cart->cast());
             $cart->remove();
             $cart = $session_cart;
             $cart->user_id = $identity->id;
             $cart->save();
             \Dsc\System::addMessage("All products from your previous cart were moved to your wishlist");
         }
         // if there was no user cart but there IS a session cart, just add the user_id to the session cart and save it
         if (empty($cart->id) && !empty($session_cart->id)) {
             $cart = $session_cart;
             $cart->user_id = $identity->id;
             $cart->save();
         }
     }
     return $cart;
 }