Esempio n. 1
0
 /**
  * Store new item in cart
  * @return Response
  */
 public function store()
 {
     // Find entry
     $id = Input::get('id');
     $entry = $this->entries->find($id);
     if ($entry) {
         // Get quantity and price
         $qty = (int) Input::get('qty', 1);
         $price = (double) $entry->field('price');
         // Prepare the item
         $item = array('id' => $id, 'title' => $entry->title, 'price' => $price, 'quantity' => $qty);
         // Add some content data
         if ($image = $entry->field('image')) {
             $item['image'] = $image;
         }
         // Add to cart
         if ($qty >= 1 and $price) {
             Cart::add($item);
         }
         // Respond
         $response = array('result' => 'ok');
     } else {
         $response = array('result' => 'error');
     }
     // Build response
     return Response::json(array_merge($response, array('item_count' => Cart::quantity(), 'total_price' => Cart::total())));
 }
Esempio n. 2
0
 /**
  * Collection of entries in taxonomy by term
  * @param  string $term
  * @return View
  */
 public function entryTaxonomyCollection($term)
 {
     Profiler::start('FINDER - ENTRY TAXONOMY COLLECTION');
     // First get taxonomy
     $taxonomy = app('krustr.taxonomies')->findBySlug(Request::segment(2));
     if ($taxonomy) {
         $term = $this->termRepository->findBySlug($term);
         if ($term) {
             $entries = $this->entryRepository->allPublishedByTerm($term->id, $this->channel->resource);
         } else {
             return App::abort(404);
         }
         View::share('term', $term);
     } else {
         return App::abort(404);
     }
     // Share content
     View::share('entries', $entries);
     View::share('pagination', $this->entryRepository->pagination());
     View::share('taxonomy', $taxonomy);
     // Views that we need to search for
     $views = array($this->channel->name . '_' . $taxonomy->name_singular, $this->channel->name . '_taxonomy', $taxonomy->name_singular, 'taxonomy_' . $taxonomy->name_singular, $this->channel->resource_singular . '_collection', $this->channel->resource, $this->channel->resource . '_collection', 'taxonomy', 'collection', 'index');
     Profiler::end('FINDER - ENTRY TAXONOMY COLLECTION');
     // The view
     return $this->render($views);
 }
Esempio n. 3
0
 /**
  * Return all terms for taxonomy
  * @param  string $taxonomyId
  * @return TermCollection
  */
 public function terms($taxonomyId = null)
 {
     if (!$taxonomyId) {
         $key = 'all';
     } else {
         $key = $taxonomyId;
     }
     if (!isset($this->taxonomyTerms[$key])) {
         $this->taxonomyTerms[$key] = $this->entryRepository->terms($this->id, $taxonomyId);
     }
     return $this->taxonomyTerms[$key];
 }