Пример #1
0
 /**
  * Special page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_special($type = 'best-sellers')
 {
     $types = array('best-sellers' => 24, 'new-release' => 25, 'sale' => 26, 'popular-products' => 1);
     if (!isset($types[$type])) {
         throw new \HttpNotFoundException();
     }
     if (!($group = Model_Group::find_one_by_id($types[$type]))) {
         throw new \HttpNotFoundException();
     }
     if ($type == 'sale') {
         $products = Model_Product::find();
         foreach ($products as $key => $product) {
             if (empty($product->sale_price) || !reset($product->sale_price)->price > 0) {
                 unset($products[$key]);
             }
         }
     } else {
         $products = $group->products;
     }
     $items = $products;
     if ($items) {
         // Price range
         if (\Input::get('range')) {
             $range = explode('-', \Input::get('range'));
             $price_from = isset($range[0]) && is_numeric($range[0]) ? $range[0] : null;
             $price_to = isset($range[1]) && is_numeric($range[1]) ? $range[1] : null;
             if (!is_null($price_from) && !is_null($price_to)) {
                 foreach ($items as $key => $item) {
                     if ($item->default_price[0] >= $price_from && $item->default_price[0] <= $price_to) {
                         continue;
                     }
                     unset($items[$key]);
                 }
             }
         }
     }
     if ($items) {
         if (\Input::get('sort') == 'price_asc') {
             $items = \Product\Model_Product::get_sorted_products($items);
         } elseif (\Input::get('sort') == 'price_desc') {
             $items = array_reverse(\Product\Model_Product::get_sorted_products($items));
         }
     }
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 12), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     \Theme::instance()->set_partial('content', $this->view_dir . 'special')->set('items', $items, false)->set('pagination', $pagination, false)->set('products', $products, false)->set('product_group', $group);
 }
Пример #2
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Group::find_one_by_id($id)) {
             // Delete item
             try {
                 // Delete all relations of this group with products
                 $groups = Model_Product_To_Groups::find_by_group_id($item->id);
                 if (!empty($groups)) {
                     foreach ($groups as $group) {
                         $group->delete();
                     }
                 }
                 $groups = Model_Group_Options::find_by_product_group_id($item->id);
                 if (!empty($groups)) {
                     foreach ($groups as $group) {
                         $group->delete();
                     }
                 }
                 if (!empty($item->images)) {
                     foreach ($item->images as $image) {
                         $this->delete_image($image->image);
                         $image->delete();
                     }
                 }
                 // Delete group
                 $item->delete();
                 \Messages::success('Group successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete group</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }