Esempio n. 1
0
  <div class="blurb">
    <div class="container">
      <!-- Description -->
      <h2 class="blurb-title"><?php 
echo $item->description_full;
?>
</h2>
      <!-- EOF Description -->
    </div>
  </div>

  <?php 
// get active products
$products = \Product\Model_Product::find(function ($query) {
    $query->where('status', 1);
    $query->order_by('created_at', 'desc');
});
?>
  <div class="featured-products">
    <div class="container">
      <h2 class="featured-title">Products</h2>
      <div class="row">
        <?php 
$limit = 9;
$counter = 0;
foreach ($products as $product) {
    $counter++;
    if ($limit < $counter) {
        break;
    }
    ?>
Esempio n. 2
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Casestudy::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get content accordions
                 $item->get_accordions = static::lazy_load(function () use($item) {
                     return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'accordions');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
                 // Get related products
                 $item->get_related_products = static::lazy_load(function () use($item) {
                     $related = Model_Application_To_Related::find(function ($query) use($item) {
                         return $query->where('application_id', $item->id);
                     }, 'related_id');
                     if (!empty($related)) {
                         $related = '(' . implode(',', array_keys($related)) . ')';
                         return \Product\Model_Product::find(function ($query) use($related, $item) {
                             $query->where('id', 'IN', \DB::expr($related));
                             $query->where('id', '<>', $item->id);
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'related_products');
                 // Get hotspot images
                 $item->get_hotspot = static::lazy_load(function () use($item) {
                     $return = new \stdClass();
                     $return->images = Model_Application_Image::find_by_application_id($item->id);
                     return $return;
                 }, $item->id, 'hotspot', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
 protected function save_order()
 {
     if (!$this->check_logged()) {
         \Messages::error('You must be logged in if you want to continue with your order.');
         \Response::redirect(\Uri::create('order/checkout/address'));
     }
     // Save order
     $user = false;
     $order = false;
     $items = \Cart::items();
     if (\Sentry::check()) {
         $user = \Sentry::user();
     }
     if (\Input::post() && $items && $user) {
         $group_id = $user['groups'][0]['id'];
         $item_with_discount = array();
         foreach ($items as $item) {
             $id = $item->get('id');
             $product_groups = \Product\Model_Product_To_Groups::find_by_product_id($item->get('id'));
             foreach ($product_groups as $group) {
                 $all_discounts = \Product\Model_Group_Discounts::find_by(array('user_group_id' => $group_id, 'product_group_id' => $group->group_id), null, null, null);
                 foreach ($all_discounts as $discount) {
                     $discount = (int) $item_with_discount[$id]['discount'] + $discount->discount;
                     $sub_total = $item->totalPrice(true) - (int) $discount / $item->totalPrice(true) * 100;
                     $item_with_discount[$id] = array('product_group_id' => $group->product_id, 'user_group_id' => $group->group_id, 'discount' => $discount, 'sub_total' => $sub_total);
                 }
             }
             $item_with_discount['total_discount'] = (int) $item_with_discount['total_discount'] + (int) $item_with_discount[$id]['total_discount'];
             $item_with_discount['total_price'] = (double) $item_with_discount['total_price'] + (double) $item_with_discount[$id]['sub_total'];
         }
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
         }
         try {
             // Update or create order
             if (is_numeric(\Session::get('order.id'))) {
                 $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
             }
             if (!$order) {
                 $order = \Order\Model_Order::forge();
             }
             $shipping_price = $order->shipping_price(null, null, true);
             $metadata = $user['metadata'];
             if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
                 foreach ($billing as $key => $value) {
                     $order->{$key} = $metadata[$key];
                     unset($metadata[$key]);
                 }
             }
             foreach ($metadata as $key => $value) {
                 $order->{$key} = $value;
             }
             $order->email = $user->get('email');
             $order->user_id = $user->get('id');
             $order->status = 'Pending';
             $order->discount_amount = $item_with_discount['total_discount'];
             //\Cart::getTotal('price');
             $order->total_price = $item_with_discount['total_price'];
             //\Cart::getTotal('price');
             $order->finished = 1;
             $order->guest = $metadata['guest'] ? 1 : 0;
             $order->accepted = $metadata['master'] == 1 ? 1 : 0;
             $order->credit_account = $metadata['credit_account'] == 1 ? 1 : 0;
             $order->shipping_price = $shipping_price;
             // Save order, add products to order products
             if ($order->save()) {
                 foreach ($items as $item) {
                     $product_data = null;
                     if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                         $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                     }
                     if ($product_data) {
                         $order_products = \Order\Model_Products::forge();
                         $order_products->order_id = $order->id;
                         $order_products->title = $product->title;
                         $order_products->code = $product_data['code'];
                         $order_products->price = $item->singlePrice(true);
                         $order_products->price_type = $product_data['price_type'];
                         $order_products->quantity = $item->get('quantity');
                         $order_products->product_id = $product->id;
                         $order_products->artwork_required = $product->artwork_required;
                         $order_products->artwork_free_over = $product->artwork_free_over;
                         $order_products->subtotal = $item_with_discount[$item->get('id')]['sub_total'];
                         //$item->totalPrice(true);
                         $order_products->attributes = json_encode(\Product\Model_Attribute::get_combination($item->get('attributes')));
                         if (!empty($product->categories)) {
                             $categories = array();
                             foreach ($product->categories as $category) {
                                 $categories[] = $category->title;
                             }
                             if ($categories) {
                                 $order_products->product_category = implode(',', $categories);
                             }
                         }
                         $order_products->save();
                         // Find artworks
                         if ($unique_id = $item->get('unique_id')) {
                             if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
                                 $ysi = \Yousendit\Base::forge();
                                 // Artworks (update, delete)
                                 foreach ($artworks as $artwork) {
                                     // Remove deleted artwork
                                     if ($artwork->deleted_at > 0) {
                                         $ysi->delete_artwork($artwork->file_id);
                                         $artwork->delete();
                                     } else {
                                         $artwork->order_product_id = $order_products->id;
                                         $artwork->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($order) {
                 return $order;
             } else {
                 return false;
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('There was an error while trying to save your order.');
             // Uncomment lines below to show database errors
             $errors = $e->getMessage();
             \Messages::error($errors);
             \Response::redirect(\Uri::create('order/checkout/cost'));
         }
         return false;
     }
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 protected function save_order()
 {
     if (!$this->check_logged()) {
         \Messages::error('You must be logged in if you want to continue with your order.');
         \Response::redirect(\Uri::create('order/checkout/address'));
     }
     // Save order
     $user = false;
     $order = false;
     $items = \Cart::items();
     if (\Sentry::check()) {
         $user = \Sentry::user();
     }
     if (\Input::post() && $items && $user) {
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
         }
         try {
             // Update or create order
             if (is_numeric(\Session::get('order.id'))) {
                 $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
             }
             if (!$order) {
                 $order = \Order\Model_Order::forge();
             }
             $cart_total = 0;
             foreach ($items as $item) {
                 $product_data = null;
                 if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                     $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                 }
                 $total_price = $item->totalDiscountedPrice(true);
                 if (isset($product_data["price"]) && $product_data["price"] != 0) {
                     $total_price = $product_data["price"] * $item->get('quantity');
                 }
                 $cart_total += $total_price;
             }
             $method = \Input::post('delivery') == 'pickup' ? false : true;
             $shipping_price = $order->shipping_price(null, null, true, $method);
             $metadata = $user['metadata'];
             $data = array('email' => $user->get('email'), 'user_id' => $user->get('id'), 'status' => 'Pending', 'total_price' => $cart_total, 'finished' => 1, 'guest' => $metadata['guest'] ? 1 : 0, 'accepted' => $metadata['master'] == 1 ? 1 : 0, 'credit_account' => $metadata['credit_account'] == 1 ? 1 : 0, 'shipping_method' => \Input::post('delivery'), 'shipping_price' => $shipping_price, 'gst_price' => ($cart_total + $shipping_price) * 0.1);
             // $order->discount_amount = $item_with_discount['total_discount'];//\Cart::getTotal('price');
             //\Cart::getDiscountedTotal('price');//\Cart::getTotal('price');
             if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
                 foreach ($billing as $key => $value) {
                     $data[$key] = $metadata[$key];
                     unset($metadata[$key]);
                 }
             }
             foreach ($metadata as $key => $value) {
                 $data[$key] = $value;
             }
             $order->set($data);
             // Save order, add products to order products
             if ($order->save()) {
                 foreach ($items as $item) {
                     $product_data = null;
                     if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                         $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                     }
                     $item_exists = \Order\Model_Products::find(array('where' => array('product_id' => $product->id, 'order_id' => $order->id)));
                     if ($product_data && !$item_exists) {
                         $order_products = \Order\Model_Products::forge(array('order_id' => $order->id, 'title' => $product->title, 'code' => $product_data['code'], 'price' => $product_data['price'], 'price_type' => $product_data['price_type'], 'quantity' => $item->get('quantity'), 'product_id' => $product->id, 'artwork_required' => $product->artwork_required, 'artwork_free_over' => $product->artwork_free_over, 'subtotal' => $product_data['price'] * $item->get('quantity'), 'attributes' => json_encode(\Product\Model_Attribute::get_combination($item->get('attributes'))), 'attributes_id' => $item->get('attributes')));
                         //$item->singleDiscountedPrice(true);//$item->singlePrice(true);
                         //$item->totalDiscountedPrice(true);//$item->totalPrice(true);
                         if (!empty($product->categories)) {
                             $categories = array();
                             foreach ($product->categories as $category) {
                                 $categories[] = $category->title;
                             }
                             if ($categories) {
                                 $order_products->product_category = implode(',', $categories);
                             }
                         }
                         // update stock quantity
                         \Product\Model_Attribute::update_stock_quantity($item->get('attributes'), $item->get('quantity'));
                         $order_products->save();
                         // Find artworks
                         if ($unique_id = $item->get('unique_id')) {
                             if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
                                 $ysi = \Yousendit\Base::forge();
                                 // Artworks (update, delete)
                                 foreach ($artworks as $artwork) {
                                     // Remove deleted artwork
                                     if ($artwork->deleted_at > 0) {
                                         $ysi->delete_artwork($artwork->file_id);
                                         $artwork->delete();
                                     } else {
                                         $artwork->set(array('order_product_id' => $order_products->id));
                                         $artwork->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($order) {
                 return $order;
             } else {
                 return false;
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('There was an error while trying to save your order.');
             // Uncomment lines below to show database errors
             $errors = $e->getMessage();
             \Messages::error($errors);
             \Response::redirect(\Uri::create('order/checkout/cost'));
         }
         return false;
     }
 }
Esempio n. 6
0
 /**
  * Get product data (code, price, attributes, images)
  * 
  * @access  public
  * @param   $product   object
  * @return  
  */
 public static function product_data($product = false, $attributes_json = null, $post_select = false, $attributeid = false)
 {
     if (!$product) {
         return;
     }
     $out['current_attributes'] = null;
     $out['code'] = null;
     $out['images'] = null;
     $out['select'] = null;
     $out['select_name'] = null;
     $out['sx'] = null;
     // select (attribute) order
     $out['retail_price'] = null;
     $out['sale'] = null;
     $out['price'] = 0;
     $out['price_type'] = null;
     $current_attributes = array();
     $select = array();
     $select_name = array();
     $sx = array();
     $options = array();
     if (json_decode($attributes_json) != null) {
         $current_attributes = Model_Attribute::find(array('where' => array('attributes' => $attributes_json, 'product_id' => $product->id, 'active' => 1), 'limit' => 1));
     }
     //get attributes per product
     $prod_attributes = \Product\Model_Attribute::find_by_product_id($product->id);
     $a_attribute_ids = array();
     if ($prod_attributes) {
         foreach ($prod_attributes as $attr_id) {
             array_push($a_attribute_ids, $attr_id->id);
         }
     }
     // NRB-Gem: if current URL is Pricing Group -> Products
     // Get pricing_attribute_price from current Pricing Group
     // Products can belong to multiple Pricing Groups
     $a_groups = \Sentry::user()->groups();
     if ($a_attribute_ids) {
         if (\Sentry::check()) {
             $a_cond = array(array('product_attribute_id', 'in', $a_attribute_ids));
             if (\Uri::segment(2) != 'admin' && \Sentry::user()->groups() && $a_groups[0]) {
                 $a_cond['user_group_id'] = $a_groups[0]['id'];
             }
             if (\Uri::segment(3) == 'group' && \Uri::segment(4) == 'products') {
                 $a_cond['pricing_group_id'] = \Uri::segment(5);
             }
             $product_sale_price = \Product\Model_Attribute_Price::find(array('where' => $a_cond));
         }
     }
     // NRB-Gem: check if logged in user can buy product for discounted rate
     if (\Uri::segment(2) != 'admin' && \Sentry::user()->groups() && !\Sentry::user()->is_admin() && $a_groups[0]) {
         $o_product_group_options = \DB::select_array(array('able_to_buy'))->from('product_group_options')->join('product_to_groups')->on('product_group_options.product_group_id', '=', 'product_to_groups.group_id')->where('product_group_options.user_group_id', $a_groups[0]['id'])->where('able_to_buy', 1)->where('product_to_groups.product_id', $product->id)->execute();
         $a_result = $o_product_group_options->as_array();
         $product_sale_price = $a_result && $a_result[0]['able_to_buy'] ? $product_sale_price : false;
     }
     // Get all product attributes
     $product_attributes = Model_Product::get_product_attributes($product);
     // Product with attributes
     if ($product_attributes) {
         // Set current attribute
         if ($current_attributes && isset($product_attributes[$current_attributes[0]->id])) {
             $current_attributes = $product_attributes[$current_attributes[0]->id];
         } elseif ($post_select && count($post_select) > 1) {
             foreach ($post_select as $sk => $sv) {
                 if (!isset($post_select_pop)) {
                     $post_select_pop = $post_select;
                     array_pop($post_select_pop);
                 }
                 $count = count($post_select_pop);
                 foreach ($product_attributes as $pk => $pv) {
                     $i = 0;
                     $not_exists = array();
                     foreach ($pv as $pkk => $pvv) {
                         if ($i >= $count) {
                             continue;
                         }
                         if (!isset($post_select_pop[$pvv->attribute->id]) || $post_select_pop[$pvv->attribute->id] != $pvv->option->id) {
                             $not_exists[] = true;
                         }
                         $i++;
                     }
                     if (empty($not_exists)) {
                         $current_attributes = $product_attributes[$pk];
                         break 2;
                     }
                 }
                 if (empty($current_attributes) && $count > 1) {
                     array_pop($post_select_pop);
                 }
             }
             if (empty($current_attributes)) {
                 $current_attributes = reset($product_attributes);
             }
         } elseif ($product->default_attributes) {
             $current_attributes = $product_attributes[reset($product->default_attributes)->id];
         } else {
             $current_attributes = reset($product_attributes);
         }
         foreach ($current_attributes as $k => $v) {
             $options[] = $v->option->id;
         }
         foreach ($product_attributes as $k => $v) {
             if (is_array($v)) {
                 foreach ($v as $kk => $vv) {
                     $select_name[$vv->attribute->id] = $vv->attribute->name != '' ? $vv->attribute->name : $vv->attribute->title;
                     $select_tmp[$k][$vv->attribute->id][$vv->option->id] = $vv->option->title;
                     foreach ($options as $option_key => $option_value) {
                         if ($kk == $option_key) {
                             $select[$vv->attribute->id][$vv->option->id] = $vv->option->title;
                             if ($vv->option->id != $option_value) {
                                 continue 3;
                             }
                         }
                     }
                 }
             }
         }
         if ($select) {
             $sx = array_keys($select_name);
         }
         $b_use_original_price = false;
         if (!empty($current_attributes)) {
             $attr_obj = $current_attributes[0]->product_attribute;
             $out['current_attributes'] = $current_attributes;
             $out['code'] = $attr_obj->product_code;
             if (!empty($attr_obj->images)) {
                 $out['images'] = $attr_obj->images;
             }
             $out['select'] = $select;
             $out['select_name'] = $select_name;
             $out['sx'] = $sx;
             $out['stock_quantity'] = $attr_obj->stock_quantity;
             $out['retail_price'] = $attr_obj->retail_price;
             // NRB-Gem: changed condition from: (!empty($product_sale_price) && $product_sale_price[0]->price != 0)
             // fix for attributes with sale price are not displayed
             if (!empty($product_sale_price)) {
                 $out['with_attr'] = array('attribute' => array());
                 foreach ($product_sale_price as $with_attr) {
                     $out['with_attr']['able_discount'][$with_attr->product_attribute_id] = $with_attr->able_discount;
                     if ($out['with_attr']['able_discount'][$with_attr->product_attribute_id]) {
                         $out['with_attr']['discount'][$with_attr->product_attribute_id] = $with_attr->discount;
                         $out['with_attr']['price'][$with_attr->product_attribute_id] = $with_attr->price;
                     }
                     $out['with_attr']['attribute'][$with_attr->product_attribute_id] = '';
                     foreach ($product_attributes as $o_prod_attr) {
                         $a_attr = array();
                         foreach ($o_prod_attr as $o_attr) {
                             if ($with_attr->product_attribute_id == $o_attr->product_attribute->id) {
                                 $a_attr[] = $o_attr->option->title;
                             }
                         }
                         $out['with_attr']['attribute'][$with_attr->product_attribute_id] .= implode(' | ', $a_attr);
                     }
                     // NRB-Gem: do not display inactive attribute
                     if (empty($out['with_attr']['attribute'][$with_attr->product_attribute_id])) {
                         unset($out['with_attr']['attribute'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['able_discount'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['discount'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['price'][$with_attr->product_attribute_id]);
                     }
                 }
                 // NRB-Gem: get default prices
                 foreach ($prod_attributes as $attr) {
                     if (isset($out['with_attr']['discount'][$attr->id]) && $out['with_attr']['discount'][$attr->id] > 0) {
                         $out['with_attr']['price'][$attr->id] = $attr->retail_price - $attr->retail_price * ($out['with_attr']['discount'][$attr->id] / 100);
                     } else {
                         if (isset($out['with_attr']['price'][$attr->id]) && !$out['with_attr']['price'][$attr->id]) {
                             $out['with_attr']['price'][$attr->id] = $attr->sale_price ? $attr->sale_price : $attr->retail_price;
                         }
                     }
                 }
                 $out['sale'] = \Product\Model_Product::calculate_discount($product, $product_sale_price[0]->discount);
                 $out['price'] = \Product\Model_Product::calculate_discount($product, $product_sale_price[0]->price);
                 $out['price_type'] = 'sale_price';
                 // NRB-Gem: Set discounted rate from product_attribute_price Product attributes
                 if ($attributes_json) {
                     foreach ($current_attributes as $o_attribute) {
                         if ($o_attribute->product_attribute->attributes == $attributes_json) {
                             if ($out['with_attr']['able_discount'][$o_attribute->product_attribute->id]) {
                                 if ($out['with_attr']['discount'][$o_attribute->product_attribute->id] > 0) {
                                     $out['price'] = $out['retail_price'] - $out['retail_price'] * ($out['with_attr']['discount'][$o_attribute->product_attribute->id] / 100);
                                 } else {
                                     $out['price'] = $out['with_attr']['price'][$o_attribute->product_attribute->id];
                                 }
                             } else {
                                 $b_use_original_price = true;
                             }
                         }
                     }
                 }
             } else {
                 $out['price'] = \Product\Model_Product::calculate_discount($product, $attr_obj->retail_price);
                 $out['price_type'] = 'retail_price';
                 $b_use_original_price = true;
             }
             // NRB-Gem: Display original price if Discount price is not enabled (used by non-ajax request)
             if (\Uri::segment(1) == 'product' && !$attributes_json) {
                 $a_prod_attr_keys = array_keys($product_attributes);
                 $attr_id = $a_prod_attr_keys[0];
                 if (isset($out['with_attr']['able_discount'][$attr_id])) {
                     if (isset($out['with_attr']['discount']) && $out['with_attr']['discount'][$attr_id] > 0) {
                         $out['price'] = $out['retail_price'] - $out['retail_price'] * ($out['with_attr']['discount'][$attr_id] / 100);
                     } else {
                         $out['price'] = isset($out['with_attr']['price']) ? $out['with_attr']['price'][$attr_id] : '';
                     }
                 } else {
                     $b_use_original_price = true;
                     $attributes_json = true;
                 }
             }
             // NRB-Gem: Set original discounted rate for Product attributes
             if ($b_use_original_price && $attributes_json) {
                 if ($attr_obj->sale_price > 0) {
                     $out['price'] = $attr_obj->sale_price;
                     $out['price_type'] = 'sale_price';
                 } else {
                     $out['price'] = $attr_obj->retail_price;
                     unset($out['price_type']);
                 }
             }
         }
     } else {
         $p = $product->attributes[0];
         $out['current_attributes'] = null;
         $out['code'] = $p->product_code;
         $out['images'] = $p->images;
         $out['retail_price'] = $p->retail_price;
         $out['stock_quantity'] = $p->stock_quantity;
         $out['able_discount'] = isset($product_sale_price[0]) ? $product_sale_price[0]->able_discount : 0;
         if (!empty($product_sale_price) && $product_sale_price[0]->price != 0) {
             if ($out['able_discount']) {
                 $out['sale'] = \Product\Model_Product::calculate_discount($p, $product_sale_price[0]->discount);
                 $out['price'] = \Product\Model_Product::calculate_discount($p, $product_sale_price[0]->price);
             }
             $out['price_type'] = 'sale_price';
         } else {
             $out['sale'] = isset($product_sale_price[0]) ? $product_sale_price[0]->discount : 0;
             $out['price'] = \Product\Model_Product::calculate_discount($product, $p->retail_price);
             $out['price_type'] = 'retail_price';
         }
         // NRB-Gem: Display original price if Discount price is not enabled
         if ($out['able_discount']) {
             if ($product_sale_price[0]->discount > 0) {
                 $out['price'] = $p->retail_price - $p->retail_price * ($product_sale_price[0]->discount / 100);
             }
         } else {
             if ($p->sale_price > 0) {
                 $out['price'] = $p->sale_price;
                 $out['price_type'] = 'sale_price';
             } else {
                 unset($out['price_type']);
                 $out['price'] = $p->retail_price;
             }
         }
     }
     $prod_category = Model_Product_To_Categories::find_by_product_id($product->id);
     $category = \Product\Model_Category::find_one_by_id($prod_category[0]->category_id);
     $out['category_id'] = $prod_category ? $prod_category[0]->category_id : null;
     $out['category'] = $category ? $category->title : null;
     // Product without attributes
     if (empty($out['current_attributes'])) {
         $out['code'] = $product->code;
     }
     // Set images from product if there is no images in product attribute
     if (empty($out['images']) && !empty($product->images)) {
         $out['images'] = $product->images;
     }
     return $out;
 }
            <?php 
$check_product = 0;
?>
            <?php 
if (!is_null(\Input::get('title')) && \Input::get('title') != 'customer_order_select') {
    ?>
                <?php 
    foreach ($items as $item) {
        ?>
                    <?php 
        $item = (object) $item;
        ?>

                    <?php 
        foreach ($item->products as $product) {
            $prdct = \Product\Model_Product::find_one_by_id($product->product_id);
            ?>
                        <tr>
                            <td><?php 
            echo $product->code;
            ?>
</td>
                            <td><?php 
            echo $product->title;
            ?>
</td>
                            <td><?php 
            echo $prdct->active_attribute_group ? $prdct->active_attribute_group[0]->title : 'N/A';
            ?>
</td>
                            <td>
Esempio n. 8
0
 public function my_categories()
 {
     if (!$this->check_logged()) {
         return false;
     }
     // Get current user
     $user = \Sentry::user();
     $user_group = $user->groups();
     $user_group = $user_group[0];
     if (!isset($user_group['id']) || $user_group['id'] < 4) {
         return false;
     }
     return \Product\Model_Product::my_categories();
 }
Esempio n. 9
0
 public function action_export_customer_products()
 {
     $status = array('false' => 'All', '1' => 'Active', '0' => 'Inactive');
     $search = $this->get_search_customer_products();
     $items = $search['items'];
     $output = "Product Code,Product Name,Attribute Group,Status,Stock,Price Paid\n";
     $content = 'text/csv';
     $filename = 'Customer-x-Products-Reports-' . date('YmdHis') . ' Report.csv';
     if (!is_null(\Input::get('title')) && \Input::get('title') != 'customer_order_select') {
         foreach ($items as $item) {
             foreach ($item->products as $product) {
                 $prdct = \Product\Model_Product::find_one_by_id($product->product_id);
                 $hold_stock = \DB::query('SELECT b.id, b.stock_quantity FROM product a join product_attributes b on a.id = b.product_id where a.id = ' . $prdct->id)->execute();
                 $get_status = '';
                 // If page is active from certain date
                 if ($prdct->status == 2) {
                     $dates = array();
                     !is_null($prdct->active_from) and array_push($dates, date('m/d/Y', $prdct->active_from));
                     !is_null($prdct->active_to) and array_push($dates, date('m/d/Y', $prdct->active_to));
                     if (true) {
                         $get_status = 'Active ' . implode(' - ', $dates);
                     }
                 } else {
                     $get_status = $status[$prdct->status];
                 }
                 $output .= implode(",", [$product->code, $product->title, $prdct->active_attribute_group ? $prdct->active_attribute_group[0]->title : 'N/A', $get_status, $hold_stock[0]['stock_quantity'], '$' . $product->price]) . "\n";
             }
         }
     }
     $output = rtrim($output, "\n");
     $headers = array('Content-Type' => $content, 'Content-Disposition' => 'attachment; filename="' . $filename . '"');
     return \Response::forge($output, 200, $headers);
 }
Esempio n. 10
0
 public function action_discuss_brief()
 {
     if (\Input::post()) {
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('/')));
         }
         $file = null;
         // Send autoresponder
         $autoresponder = \Autoresponder\Autoresponder::forge();
         $autoresponder->view_custom = 'discuss_brief';
         $autoresponder->view_admin = 'discuss_brief';
         $post = \Input::post();
         if ($product = \Product\Model_Product::find_one_by_id(\Input::post('product'))) {
             $post['product'] = $product;
         }
         $content['content'] = $post;
         $config = array('path' => APPPATH . 'tmp', 'normalize' => true, 'max_size' => 5242880);
         // Check if file uploaded
         if (isset($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['name'] != '') {
             // process the uploaded files in $_FILES
             \Upload::process($config);
             // if there are any valid files
             if (\Upload::is_valid()) {
                 // save them according to the config
                 \Upload::save();
                 $file = \Upload::get_files(0);
             }
             // Upload errors
             if (\Upload::get_errors() !== array()) {
                 foreach (\Upload::get_errors() as $file) {
                     foreach ($file['errors'] as $key => $value) {
                         \Messages::error($value['message']);
                     }
                 }
                 \Response::redirect(\Input::referrer(\Uri::create('/')));
             }
         }
         $attachment = array();
         if (isset($file['saved_to']) && is_file($file['saved_to'] . $file['saved_as'])) {
             $attachment = array($file['saved_to'] . $file['saved_as']);
         }
         // echo 'test';
         // die;
         $content['subject'] = 'Thanks for contacting Evan Evans';
         $autoresponder->autoresponder_custom($content, \Input::post('email'), $attachment);
         $content['subject'] = 'Autoresponder Discuss Brief for Admin';
         $autoresponder->autoresponder_admin($content, \Config::get('auto_response_emails.discuss_brief'), $attachment);
         if ($autoresponder->send()) {
             \Messages::success('Thank You for sending request.');
         } else {
             \Messages::error('There was an error while trying to submit request.');
         }
         // Delete uploaded files
         if (!empty($attachment)) {
             foreach ($attachment as $file) {
                 if (is_file($file)) {
                     unlink($file);
                 }
             }
         }
         \Response::redirect(\Input::referrer(\Uri::create('/')));
     }
     if (\Input::is_ajax()) {
         $products = \Product\Model_Product::fetch_pair('id', 'title', array('order_by' => array('title' => 'asc')));
         echo \Theme::instance()->view('views/_partials/discuss_brief')->set('products', $products, false);
         exit;
     }
     throw new \HttpNotFoundException();
 }
Esempio n. 11
0
 public function get_search_items($item)
 {
     /************ Get non related infotabs ***********/
     $items = \Product\Model_Product::find(function ($query) use($item) {
         $related_ids = array();
         foreach ($item->related_products as $related) {
             array_push($related_ids, $related->id);
         }
         if (!empty($related_ids)) {
             $related_ids = '(' . implode(',', $related_ids) . ')';
             $query->where('id', 'NOT IN', \DB::expr($related_ids));
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     $item->not_related_products = $items ? $items : array();
     /************ End generating query ***********/
     foreach ($item->not_related_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_related_products[$item_key]);
                         }
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             if ($item_value->status != $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_from < $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_to > $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'category_id':
                         if (is_numeric($value)) {
                             if (!array_key_exists($value, $item_value->categories)) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                 }
             }
         }
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($item->not_related_products), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $item->not_related_products = array_slice($item->not_related_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);
 }
Esempio n. 12
0
                    <tr>
                        <td width="50%">Product Name</td>
                        <td width="35%">Quantity</td>
                        <td width="15%">Price</td>
                    </tr>

                    <!-- Display Items in Cart -->
                    <?php 
if (!empty($items)) {
    ?>
                        <?php 
    $cart_total = 0;
    foreach ($items as $item) {
        $product_data = null;
        if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
            $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
            extract($product_data);
        }
        $price = $item->singlePrice(true);
        $total_price = $item->totalDiscountedPrice(true);
        if (isset($product_data["price"]) && $product_data["price"] != 0) {
            $price = $product_data["price"];
            $total_price = number_format($product_data["price"], 2) * $item->get('quantity');
        }
        $cart_total += $total_price;
        ?>
                            <tr>
                                <td><?php 
        echo $item->get('title');
        ?>
</td>
Esempio n. 13
0
 public function action_get_cart_data()
 {
     $items = \Input::post('items');
     $return_items = array();
     $products_total = 0;
     foreach ($items as $key => $item) {
         $product = \Product\Model_Product::find_one_by_id($item['product_id']);
         $product_data = $product->data;
         array_push($return_items, array('price' => $product_data['price'], 'title' => $product['title'], 'product_id' => $item['product_id'], 'product_quantity' => $item['product_quantity']));
         $products_total += $item['product_quantity'] * $product_data['price'];
     }
     //discount
     $order = \Order\Model_Order::forge();
     $shipping_price = $order->shipping_price(null, null, true);
     echo json_encode(array('items' => $return_items, 'products_total' => $products_total, 'discount' => 0, 'shipping' => $shipping_price, 'gst_amount' => ($products_total + $shipping_price) * 0.1, 'grand_total' => $products_total + $shipping_price + ($products_total + $shipping_price) * 0.1));
 }
Esempio n. 14
0
                        <?php 
        if ($key > 0 && $key % 5 == 0) {
            echo '<div class="clear"></div>';
        }
        ?>
                        <div class="images">
                        <div class="col-sm-4">
                            <div class="product-item">
                                <a href="<?php 
        echo \Uri::create('product/' . $item->seo->slug);
        ?>
">
                                    <div class="product-img">
                                        <?php 
        // Get product data
        $product_data = \Product\Model_Product::product_data($item);
        ?>
                                        <?php 
        if (!empty($product_data['images']) && is_file($images_base_path . 'medium/' . $product_data['images'][0]->image)) {
            ?>
                                            <?php 
            echo \Html::img(\Uri::create($images_base_url . 'medium/' . $product_data['images'][0]->image), array('width' => 'auto', 'height' => 321, 'alt' => $product_data['images'][0]->alt_text));
            ?>
                                        <?php 
        } else {
            ?>
                                          <div class="no-image">
                                            <i class="icon icon-image2"></i>
                                            <h4>No image</h4>
                                          </div>
                                        <?php 
Esempio n. 15
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get product categories
                 $item->get_categories = static::lazy_load(function () use($item) {
                     $categories = Model_Product_To_Categories::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'category_id');
                     if (!empty($categories)) {
                         $categories = '(' . implode(',', array_keys($categories)) . ')';
                         return Model_Category::find(function ($query) use($categories) {
                             return $query->where('id', 'IN', \DB::expr($categories));
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'categories');
                 // Get product infotabs
                 $item->get_infotabs = static::lazy_load(function () use($item) {
                     return Model_Product_To_Infotabs::find(function ($query) use($item) {
                         $query->order_by('sort', 'asc');
                         return $query->where('product_id', $item->id);
                     });
                 }, $item->id, 'infotabs');
                 // Get product groups
                 $item->get_groups = static::lazy_load(function () use($item) {
                     $groups = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'group_id');
                     if (!empty($groups)) {
                         $groups = '(' . implode(',', array_keys($groups)) . ')';
                         return Model_Group::find(function ($query) use($groups, $item) {
                             $query->where('id', 'IN', \DB::expr($groups));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'groups');
                 // Get product groups
                 $item->get_pricing_group = static::lazy_load(function () use($item) {
                     $groups = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'group_id');
                     if (!empty($groups)) {
                         $groups = '(' . implode(',', array_keys($groups)) . ')';
                         $groups = Model_Group::find(function ($query) use($groups, $item) {
                             $query->where('type', 'pricing');
                             $query->where('id', 'IN', \DB::expr($groups));
                             $query->order_by('sort', 'asc');
                             return $query;
                         });
                         return !empty($groups) ? $groups[0] : false;
                     }
                     return false;
                 }, $item->id, 'pricing_group', 'object');
                 // Get related products
                 $item->get_related_products = static::lazy_load(function () use($item) {
                     $related = Model_Product_To_Related::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'related_id');
                     if (!empty($related)) {
                         $related = '(' . implode(',', array_keys($related)) . ')';
                         return Model_Product::find(function ($query) use($related, $item) {
                             $query->where('id', 'IN', \DB::expr($related));
                             $query->where('id', '<>', $item->id);
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'related_products');
                 // Get upsell products
                 $item->get_upsell_products = static::lazy_load(function () use($item) {
                     $upsell = Model_Product_To_Upsell::find(function ($query) use($item) {
                         return $query->where('product_id', $item->id);
                     }, 'upsell_id');
                     if (!empty($upsell)) {
                         $upsell = '(' . implode(',', array_keys($upsell)) . ')';
                         return Model_Product::find(function ($query) use($upsell, $item) {
                             $query->select(Model_Product_To_Upsell::get_protected('_table_name') . '.discount', Model_Product::get_protected('_table_name') . '.*');
                             $query->join(Model_Product_To_Upsell::get_protected('_table_name'));
                             $query->on(Model_Product_To_Upsell::get_protected('_table_name') . '.upsell_id', '=', Model_Product::get_protected('_table_name') . '.id');
                             $query->where(Model_Product::get_protected('_table_name') . '.id', 'IN', \DB::expr($upsell));
                             $query->where(Model_Product::get_protected('_table_name') . '.id', '<>', $item->id);
                             $query->order_by(Model_Product::get_protected('_table_name') . '.sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'upsell_products');
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Product_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_Product_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Product_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Product_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
                 // Get attributes
                 $item->get_attributes = static::lazy_load(function () use($item) {
                     return Model_Attribute::find(array('where' => array('product_id' => $item->id)));
                 }, $item->id, 'attributes');
                 // Get default attribute
                 $item->get_default_attributes = static::lazy_load(function () use($item) {
                     return Model_Attribute::find(array('where' => array('product_id' => $item->id, 'default' => 1, 'active' => 1)));
                 }, $item->id, 'default_attributes');
                 // Get all active prices
                 $item->get_all_prices = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get prices for product
                 $item->get_prices = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get unit price
                 $item->get_unit_price = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'unit_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'unit_price');
                 // Get sale price
                 $item->get_sale_price = static::lazy_load(function () use($item) {
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'sale_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     return $product_attributes;
                 }, $item->id, 'sale_price');
                 // Get default price (RRP or Sale price)
                 $item->get_default_price = static::lazy_load(function () use($item) {
                     $out = array(0);
                     $product_attributes = Model_Attribute::find(function ($query) use($item) {
                         $query->join(Model_Attribute_Price::get_protected('_table_name'));
                         $query->on(Model_Attribute_Price::get_protected('_table_name') . '.product_attribute_id', '=', Model_Attribute::get_protected('_table_name') . '.id');
                         $query->where('product_id', $item->id);
                         $query->and_where('type', 'sale_price');
                         $query->and_where('attributes', '!=', '');
                         $query->and_where('active', 1);
                         $query->and_where('default', 1);
                         $query->limit(1);
                         return $query;
                     }, 'id');
                     if ($product_attributes) {
                         $obj = reset($product_attributes);
                         if ($obj->price > 0) {
                             $out[0] = $obj->price;
                             $out[1] = 'sale_price';
                         } else {
                             $out[0] = $obj->retail_price;
                             $out[1] = 'retail_price';
                         }
                     }
                     return $out;
                 }, $item->id, 'default_price');
                 // Get active attribute group
                 $item->get_active_attribute_group = static::lazy_load(function () use($item) {
                     if ($attribute = Model_Attribute::find_one_by_product_id($item->id)) {
                         return $attribute->attribute_group;
                     }
                     return false;
                 }, $item->id, 'active_attribute_group');
                 // Get product data
                 $item->get_data = static::lazy_load(function () use($item) {
                     return \Product\Model_Product::product_data($item);
                 }, $item->id, 'data');
             }
         }
     }
     // return the result
     return $result;
 }