Beispiel #1
0
 private function sendMail($id)
 {
     $response = ['sys_title' => $this->system['title'], 'sys_email' => $this->system['email']];
     //Try to catch order id
     if (empty($id)) {
         $id = session()->get('order_id', FALSE);
         if (!empty($id)) {
             $response['new'] = TRUE;
             session()->forget('order_id');
         }
     }
     //If no order
     if (empty($id)) {
         return redirect('/');
     }
     $order_data = Model_Orders::getOrders($id, FALSE);
     if (!empty($order_data = $order_data[0]) && is_array($order_data)) {
         $response['cart'] = !empty($order_data['cart']) ? json_decode($order_data['cart'], TRUE) : [];
         $response['total'] = !empty($order_data['total']) ? $order_data['total'] : 0;
         if (isset($order_data['total'])) {
             unset($order_data['total']);
         }
         if (isset($order_data['cart'])) {
             unset($order_data['cart']);
         }
         if (isset($response['cart']['total'])) {
             unset($response['cart']['total']);
         }
         $response['order'] = $order_data;
     }
     foreach ($this->states as $state) {
         $response['states'][$state] = trans('orders.' . $state);
     }
     //Calculate delivery and total
     if (!empty($order_data['delivery_type']) && $response['total'] < $this->system['delivery_free_delivery']) {
         if ($order_data['delivery_type'] == 'to_address') {
             $response['delivery_cost'] = $this->system['delivery_to_address'];
         } elseif ($order_data['delivery_type'] == 'to_office') {
             $response['delivery_cost'] = $this->system['delivery_to_office'];
         }
         $response['order_total'] = $response['total'] + $response['delivery_cost'];
     } else {
         $response['delivery_cost'] = 0;
         $response['order_total'] = $response['total'];
     }
     $response['order_id'] = $order_data['id'];
     $response['date_created'] = date('H:i - m.d.Y', strtotime($order_data['created_at']));
     $response['delivery_type'] = $order_data['delivery_type'];
     $products_to_cart = [];
     //Get product id's
     if (!empty($response['cart']) && is_array($response['cart'])) {
         foreach ($response['cart'] as $key => $item) {
             $products_to_cart[] = $item['product_id'];
         }
     }
     // Get products data
     $response['products'] = Model_Main::getProducts($products_to_cart, ['title', 'images']);
     // Send products to response
     $response['products'] = self::prepareProductsForResponse($response['products']);
     $response['thumbs_path'] = Config::get('system_settings.product_public_path');
     $response['icon_size'] = Config::get('images.sm_icon_size');
     Mail::send('dressplace::emails.order', $response, function ($m) use($response) {
         $m->from($response['sys_email'], $response['sys_title']);
         $m->replyTo($response['sys_email'], $response['sys_title']);
         $m->to($response['order']['email'], $response['order']['name'] . ' ' . $response['order']['last_name'])->subject(trans('client.order_completed_mail'));
     });
 }
Beispiel #2
0
 public function drop()
 {
     $response['blade_standalone'] = TRUE;
     $response['ajax'] = TRUE;
     $response['cart'] = session()->get('cart');
     $response['total'] = session()->get('total');
     $response['delivery_type'] = session()->get('delivery_type');
     $response['cart_items'] = count($response['cart']);
     if (!empty($response['cart'])) {
         $products_to_cart = [];
         //Get product id's
         if (!empty($response['cart']) && is_array($response['cart'])) {
             foreach ($response['cart'] as $key => $item) {
                 $products_to_cart[] = $item['product_id'];
             }
         }
         // Get products data
         $response['products'] = Model_Main::getProducts($products_to_cart, ['title', 'images']);
         //Loop trough products data
         if (!empty($response['products']) && is_array($response['products'])) {
             foreach ($response['products'] as $id => $product) {
                 if (!empty($product['discount_price'])) {
                     //Calculate is discount active
                     $now = time();
                     if ($product['discount_start'] == '0000.00.00 00:00:00' || strtotime($product['discount_start']) <= $now) {
                         $allow_start = TRUE;
                     } else {
                         $allow_start = FALSE;
                     }
                     if ($product['discount_end'] == '0000.00.00 00:00:00' || strtotime($product['discount_end']) <= $now) {
                         $allow_end = TRUE;
                     } else {
                         $allow_end = FALSE;
                     }
                     if ($allow_start === TRUE && $allow_end === TRUE) {
                         $response['products'][$id]['active_discount'] = TRUE;
                     }
                     if (!empty($response['products'][$id]['active_discount'])) {
                         $response['products'][$id]['discount'] = intval((floatval($response['products'][$id]['price']) - floatval($response['products'][$id]['discount_price'])) / floatval($response['products'][$id]['price']) * 100);
                     }
                 }
             }
         }
         // Send products to response
         $response['products'] = self::prepareProductsForResponse($response['products']);
         $response['thumbs_path'] = Config::get('system_settings.product_public_path');
         $response['icon_size'] = Config::get('images.sm_icon_size');
         return Theme::view('partials.cart_items_drop', $response);
     } else {
         return response()->json(['empty' => true]);
     }
 }
Beispiel #3
0
 public static function sitemap()
 {
     $customCSS = [];
     $customJS = [];
     $response = ['page_title' => trans('client.sitemap'), 'blade_custom_css' => $customCSS, 'blade_custom_js' => $customJS];
     if ($response['categories'] = Model_Main::getCategory(FALSE, ['title'], FALSE)) {
         $categories_ids = [];
         $main_categories = [];
         $second_level_categories = [];
         //			$third_level_categories  = [];
         if (!empty($response['categories']) && is_array($response['categories'])) {
             //Loop and get ID's
             foreach ($response['categories'] as $key => $category) {
                 $categories_ids[] = $category['id'];
             }
             //Get urls
             if ($urls = Model_Client::getURL($categories_ids, 'category')) {
                 if (!empty($urls) && is_array($urls)) {
                     foreach ($urls as $url) {
                         $response['categories'][$url['object']]['slug'] = $url['slug'];
                     }
                 }
             }
             foreach ($response['categories'] as $key => $category) {
                 if ($category['level'] == 0) {
                     $main_categories[$category['id']] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title']];
                 } elseif ($category['level'] == 1) {
                     $second_level_categories[$category['parent_id']][] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title'], 'parent' => $category['parent_id']];
                 }
                 //					elseif ($category['level'] == 2)
                 //					{
                 //						$third_level_categories[$category['parent_id']][] = [
                 //							'id'     => $category['id'],
                 //							'slug'   => ! empty($category['slug']) ? $category['slug'] : '',
                 //							'title'  => $category['title'],
                 //							'parent' => $category['parent_id'],
                 //						];
                 //					}
             }
         }
         $response['map_cat_lvl_1'] = $main_categories;
         $response['map_cat_lvl_2'] = $second_level_categories;
         //			$response['map_cat_lvl_3'] = $third_level_categories;
         $response['map_pages'] = Model_Main::getSitemapPages();
     }
     return Theme::view('homepage.sitemap', $response);
 }
Beispiel #4
0
 private function loadProduct($id)
 {
     $response = [];
     $product = Model_Main::getProducts($id);
     //Breadcrumbs
     $response['all_categories'] = $this->categories['all'];
     if (!empty($product[$id]['main_category']) && $this->categories['all'][$product[$id]['main_category']]) {
         $response['breadcrumbs'] = self::generateCategoryBreadcrumbs($this->categories['all'][$product[$id]['main_category']]);
     }
     //Prepare product for response
     if (!empty($product[$id])) {
         $response['product'] = $product[$id];
         if (!empty($response['product']['page_title'])) {
             View::share('page_title', $response['product']['page_title']);
         } else {
             if (!empty($response['product']['title'])) {
                 View::share('page_title', $response['product']['title']);
             }
         }
         if (!empty($response['product']['meta_description'])) {
             View::share('page_meta_description', $response['product']['meta_description']);
         }
         if (!empty($response['product']['meta_keywords'])) {
             View::share('page_meta_keywords', $response['product']['meta_keywords']);
         }
         if (!empty($response['product']['discount_price'])) {
             //Calculate is discount active
             $now = time();
             if ($response['product']['discount_start'] == '0000.00.00 00:00:00' || strtotime($response['product']['discount_start']) <= $now) {
                 $allow_start = TRUE;
             } else {
                 $allow_start = FALSE;
             }
             if ($response['product']['discount_end'] == '0000.00.00 00:00:00' || strtotime($response['product']['discount_end']) <= $now) {
                 $allow_end = TRUE;
             } else {
                 $allow_end = FALSE;
             }
             if ($allow_start === TRUE && $allow_end === TRUE) {
                 $response['product']['active_discount'] = TRUE;
             }
         }
         if (!empty($response['product']['sizes']) && is_array($response['product']['sizes'] = json_decode($response['product']['sizes'], TRUE))) {
             foreach ($response['product']['sizes'] as $key => $size) {
                 if (empty($size['name']) || empty($size['quantity'])) {
                     if (isset($response['product']['sizes'][$key])) {
                         unset($response['product']['sizes'][$key]);
                     }
                 }
             }
         }
     }
     //Product discount percentage
     if (!empty($response['product']['active_discount'])) {
         $response['product']['discount'] = intval((floatval($response['product']['price']) - floatval($response['product']['discount_price'])) / floatval($response['product']['price']) * 100);
     }
     //Images
     if (!empty($response['product']['images'])) {
         $response['product']['images'] = json_decode($response['product']['images'], TRUE);
         if (is_array($response['product']['images'])) {
             $response['product_thumbs_path'] = Config::get('system_settings.product_public_path') . $id . '/' . Config::get('images.sm_icon_size') . '/';
             $response['images_path'] = Config::get('system_settings.product_public_path') . $id . '/' . Config::get('images.full_size') . '/';
             $response['md_path'] = Config::get('system_settings.product_public_path') . $id . '/' . Config::get('images.md_icon_size') . '/';
             uasort($response['product']['images'], function ($a, $b) {
                 if ($a == $b) {
                     return 0;
                 }
                 return $a < $b ? -1 : 1;
             });
         }
     }
     //Tags
     $response['product']['tags'] = Model_Main::getTags($id);
     //Manufacturer
     $response['product']['manufacturer'] = Model_Main::getManufacturer($id);
     //Material
     $response['product']['material'] = Model_Main::getMaterial($id);
     if (!empty($response['product']['material'][0])) {
         $response['product']['material'] = $response['product']['material'][0];
     }
     //Color
     $response['product']['related_colors'] = Model_Main::getColor($id);
     if (!empty($response['product']['related_colors'])) {
         $response['product']['related_colors'] = implode(', ', $response['product']['related_colors']);
     }
     //Related products
     if (!empty($response['product']['related_products']) && is_array(json_decode($response['product']['related_products'], TRUE))) {
         $response['carousel']['products'] = json_decode($response['product']['related_products'], TRUE);
     } else {
         if (!empty($response['product']['main_category'])) {
             $response['carousel']['products'] = Model_Main::getSimilarProducts($response['product']['main_category']);
         }
     }
     if (!empty($response['carousel']['products'])) {
         $response['products'] = $response['carousel']['products'];
     }
     //Get upcoming product
     $response['upcoming'] = Model_Client::getUpcomingProduct();
     if (!empty($response['upcoming']['product_id'])) {
         $response['products'][] = $response['upcoming']['product_id'];
         if (!empty($response['upcoming']['date'])) {
             $response['upcoming']['date'] = date('Y/m/d', strtotime($response['upcoming']['date']));
         }
     }
     $recent = Model_Main::getNewestProducts(3, $id, TRUE);
     if (!empty($recent)) {
         $response['recent'] = $recent;
         array_merge($response['products'], $recent);
     }
     $response['icon_size'] = Config::get('images.sm_icon_size');
     $response['thumbs_path'] = Config::get('system_settings.product_public_path');
     $response['carousel']['title'] = trans('client.similar_products');
     // Get products data
     $response['products'] = Model_Main::getProducts($response['products'], ['title', 'images', 'sizes', 'description']);
     // Send products to response
     $response['products'] = self::prepareProductsForResponse($response['products']);
     //Check dimensions table
     if (!empty($response['product']['dimensions_table'])) {
         $response['product']['dimensions_table'] = trim($response['product']['dimensions_table']);
     }
     return $response;
 }
Beispiel #5
0
 public function rss()
 {
     // create new feed
     $feed = App::make("feed");
     // cache the feed for 60 minutes (second parameter is optional)
     $feed->setCache(30, 'laravelFeedKey');
     // check if there is cached feed and build new only if is not
     if (!$feed->isCached()) {
         // creating rss feed with our most recent 20 posts
         $products = Model_Main::getProducts(FALSE, ['title', 'description', 'meta_description', 'images'], FALSE, 0, 20);
         $products_copy = $products;
         $pubdate = reset($products_copy);
         $pubdate = isset($pubdate['created_at']) ? $pubdate['created_at'] : date('Y.m.d H:i:s');
         unset($products_copy);
         // set your feed's title, description, link, pubdate and language
         $feed->title = $this->system['title'];
         $feed->description = $this->system['meta_description'];
         $feed->logo = url('/images/logo.png');
         $feed->link = url('rss');
         $feed->setDateFormat('datetime');
         // 'datetime', 'timestamp' or 'carbon'
         $feed->pubdate = $pubdate;
         //$posts[0]->created_at;
         $feed->lang = Lang::locale();
         $feed->setShortening(true);
         // true or false
         $feed->setTextLimit(255);
         // maximum length of description text
         $feed->ctype = "text/xml";
         $public_path = Config::get('system_settings.product_public_path');
         $full_size = Config::get('images.full_size');
         //			Loop trough products
         foreach ($products as $key => $product) {
             $product['meta_description'] = isset($product['meta_description']) ? $product['meta_description'] : '';
             $product['description'] = isset($product['description']) ? strip_tags($product['description']) : '';
             $product['description'] = trim(preg_replace('/\\s\\s+/', ' ', $product['description']));
             //Fetch images
             if (!empty($product['images']) && is_array(json_decode($product['images'], TRUE))) {
                 $products[$key]['images'] = json_decode($product['images'], TRUE);
                 //Order images
                 uasort($products[$key]['images'], function ($a, $b) {
                     if ($a == $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 $enclosure = [];
                 //Add to feed
                 foreach ($products[$key]['images'] as $image => $position) {
                     $enclosure[] = ['url' => url($public_path . $product['id'] . '/' . $full_size . '/' . $image), 'type' => 'image/jpeg'];
                 }
             }
             $enclosure = reset($enclosure);
             // set item's title, author, url, pubdate, description, content, enclosure (optional)*
             $feed->add($product['title'], $this->system['title'], URL::to('/' . $product['slug']), $product['created_at'], $product['meta_description'], $product['description'], $enclosure);
         }
     }
     // first param is the feed format
     // optional: second param is cache duration (value of 0 turns off caching)
     // optional: you can set custom cache key with 3rd param as string
     return $feed->render('rss', 1, 'laravelFeedKey');
 }
 private function getNavPages()
 {
     View::share('navigation_pages', Model_Main::getNavPages());
 }