コード例 #1
0
 protected function show($slug = false)
 {
     if (isset($sorting)) {
         Model_Category::$sorting = $sorting;
     }
     if ($category = Model_Category::get_by_slug($slug)) {
         // TODO delete this
         srand($category->id);
         $items = null;
         $parent_category = null;
         if ($category->parent_id == 0) {
             $view_file = 'category';
             // Categories
             $items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
         } else {
             $view_file = 'subcategory';
             // Products
             $items = $category->products;
             $parent_category = Model_Category::find_one_by_id($category->parent_id);
         }
         \Helper::sorting($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', 15), '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 . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('pagination', $pagination, false);
     } else {
         throw new \HttpNotFoundException();
     }
 }
コード例 #2
0
 protected function show($slug = false)
 {
     if (isset($sorting)) {
         Model_Category::$sorting = $sorting;
     }
     if ($category = Model_Category::get_by_slug($slug)) {
         // TODO delete this
         srand($category->id);
         $items = null;
         $parent_category = null;
         if ($category->parent_id == 0) {
             $view_file = 'category';
             // Categories
             $items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
             if (!$items) {
                 $view_file = 'subcategory';
                 $items = $category->products;
             }
         } else {
             $view_file = 'subcategory';
             // Products
             $items = $category->products;
             // echo '<pre>';
             // print_r($items);
             // echo '</pre>';
             $parent_category = Model_Category::find_one_by_id($category->parent_id);
         }
         \Helper::sorting($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', 15), 'uri_segment' => null));
         // Remove unwanted items, and show only required ones
         $items = array_slice($items, $pagination->offset, $pagination->per_page);
         $category_parents = false;
         if ($parent_category) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents($category->parent_id, $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         $stock_options = \Config::load('stock-option.db');
         \Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('category_parents', $category_parents, false)->set('pagination', $pagination, false)->set('manage_stock', $stock_options['manage_stock'], false)->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false);
         \View::set_global('title', $category->seo->meta_title ?: $category->title);
         \View::set_global('meta_description', $category->seo->meta_description ?: '');
         \View::set_global('meta_keywords', $category->seo->meta_keywords ?: '');
         $robots = array('meta_robots_index' => $category->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $category->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
         \View::set_global('robots', $robots);
         \View::set_global('canonical', $category->seo->canonical_links);
         \View::set_global('h1_tag', $category->seo->h1_tag);
         if ($category->seo->redirect_301) {
             \Response::redirect($category->seo->redirect_301);
         }
     } else {
         throw new \HttpNotFoundException();
     }
 }
コード例 #3
0
ファイル: group.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_list()
 {
     \View::set_global('title', 'List groups');
     // Get all groups and remove admin groups from array
     $items = \Sentry::group()->all('front');
     // 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', 10), '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 . 'list')->set('items', $items)->set('pagination', $pagination, false);
 }
コード例 #4
0
ファイル: product.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_myproducts()
 {
     $products = \Product\Model_Product::filter_by_group();
     // Products
     $items = array();
     if ($products) {
         $items = Model_Product::find(array('where' => array(array('id', 'in', array_keys($products['assigned'])))), 'id');
     }
     $category = null;
     $parent_category = null;
     // 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', 15), '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 . 'subcategory')->set('page_title', 'My Products', false)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('pagination', $pagination, false);
 }
コード例 #5
0
ファイル: team.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items()
 {
     /************ Start generating query ***********/
     $items = Model_Team::find(function ($query) {
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where('name', 'like', "%{$value}%");
                         break;
                     case 'featured':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '>=', $date);
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '<=', $date);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }
コード例 #6
0
ファイル: group.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_products_assigned($id = false)
 {
     if (!is_numeric($id)) {
         \Response::redirect('admin/product/group/list');
     }
     // Get group to edit
     if (!($item = Model_Group::find_one_by_id($id))) {
         \Response::redirect('admin/product/group/list');
     }
     \View::set_global('title', 'Edit Group Products');
     // Update group products
     if (\Input::post()) {
         $add = \Input::post('products.add', array());
         $remove = \Input::post('products.remove', array());
         $update = \Input::post('products.update', array());
         if (\Input::post('add', false)) {
             foreach ($add as $value) {
                 $related = Model_Product_To_Groups::forge(array('group_id' => $item->id, 'product_id' => $value));
                 $related->save();
                 // NRB-Gem: Get current Customer Group for this Pricing Group
                 $product_group_option = \Product\Model_Group_Options::find_one_by(array('active' => 1, 'product_group_id' => $id));
                 $user_group_id = null;
                 if ($product_group_option) {
                     $user_group_id = $product_group_option->user_group_id;
                 }
                 // NRB-Gem: add attributes
                 $a_attributes = \Product\Model_Attribute::find(function ($query) use($value) {
                     $query->where('product_id', '=', $value);
                     $query->where('active', '=', 1);
                 });
                 $a_attribute_ids = array();
                 if (count($a_attributes)) {
                     foreach ($a_attributes as $o_attr) {
                         $o_attr_price = new Model_Attribute_Price(array('product_attribute_id' => $o_attr->id, 'pricing_group_id' => $item->id, 'user_group_id' => $user_group_id, 'type' => 'sale_price'));
                         $o_attr_price->save();
                     }
                 }
             }
             \Messages::success('Products successfully added to group.');
         } else {
             if (\Input::post('remove', false)) {
                 foreach ($remove as $value) {
                     $related = Model_Product_To_Groups::find_one_by(array(array('group_id', '=', $item->id), array('product_id', '=', $value)));
                     if (!is_null($related)) {
                         $related->delete();
                         // NRB-Gem: remove attributes
                         $a_attributes = \Product\Model_Attribute::find(function ($query) use($value) {
                             $query->where('product_id', '=', $value);
                         });
                         $a_attribute_ids = array();
                         if (count($a_attributes)) {
                             foreach ($a_attributes as $o_attr) {
                                 $a_attribute_ids[] = $o_attr->id;
                             }
                         }
                         if (count($a_attribute_ids)) {
                             \DB::delete('product_attribute_price')->where('product_attribute_id', 'IN', \DB::expr('(' . implode(',', $a_attribute_ids) . ')'))->where('pricing_group_id', '=', $item->id)->execute();
                         }
                     }
                 }
                 \Messages::success('Products successfully removed from group.');
             }
         }
         if (!empty($update)) {
             foreach ($update['discount'] as $key => $value) {
                 if (isset($update['attr_id'][$key])) {
                     foreach ($update['attr_id'][$key] as $attribute_id) {
                         $update_sale_price = Model_Attribute_Price::find_one_by(array(array('product_attribute_id', '=', $attribute_id), array('pricing_group_id', '=', $item->id)));
                         if ($update_sale_price) {
                             $update_sale_price->set(array('discount' => $update['discount'][$key][$attribute_id], 'able_discount' => $update['able_discount'][$key][$attribute_id], 'price' => $update['price'][$key][$attribute_id]));
                             $update_sale_price->save();
                         }
                     }
                 } else {
                     $prod_attributes = \Product\Model_Attribute::find_by_product_id($key);
                     $attribute_id = $prod_attributes[0]->id;
                     $o_attr_price_list = Model_Attribute_Price::find_one_by(array(array('product_attribute_id', '=', $attribute_id), array('pricing_group_id', '<>', $item->id)));
                     if ($o_attr_price_list) {
                         $o_attr_price_list->delete();
                     }
                     $update_sale_price = Model_Attribute_Price::find_one_by(array(array('product_attribute_id', '=', $attribute_id), array('pricing_group_id', '=', $item->id)));
                     if ($update_sale_price) {
                         $update_sale_price->set(array('discount' => $update['discount'][$key], 'able_discount' => $update['able_discount'][$key], 'price' => $update['price'][$key]));
                         $update_sale_price->save();
                     }
                 }
             }
             \Messages::success('Products successfully updated.');
         }
         // if(\Input::is_ajax())
         // {
         // 	echo \Messages::display('left', false);
         // 	exit;
         // }
         // else
         // {
         \Response::redirect(\Input::referrer(\Uri::admin('current')));
         // }
     }
     $group = Model_Group::find_one_by_id($id);
     /************ Get non related infotabs ***********/
     $items = Model_Product::find(function ($query) use($item) {
         $product_ids = array();
         // NRB-Gem: Comment out, to enable multiple pricing groups for a product
         // Products can be in only ONE discounted group
         // But can exist in MULTIPLE standard groups
         // if($item->type == 'pricing')
         // {
         // 	$discounted_products = Model_Product::in_group_type('pricing');
         // 	foreach($discounted_products as $product)
         // 		array_push($product_ids, $product->id);
         // }
         foreach ($item->products as $product) {
             array_push($product_ids, $product->id);
         }
         if (!empty($product_ids)) {
             $product_ids = '(' . implode(',', $product_ids) . ')';
             $query->where('id', 'NOT IN', \DB::expr($product_ids));
         }
         // Filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'category_id':
                         if (is_numeric($value)) {
                             $products = Model_Product_To_Categories::find(function ($query) use($value) {
                                 return $query->where('category_id', $value);
                             }, 'product_id');
                             if (empty($products)) {
                                 $products = array(0);
                             }
                             $query->where('id', 'IN', array_keys($products));
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     $group->not_related_products = null;
     $not_related_products = $items ? $items : array();
     // product_group_options
     $customer_groups = Model_Group_Options::find_by(array('active' => 1, 'product_group_id' => $id));
     $customer_group = array();
     if ($customer_groups) {
         $customer_group = Model_Customer_Group::find_one_by_id($customer_groups[0]->user_group_id);
     }
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     \Theme::instance()->set_partial('content', $this->view_dir . 'products_assigned')->set('group', $group, false)->set('items', $items, false)->set('pagination', $pagination, false)->set('status', $status, false)->set('customer_group', $customer_group, false);
 }
コード例 #7
0
ファイル: user.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items($group_id = false)
 {
     // Override group_id if its a search
     $group_id = \Input::get('user_group', $group_id);
     if ($group_id && \Sentry::group_exists((int) $group_id)) {
         // Get only group users
         \View::set_global('group', \Sentry::group((int) $group_id));
         $items = \Sentry::group((int) $group_id)->users();
     } else {
         $items = \Sentry::user()->all('admin');
     }
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Get user objects
     if (!empty($items)) {
         foreach ($items as $key => $item) {
             $items[$key] = \Sentry::user((int) $item['id']);
         }
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         foreach ($items as $number => $item) {
                             if (empty($item['metadata'])) {
                                 unset($items[$number]);
                                 continue;
                             }
                             $full_name = $item->get('metadata.first_name') . ' ' . $item->get('metadata.last_name');
                             if (stripos($full_name, $value) === false) {
                                 unset($items[$number]);
                             }
                         }
                         break;
                     case 'email':
                         foreach ($items as $number => $item) {
                             if (stripos($item->email, $value) === false) {
                                 unset($items[$number]);
                             }
                         }
                         break;
                     case 'country':
                         if ($value && $value !== 'false') {
                             foreach ($items as $number => $item) {
                                 if (empty($item['metadata'])) {
                                     unset($items[$number]);
                                     continue;
                                 }
                                 if (stripos($item->get('metadata.country'), $value) === false) {
                                     unset($items[$number]);
                                 }
                             }
                         }
                         break;
                     case 'postcode_from':
                         foreach ($items as $number => $item) {
                             if (empty($item['metadata'])) {
                                 unset($items[$number]);
                                 continue;
                             }
                             if ($item->get('metadata.postcode') < $value) {
                                 unset($items[$number]);
                             }
                         }
                         break;
                     case 'postcode_to':
                         foreach ($items as $number => $item) {
                             if (empty($item['metadata'])) {
                                 unset($items[$number]);
                                 continue;
                             }
                             if ($item->get('metadata.postcode') > $value) {
                                 unset($items[$number]);
                             }
                         }
                         break;
                 }
             }
         }
     }
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     return array('items' => $items, 'pagination' => $pagination);
 }
コード例 #8
0
ファイル: product.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items($category_id = false)
 {
     // Override category_id if its a search
     $category_id = \Input::get('category_id', $category_id);
     $product_ids = array();
     // If we are viewing category products
     // We need to find all products from that and child categories
     if (is_numeric($category_id)) {
         $category = \Product\Model_Category::find_one_by_id($category_id);
         if ($category) {
             \View::set_global('category', $category);
             if ($category->all_products) {
                 $product_ids = array_keys($category->all_products);
             }
         }
     }
     // If we are filtering products by category and there is nothing found
     // We return empty array of products without even going to database
     if (empty($product_ids) && is_numeric($category_id)) {
         $items = array();
     } else {
         /************ Start generating query ***********/
         $items = Model_Product::find(function ($query) use($product_ids) {
             if (!empty($product_ids)) {
                 $query->where('id', 'in', $product_ids);
             }
             // Get search filters
             foreach (\Input::get() as $key => $value) {
                 if (!empty($value) || $value == '0') {
                     switch ($key) {
                         case 'title':
                             $query->where($key, 'like', "%{$value}%")->or_where('code', 'like', "%{$value}%");
                             break;
                         case 'status':
                             if (is_numeric($value)) {
                                 $query->where($key, $value);
                             }
                             break;
                         case 'active_from':
                             $date = strtotime($value);
                             if ($date) {
                                 $query->where($key, '>=', $date);
                             }
                             break;
                         case 'active_to':
                             $date = strtotime($value);
                             if ($date) {
                                 $query->where($key, '<=', $date);
                             }
                             break;
                     }
                 }
             }
             // Order query
             $query->order_by('sort', 'asc');
             $query->order_by('id', 'asc');
         });
     }
     /************ End generating query ***********/
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }
コード例 #9
0
 public function get_search_items($user_id = false)
 {
     // Override group_id if its a search
     $user_id = \Input::get('user_id', $user_id);
     if ($user_id && \Sentry::user_exists((int) $user_id)) {
         $user = \Sentry::user((int) $user_id);
     }
     $items = \Order\Model_Order::find(function ($query) {
         if (isset($user)) {
             $query->where('user_id', $user->id);
         }
         // $query->order_by('main_number', 'desc');
         $query->order_by('id', 'asc');
     });
     foreach (\Input::get() as $key => $value) {
         if (!empty($value) || $value == '0') {
             switch ($key) {
                 case 'title':
                     foreach ($items as $number => $item) {
                         $full_name = $item->first_name . ' ' . $item->last_name;
                         if (stripos($item->company, $value) === false) {
                             if (stripos($full_name, $value) === false) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'email':
                     foreach ($items as $number => $item) {
                         if (stripos($item->email, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'custom_order_status':
                     if (array_key_exists($value, \Config::get('details.status', array()))) {
                         foreach ($items as $number => $item) {
                             if ($item->status != $value) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'order_total_from':
                     is_numeric($value) or $value = 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if ($item_details['total_price'] < $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'order_total_to':
                     is_numeric($value) or $value = 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if ($item_details['total_price'] > $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'date_from':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at < $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'date_to':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at > $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'sch_from':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->sch_delivery < $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'sch_to':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->sch_delivery > $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'invoice_status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->invoice_status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'delivery_status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->delivery_status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'user_group':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (!\Sentry::user_exists((int) $item->user_id) || !\Sentry::user((int) $item->user_id)->in_group($value)) {
                             unset($items[$number]);
                         }
                     }
                     break;
             }
         }
     }
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     return array('items' => $items, 'pagination' => $pagination);
 }
コード例 #10
0
ファイル: upsell.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items($item)
 {
     /************ Get non upsell products ***********/
     $items = Model_Product::find(function ($query) use($item) {
         $upsell_ids = array($item->id);
         foreach ($item->upsell_products as $upsell) {
             array_push($upsell_ids, $upsell->id);
         }
         if (!empty($upsell_ids)) {
             $upsell_ids = '(' . implode(',', $upsell_ids) . ')';
             $query->where('id', 'NOT IN', \DB::expr($upsell_ids));
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     $item->not_upsell_products = $items ? $items : array();
     /************ End generating query ***********/
     foreach ($item->not_upsell_products as $item_key => $item_value) {
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         if (stripos($item_value->title, $value) === false) {
                             unset($item->not_upsell_products[$item_key]);
                         }
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             if ($item_value->status != $value) {
                                 unset($item->not_upsell_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_from < $value) {
                                 unset($item->not_upsell_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_to > $value) {
                                 unset($item->not_upsell_products[$item_key]);
                             }
                         }
                         break;
                     case 'category_id':
                         if (is_numeric($value)) {
                             if (!array_key_exists($value, $item_value->categories)) {
                                 unset($item->not_upsell_products[$item_key]);
                             }
                         }
                         break;
                 }
             }
         }
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($item->not_upsell_products), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $item->not_upsell_products = array_slice($item->not_upsell_products, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('item' => $item, 'pagination' => $pagination, 'status' => $status);
 }
コード例 #11
0
ファイル: infotab.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_list()
 {
     \View::set_global('title', 'List Infotabs');
     /************ Start generating query ***********/
     $items = Model_Infotab::find(function ($query) {
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // 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', 10), '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 . 'list')->set('items', $items)->set('pagination', $pagination, false);
 }
コード例 #12
0
ファイル: order.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items($user_id = false)
 {
     // Override group_id if its a search
     $user_id = \Input::get('user_id', $user_id);
     if ($user_id && \Sentry::user_exists((int) $user_id)) {
         $user = \Sentry::user((int) $user_id);
     }
     $items = \Order\Model_Order::find(function ($query) {
         if (isset($user)) {
             $query->where('user_id', $user->id);
         }
         $query->where('finished', '1');
         $query->order_by('id', 'desc');
     });
     foreach (\Input::get() as $key => $value) {
         if (!empty($value) || $value == '0') {
             switch ($key) {
                 case 'title':
                     foreach ($items as $number => $item) {
                         $full_name = $item->first_name . ' ' . $item->last_name;
                         if (stripos($item->company, $value) === false && stripos($item->id, $value) === false) {
                             if (stripos($full_name, $value) === false) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'email':
                     foreach ($items as $number => $item) {
                         if (stripos($item->email, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'order_total_from':
                     is_numeric($value) or $value == 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if (isset($item_details['total_price']) && $item_details['total_price'] < $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'order_total_to':
                     is_numeric($value) or $value == 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if (isset($item_details['total_price']) && $item_details['total_price'] > $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'date_from':
                     // convert format date to m/d/Y
                     $parts = explode('/', $value);
                     $value = $parts[1] . '/' . $parts[0] . '/' . $parts[2];
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at < $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'date_to':
                     // convert format date to m/d/Y
                     $parts = explode('/', $value);
                     $value = $parts[1] . '/' . $parts[0] . '/' . $parts[2];
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at > $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'tracking_no':
                     foreach ($items as $number => $item) {
                         if (!$value != '') {
                             break;
                         }
                         if (stripos($item->tracking_no, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'payment_method':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (!empty($item->last_payment)) {
                             if ($item->last_payment->method != $value) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'user_group':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if ($item->user_id && \Sentry::user_exists((int) $item->user_id)) {
                             $user = \Sentry::user((int) $item->user_id);
                             if ($user->in_group($value)) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'country':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->country, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'state':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->country, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'product_category':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         // Get order products
                         if (!empty($item->products)) {
                             $exists = array();
                             foreach ($item->products as $product) {
                                 // Find category
                                 if (\Product\Model_Product_To_Categories::find(array('where' => array('product_id' => $product->product_id, 'category_id' => $value)))) {
                                     $exists[] = $product->id;
                                 }
                             }
                             if (empty($exists)) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
             }
         }
     }
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     return array('items' => $items, 'pagination' => $pagination);
 }
コード例 #13
0
 public function get_search_items()
 {
     $filters = array('title' => \Input::get('title'), 'discount_status' => \Input::get('discount_status'), 'discount_type' => \Input::get('discount_type'), 'type' => \Input::get('type'));
     $items = Model_Discountcode::find(function ($query) use($filters) {
         if ($filters['title']) {
             $query = $query->where('code', 'like', '%' . $filters['title'] . '%');
         }
         if ($filters['discount_status']) {
             $query = $query->where('status', $filters['discount_status']);
         }
         if ($filters['discount_type']) {
             $query = $query->where('type', $filters['discount_type']);
         }
         if ($filters['type']) {
             $query = $query->where('use_type', $filters['type']);
         }
         $query->order_by('code', 'asc');
     });
     // 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', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     return array('items' => $items, 'pagination' => $pagination);
 }
コード例 #14
0
ファイル: user.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_referrals($id = false)
 {
     \View::set_global('title', 'Referrals');
     $user = new \Sentry_User((int) $id);
     $items = Model_Referal::find(function ($query) use($id) {
         $query->where('user_added', $id);
         $query->order_by('id', 'desc');
     });
     // 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', 10), '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 . 'referrals')->set('user', $user)->set('pagination', $pagination, false)->set('items', $items);
 }
コード例 #15
0
ファイル: price.php プロジェクト: EdgeCommerce/edgecommerce
 /**
  * Update product price
  * 
  * @access  public
  * @return  Response
  */
 public function action_update($id = false)
 {
     $flag = true;
     if (!is_numeric($id)) {
         \Response::redirect('admin/product/list');
     }
     // Get product item to edit
     if (!($item = Model_Product::find_one_by_id($id))) {
         \Response::redirect('admin/product/list');
     }
     // Redirect to attribute group
     if (\Input::get('attribute_group', false) === false && !empty($item->attributes)) {
         foreach ($item->attributes as $attr_obj) {
             if ($attr_obj->attribute_group_id > 0) {
                 \Response::redirect(\Uri::create(\Uri::admin(), array(), array('attribute_group' => $attr_obj->attribute_group_id)));
             }
         }
     }
     // NRB-Gem: Comment out; Logic does not apply anymore
     // if(\Input::get('user_group', false) === false)
     // {
     //     \Response::redirect(\Uri::create(\Uri::admin(), array(), array('user_group' => 3) + \Input::get()));
     // }
     \View::set_global('title', 'Edit Product Price');
     \View::set_global('quick_menu_save', 'form.main_form');
     // Update
     if (\Input::post()) {
         $post = \Input::post();
         $return_to = is_numeric(\Input::post('return_to')) ? '#' . \Input::post('return_to') : '';
         //$val = Model_Attribute::validate();
         try {
             if (isset($post[$post['price_type']])) {
                 foreach ($post[$post['price_type']] as $key => $price) {
                     if ($update_price = Model_Attribute_Price::find_one_by_id($key)) {
                         if (isset($post['active'][$key])) {
                             $update_price->active = $post['active'][$key];
                         }
                         if (isset($post['product_group_discount_id'][$key])) {
                             $update_price->product_group_discount_id = $post['product_group_discount_id'][$key];
                         }
                         $update_price->save();
                     }
                 }
             }
             $multiple_images = array();
             $image_new = false;
             foreach ($post['attributes'] as $key => $attribute) {
                 if (!empty($post['delete_items'])) {
                     $delete_items = explode(',', $post['delete_items']);
                     $result1 = \DB::delete('product_attributes')->where('id', 'in', $delete_items)->execute();
                     $result2 = \DB::delete('product_attribute_price')->where('product_attribute_id', 'in', $delete_items)->execute();
                 }
                 // Check existing product attribute group
                 $existing_attribute_group = Model_Attribute::find(function ($query) use($post) {
                     $query->where('product_id', $post['product_id']);
                     $query->and_where_open();
                     $query->where('attribute_group_id', null, \DB::expr('IS NOT NULL'));
                     // $query->and_where('attribute_group_id', '!=' , 0);
                     $query->and_where('attribute_group_id', '!=', $post['attribute_group_id']);
                     $query->and_where_close();
                 });
                 //if($existing_attribute_group && $post['attribute_group_id'] != 0)
                 if ($existing_attribute_group) {
                     foreach ($existing_attribute_group as $item) {
                         $delete_attribute = $item->id;
                         $item->delete();
                         $attribute_option = Model_Attribute_Price::find_one_by_product_attribute_id($delete_attribute);
                         if ($attribute_option) {
                             $attribute_option->delete();
                         }
                     }
                 }
                 // Update
                 if (isset($post['update_items'][$key])) {
                     // Lightmedia - michael: check if product attribute code is exists on the product
                     if ($this->check_attr_code_exists($id, $post['update_items'][$key], $post['product_code'][$key])) {
                         $flag = false;
                         \Messages::error($post['product_code'][$key] . ' code already used');
                         continue;
                     }
                     $update = Model_Attribute::find_one_by_id($post['update_items'][$key]);
                     if ($update) {
                         $item_images = array();
                         $data = array('product_id' => $post['product_id'], 'attribute_group_id' => $post['attribute_group_id'], 'attributes' => $attribute, 'product_code' => $post['product_code'][$key], 'retail_price' => $post['retail_price'][$key], 'sale_price' => $post['sale_price'][$key], 'stock_quantity' => $post['stock_quantity'][$key], 'active' => isset($post['active']) && $post['active'][$key] ? $post['active'][$key] : $post['active_new'][$key]);
                         // Default radio
                         $data['default'] = 0;
                         if (isset($post['default']) && $post['default'] == $key) {
                             $this->reset_default($item->id);
                             $data['default'] = 1;
                         }
                         $update->set($data);
                         $update->save();
                         $attr_id = $update->id;
                         // Get combinations for multiple images
                         if (isset($post['apply_image']) && isset($post['action'])) {
                             if (in_array($attr_id, $post['action'])) {
                                 $multiple_images['action'][$attr_id] = $attr_id;
                             }
                         }
                         if (isset($_FILES['image_new_' . $attr_id])) {
                             // Upload image and display errors if there are any
                             $image = $this->upload_image('image');
                             if ($image['errors'] && $image['exists']) {
                                 \Messages::error('<strong>There was an error while trying to upload product attribute image</strong>');
                                 foreach ($image['errors'] as $error) {
                                     \Messages::error($error);
                                 }
                             }
                             // if($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images)))
                             if ($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false))) {
                                 /** IMAGES **/
                                 // Get all alt texts to update if there is no image change
                                 foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
                                     if (strpos($image_id, 'new_') === false) {
                                         $item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
                                         if (!empty($item_images)) {
                                             Model_Attribute::bind_images($item_images);
                                         }
                                     }
                                 }
                                 // Save images if new files are submitted
                                 if (isset($this->_image_data) && $image['exists'] !== false) {
                                     foreach ($this->_image_data as $image_data) {
                                         $cover_count = count($update->images);
                                         if (strpos($image_data['field'], 'new_') === false) {
                                             // Update existing image
                                             if (str_replace('image_', '', $image_data['field']) != 0) {
                                                 $image_id = (int) str_replace('image_', '', $image_data['field']);
                                                 $cover_count--;
                                                 $item_images[$image_id] = array('id' => $image_id, 'data' => array('content_id' => $attr_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
                                                 //$this->delete_image(\Input::post('image_db_' . $image_id, ''));
                                             }
                                             if (!empty($item_images)) {
                                                 Model_Attribute::bind_images($item_images);
                                             }
                                         } else {
                                             // Save new image
                                             $image_tmp = str_replace('image_new_', '', $image_data['field']);
                                             $image_new = $item_images[0] = array('id' => 0, 'data' => array('content_id' => $attr_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
                                             if (!empty($item_images)) {
                                                 Model_Attribute::bind_images($item_images);
                                             }
                                             // Multiple images
                                             if (isset($post['apply_image']) && isset($post['action']) && false) {
                                                 foreach ($post['action'] as $action_value) {
                                                     if ($action_value == $attr_id) {
                                                         continue;
                                                     }
                                                     $item_images = array();
                                                     if ($action_value > 0) {
                                                         $image_new[0] = array('id' => 0, 'data' => array('content_id' => $action_value, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
                                                     }
                                                     if (!empty($item_images)) {
                                                         Model_Attribute::bind_images($item_images);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 /** END OF IMAGES **/
                             }
                         }
                         if (isset($post['active_new'][$key])) {
                             //NRB-Gem: insert attributes to existing Products added to Pricing Groups
                             $this->add_attribute_price($post, array('attr_id' => $attr_id, 'key' => $key));
                         }
                     }
                 } else {
                     if ($this->check_attr_code_exists($post['product_id'], false, $post['product_code_new'][$key])) {
                         $flag = false;
                         \Messages::error($post['product_code_new'][$key] . ' code already used');
                         continue;
                     }
                     $item_images = array();
                     $insert = Model_Attribute::forge(array('product_id' => $post['product_id'], 'attribute_group_id' => $post['attribute_group_id'], 'attributes' => $attribute, 'product_code' => $post['product_code_new'][$key], 'retail_price' => $post['retail_price_new'][$key], 'active' => $post['active_new'][$key], 'sale_price' => $post['sale_price_new'][$key], 'stock_quantity' => $post['stock_quantity'][$key]));
                     // Default radio
                     $insert->default = 0;
                     if (isset($post['default']) && $post['default'] == $key) {
                         $this->reset_default($item->id);
                         $insert->default = 1;
                     }
                     $insert->save();
                     $attr_id = $insert->id;
                     // Get combinations for multiple images
                     if (isset($post['apply_image']) && isset($post['action_new'][$key]) && $post['action_new'][$key] == 1) {
                         $multiple_images['action_new'][$attr_id] = $attr_id;
                     }
                     if (isset($_FILES['_image_new_' . $key])) {
                         // Upload image and display errors if there are any
                         $image = $this->upload_image('image');
                         if ($image['errors'] && $image['exists']) {
                             \Messages::error('<strong>There was an error while trying to upload product attribute image</strong>');
                             foreach ($image['errors'] as $error) {
                                 \Messages::error($error);
                             }
                         }
                         // if($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images)))
                         if ($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false))) {
                             /** IMAGES **/
                             // Save images if new files are submitted
                             if (isset($this->_image_data) && $image['exists'] !== false) {
                                 foreach ($this->_image_data as $image_data) {
                                     $cover_count = 0;
                                     // Save new image
                                     $image_tmp = str_replace('_image_new_', '', $image_data['field']);
                                     $image_new = $item_images[0] = array('id' => 0, 'data' => array('content_id' => $attr_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('_alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
                                     if (!empty($item_images)) {
                                         Model_Attribute::bind_images($item_images);
                                     }
                                     // Multiple images
                                     if (isset($post['apply_image']) && isset($post['action_new']) && false) {
                                         foreach ($post['action_new'] as $action_key => $action_value) {
                                             if ($action_value == $attr_id) {
                                                 continue;
                                             }
                                             $item_images = array();
                                             if ($action_value > 0) {
                                                 $image_new[0] = array('id' => 0, 'data' => array('content_id' => $action_value, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
                                             }
                                             if (!empty($item_images)) {
                                                 Model_Attribute::bind_images($item_images);
                                             }
                                         }
                                     }
                                 }
                             }
                             /** END OF IMAGES **/
                         }
                     }
                     if (isset($post[$post['price_type'] . '_new'][$key])) {
                         //NRB-Gem: insert attributes to existing Products added to Pricing Groups
                         $this->add_attribute_price($post, array('attr_id' => $attr_id, 'key' => $key));
                     }
                 }
             }
             // Update/insert multiple images
             if (!empty($multiple_images) && !empty($image_new) && isset($image_new['data'])) {
                 $content_id = $image_new['data']['content_id'];
                 if (isset($multiple_images['action']) && !empty($multiple_images['action'])) {
                     foreach ($multiple_images['action'] as $value) {
                         $item_images = array();
                         if ($content_id == $value) {
                             continue;
                         }
                         $image_new['data']['content_id'] = $value;
                         $item_images[0] = $image_new;
                         Model_Attribute::bind_images($item_images);
                     }
                 }
                 if (isset($multiple_images['action_new']) && !empty($multiple_images['action_new'])) {
                     foreach ($multiple_images['action_new'] as $value) {
                         $item_images = array();
                         if ($content_id == $value) {
                             continue;
                         }
                         $image_new['data']['content_id'] = $value;
                         $item_images[0] = $image_new;
                         Model_Attribute::bind_images($item_images);
                     }
                 }
             }
             if ($flag) {
                 \Messages::success('Product successfully updated.');
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('<strong>There was an error while trying to update product attributes</strong>');
             // Uncomment lines below to show database errors
             // $errors = $e->getMessage();
             // \Messages::error($errors);
             \Response::redirect(\Uri::create(\Uri::admin('current'), array(), \Input::get()) . $return_to);
         }
         \Response::redirect(\Uri::create(\Uri::admin('current'), array(), \Input::get()) . $return_to);
     }
     // Get current product
     $product = Model_Product::find_one_by_id($id);
     // Create array for attribute group select
     $attribute_groups_select = \Attribute\Model_Attribute_Group::fetch_pair('id', 'title', array(), array('0' => '- No Attributes -'));
     // Set user group for lazy load
     if (\Input::get('user_group')) {
         Model_Attribute::set_user_group();
     }
     // Set tier price group for lazy load
     if (\Input::get('tier_price')) {
         Model_Attribute::set_tier_price();
     }
     $param = \Input::get();
     // Find attributes for current product
     $items_db = Model_Attribute::find(function ($query) use($id, $param) {
         $query->select('product_attributes.*');
         $query->join('attribute_groups', 'LEFT')->on('attribute_groups.id', '=', 'product_attributes.attribute_group_id');
         $query->where('product_id', $id);
         if (isset($param['attribute_group']) && is_numeric($param['attribute_group'])) {
             $query->and_where('product_attributes.attribute_group_id', $param['attribute_group']);
         }
         $query->order_by('attribute_groups.sort', 'asc');
     }, 'id');
     // Decode attribute json
     $combinations_db_arr = $this->decode_attribute_json($items_db);
     // Find current attribute group
     $attribute_group = array();
     if (\Input::get('attribute_group')) {
         $attribute_group = \Attribute\Model_Attribute_Group::find_one_by_id(\Input::get('attribute_group'));
     }
     // Set vars
     $combinations = array();
     $combinations_data = array();
     $combinations_tmp = array();
     $attributes_order = array();
     $compared = array();
     $update_items = array();
     $delete_items = '';
     // Create attribute combinations
     if ($attribute_group && $attribute_group->attributes) {
         $i = 0;
         foreach ($attribute_group->attributes as $attribute) {
             $attributes_order[] = $attribute->id;
             if ($attribute->options) {
                 foreach ($attribute->options as $option) {
                     $combinations[$i][] = $attribute->title . ': ' . $option->title;
                     //$combinations[$i][] =  array($attribute->title => $option->title);
                     $combinations_tmp[$i][] = array($attribute->id => $option->id);
                 }
             }
             $i++;
         }
         // Create combinations from current attributes
         $combinations = $this->combos($combinations);
         $combinations_tmp = $this->combos($combinations_tmp);
         // Sort product atributes from database
         if ($combinations_db_arr) {
             $sorted_db_arr = $this->sort_array(array_keys($attribute_group->attributes), $combinations_db_arr);
             if ($sorted_db_arr) {
                 $compared = $this->compare_array($combinations_tmp, $sorted_db_arr, $combinations_db_arr);
             }
         }
     }
     // Something crazy
     if (!empty($compared) && !empty($items_db)) {
         if (!empty($compared['not_exist_in1'])) {
             $delete_items = array_keys($compared['not_exist_in1']);
             $delete_items = implode(',', $delete_items);
         }
         if (!empty($compared['exist_id'])) {
             $update_items = $compared['exist_id'];
         }
     }
     // Sort array asc
     $combinations_sorted = $this->sort_array_asc($combinations_tmp);
     foreach ($combinations_sorted as $key => $value) {
         $combinations_data[$key] = json_encode($value);
     }
     // Select user groups
     $user_groups = \Sentry::group()->all('front');
     if (!empty($user_groups)) {
         $user_groups = \Model_Base::fetch_pair('id', 'name', array(), false, $user_groups);
     } else {
         $user_groups = array();
     }
     $price_select = array(3 => 'Sale Price');
     $price_select_fields = array(3 => 'sale_price');
     // Set default user price type or use selected
     $price_field = 'sale_price';
     if (isset($price_select_fields[\Input::get('special')])) {
         $price_field = $price_select_fields[\Input::get('special')];
     }
     $listing = true;
     if (\Input::get('special') == 2 && !\Input::get('tier_price')) {
         $listing = false;
     }
     // Product pricing group
     if ($item->pricing_group) {
         $pricing_group = $item->pricing_group->id;
     } else {
         $pricing_group = false;
     }
     // NRB-Gem: removed logic
     // Find and select tier price
     // $tier_price = array();
     // if(\Input::get('user_group') && is_numeric(\Input::get('user_group')) && $pricing_group)
     // {
     //     $tier_price = \Product\Model_Group_Discounts::find(array(
     //         'where' => array(
     //             'user_group_id' => \Input::get('user_group'),
     //             'product_group_id' => $pricing_group,
     //         ),
     //         'order_by' => array(
     //             'discount' => 'asc'
     //         )
     //     ));
     // }
     // Reset to empty array if there are no result found by query
     if (is_null($combinations)) {
         $combinations = array();
     }
     if (is_null($combinations_data)) {
         $combinations_data = array();
     }
     $number_of_combinations = count($combinations);
     // Pagination per page default
     $per_page = \Input::get('per_page', 'all') == 'all' ? 9999 : \Input::get('per_page');
     $show_all = $per_page > $number_of_combinations ? true : false;
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($combinations), 'per_page' => $per_page, 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $combinations = array_slice($combinations, $pagination->offset, $pagination->per_page, true);
     $combinations_data = array_slice($combinations_data, $pagination->offset, $pagination->per_page, true);
     \Theme::instance()->set_partial('content', $this->view_dir . 'attributes')->set('product', $product)->set('price_select', $price_select, false)->set('combinations', $combinations, false)->set('combinations_data', $combinations_data, false)->set('attribute_groups_select', $attribute_groups_select, false)->set('delete_items', $delete_items, false)->set('update_items', $update_items, false)->set('items_db', $items_db, false)->set('price_field', $price_field)->set('listing', $listing)->set('pagination', $pagination, false)->set('number_of_combinations', $number_of_combinations)->set('show_all', $show_all);
 }
コード例 #16
0
ファイル: account.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_referrals()
 {
     if (strtolower(\Sentry::user()->groups()[0]['name']) != 'club members') {
         \Messages::error('Only club members can access this page.');
         \Response::redirect('/');
     }
     \View::set_global('title', 'Referrals');
     $id = \Sentry::user()['id'];
     $items = Model_Referal::find(function ($query) use($id) {
         $query->where('user_added', $id);
         $query->order_by('id', 'desc');
     });
     // 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', 10), '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 . 'referrals')->set('pagination', $pagination, false)->set('items', $items);
 }
コード例 #17
0
 public function action_list()
 {
     if (\Input::post('remove', false)) {
         $remove = \Input::post('attribute.remove', array());
         $is_remove = 0;
         foreach ($remove as $value) {
             if (is_numeric($value)) {
                 // Get news item to edit
                 if ($item = Model_Attribute::find_one_by_id($value)) {
                     // Delete item
                     try {
                         // Delete attribute options
                         if (!empty($item->options)) {
                             foreach ($item->options as $option) {
                                 \Request::forge('admin/attribute/option/delete/' . $option->id)->execute()->response();
                             }
                         }
                         $item->delete();
                         $is_remove = 1;
                     } catch (\Database_Exception $e) {
                         \Messages::error('<strong>There was an error while trying to delete attribute</strong>');
                     }
                 }
             }
         }
         if ($is_remove) {
             \Messages::success('Attribute successfully deleted.');
         }
     }
     \View::set_global('title', 'List Attributes');
     /************ Start generating query ***********/
     $items = Model_Attribute::find(function ($query) {
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // 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', 10), '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 . 'list')->set('items', $items)->set('pagination', $pagination, false);
 }
コード例 #18
0
ファイル: page.php プロジェクト: EdgeCommerce/edgecommerce
 public function get_search_items($parent_id = 0)
 {
     // Reset $parent_id if its invalid value
     is_numeric($parent_id) or $parent_id = 0;
     /************ Start generating query ***********/
     $items = Model_Page::find(function ($query) use($parent_id) {
         // Select only root pages
         // $query->where('parent_id', $parent_id);
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '>=', $date);
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '<=', $date);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // start - sort by subpage
     $items_sorted = array();
     $list_subpages = function ($item) use(&$list_subpages) {
         $items_sorted_sub = array();
         foreach ($item->children as $child) {
             array_push($items_sorted_sub, $child);
             if (!empty($child->children)) {
                 foreach ($list_subpages($child) as $value) {
                     array_push($items_sorted_sub, $value);
                 }
             }
         }
         return $items_sorted_sub;
     };
     $pages = Model_Page::find(function ($query) {
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     foreach ($pages as $page) {
         if ($page->parent_id == 0) {
             array_push($items_sorted, $page);
             foreach ($list_subpages($page) as $value) {
                 array_push($items_sorted, $value);
             }
         }
     }
     $final_items = array();
     foreach ($items_sorted as $item_sorted) {
         foreach ($items as $item) {
             if ($item_sorted->id == $item->id) {
                 array_push($final_items, $item);
             }
         }
     }
     $items = $final_items;
     // end - sort by subpage
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }