Exemplo n.º 1
0
 public function action_add_upload_item($product_id = null)
 {
     if (\Input::post()) {
         if (!($product = \Product\Model_Product::find_one_by_id($product_id))) {
             die('Internal server error, please try again.');
         }
         $max_files = \Config::get('order.artwork.max_number_of_files', 5);
         $to = \Input::post('to', 1);
         $from = \Input::post('from', 1);
         if ($to > $max_files) {
             $to = $max_files;
         }
         if ($from < 1 || $from > $max_files) {
             $from = 1;
         }
         $content = '';
         for ($from; $from <= $to; $from++) {
             $content .= \Theme::instance()->view('views/order/cart/_upload_item', array('num' => $from, 'product' => $product, 'cart_uid' => \Input::post('cart_uid')));
         }
         echo $content;
     }
     exit;
 }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
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) {
         $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;
     }
 }
            <?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>
Exemplo n.º 5
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();
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
                <tbody>
                    <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');
        ?>
Exemplo n.º 8
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));
 }