コード例 #1
0
 public function ajaxshowCalendar()
 {
     $id_lang = Context::getContext()->language->id;
     $id_shop = Tools::getValue('ids');
     $shop = new AphStore($id_shop, Context::getContext()->language->id);
     $shop->hours = json_decode($shop->hours, true);
     $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
     $context = Context::getContext();
     $context->shop->id = $id_shop;
     $dates = array();
     $dday = Tools::getValue('date');
     for ($i = 2; $i > 0; $i--) {
         if (date('Y-m-d', strtotime('-' . $i . ' day', strtotime($dday))) >= date('Y-m-d')) {
             $dates[] = date('Y-m-d', strtotime('-' . $i . ' day', strtotime($dday)));
         }
     }
     $dates[] = $dday;
     for ($d = sizeof($dates), $i = 1; $d < 5; $d++, $i++) {
         $dates[] = date('Y-m-d', strtotime('+' . $i . ' day', strtotime($dday)));
     }
     $id_product = Tools::getValue('id_product');
     $product = new Product($id_product, true, $id_lang, $id_shop);
     $product_need_tools = false;
     $product_need_employees = true;
     $service_duration = 0;
     $_features = Product::getFrontFeaturesStatic($id_lang, $id_product);
     foreach ($_features as &$feature) {
         if ($product->id_service_duration > 0 && $feature['id_feature'] == $product->id_service_duration) {
             $service_duration = (int) substr($feature['value'], 0, -1);
         }
         if ($product->id_service_duration < 1 && $feature['id_feature'] == Configuration::get('APH_FEATURE_DURATION')) {
             $service_duration = (int) substr($feature['value'], 0, -1);
         }
         if ($feature['id_feature'] == Configuration::get('APH_FEATURE_SERVICE_BY')) {
             if ((int) $feature['value'] == (int) Configuration::get('APH_FEATURE_SERVICE_BY_NO_EMPLOYEE')) {
                 $product_need_employees = false;
             }
         }
         $service_duration = (int) substr($feature['value'], 0, -1);
     }
     $id_tool = 0;
     $necessary_quantity_of_tool = 0;
     $products_use_this_tool = array();
     $tool = AphTool::getByShopAndProduct($id_shop, $id_product);
     if (!empty($tool)) {
         $id_tool = $tool[0]['id_tool'];
         $necessary_quantity_of_tool = $tool[0]['quantity'];
         $product_need_tools = true;
         $_products = AphTool::getProducts($id_tool);
         if (!empty($_products)) {
             foreach ($_products as &$_product) {
                 $products_use_this_tool[] = $_product['id_product'];
             }
         }
     }
     $employees = array();
     if ($product_need_employees) {
         $_employees = AphEmployeeProduct::getEmployeesByShopAndProduct($id_shop, $id_product);
         foreach ($_employees as &$employee) {
             $employees[] = $employee['id_employee'];
         }
     }
     $time_slice = (int) Configuration::get('APH_CALENDAR_TIME_SLICE_ONLINE');
     if ($service_duration > $time_slice) {
         for ($t = 1; $t <= 4; $t++) {
             if ($time_slice * $t >= $service_duration) {
                 $time_slice = $time_slice * $t;
                 break;
             }
         }
     }
     /*$attributues_by_value = array();
       $attributues = $product->getAttributesResume($id_lang, ': ', ', ');
       foreach ($attributues as &$attribute) {
           list($giorno, $orario) = explode(', ', $attribute['attribute_designation']);
           list(, $giorno) = explode(': ', $giorno);
           list(, $giorno) = explode(' ', $giorno);
           list(, $orario) = explode(': ', $orario);
           list(, $orario) = explode(' ', $orario);
           if (!array_key_exists($giorno, $attributues_by_value))
               $attributues_by_value[$giorno] = array();
           $attributues_by_value[$giorno][strval($orario)] = $attribute['id_product_attribute'];
       }*/
     $first_day = $last_day = NULL;
     $days = array();
     foreach ($dates as $day) {
         if (empty($first_day)) {
             $first_day = $day;
         }
         $last_day = $day;
         $days[$day] = array('date' => $day, 'date_ts' => strtotime($day), 'class' => 'store_opened', 'status' => 'opened', 'available' => true, 'price_from' => $product->price, 'times_tot' => 0, 'times_not_available' => 0, 'times_full' => 0, 'times' => array());
         $days[$day]['date_lang'] = date('d/m/Y', $days[$day]['date_ts']);
         $days[$day]['week_day'] = date('w', $days[$day]['date_ts']);
         $days[$day]['week_day_lang'] = $this->week_days[(int) date('w', $days[$day]['date_ts'])];
         $days[$day]['month_lang'] = $this->months[(int) date('w', $days[$day]['date_ts'])];
         if (!empty($shop->hours[date('w', $days[$day]['date_ts'])])) {
             $hour_1 = $shop->hours[date('w', $days[$day]['date_ts'])][1];
             $hour_2 = $shop->hours[date('w', $days[$day]['date_ts'])][2];
             if ($hour_1['o'] == 'X' && $hour_1['c'] == 'X' && $hour_2['o'] == 'X' && $hour_2['c'] == 'X') {
                 $days[$day]['status'] = 'closed';
                 $days[$day]['available'] = false;
             } else {
                 $time_start = $hour_1['o'] == 'X' ? $hour_2['o'] : $hour_1['o'];
                 $time_end = $hour_2['c'] == 'X' ? $hour_1['c'] : $hour_2['c'];
                 $pause_start = $hour_1['c'] == 'X' ? false : $hour_1['c'];
                 $pause_end = $hour_2['o'] == 'X' ? false : $hour_2['o'];
             }
         } else {
             $days[$day]['status'] = 'closed';
             $days[$day]['available'] = false;
         }
         if (!empty($shop->rights_hasCalendar)) {
             if ($days[$day]['status'] == 'closed') {
                 // apertura straordinaria
                 $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, 1);
                 if (!empty($shop_availability)) {
                     $days[$day]['status'] = 'opened';
                     $days[$day]['available'] = true;
                 }
             } else {
                 // chiusura straordinaria
                 $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, -1);
                 if (!empty($shop_availability)) {
                     $days[$day]['status'] = 'closed';
                     $days[$day]['available'] = false;
                 }
             }
             if ($days[$day]['status'] == 'closed') {
                 $days[$day]['class'] = 'store_closed';
                 $days[$day]['available'] = false;
                 continue;
             }
         }
         // almeno un'offerta disponibile nel giorno
         $shop_offers = AphOffer::getByDate($id_shop, $id_product, $day, 1);
         if (!empty($shop_offers)) {
             $days[$day]['status'] = 'promoted';
             $days[$day]['class'] = 'store_promoted';
         }
         print_r($days[$day]['available']);
         if (!empty($days[$day]['available'])) {
             $times = array();
             for ($hours = substr($time_start, 0, 2); $hours < substr($time_end, 0, 2); $hours++) {
                 // the interval for hours is '1'
                 for ($mins = 0; $mins < 60; $mins += $time_slice) {
                     // the interval for mins is 'APH_CALENDAR_TIME_SLICE'
                     $t = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT);
                     // se sto valutanto l'orario nella pausa allora lo ignoro
                     if (!empty($pause_start) && !empty($pause_end) && $t >= $pause_start && $t < $pause_end) {
                         continue;
                     }
                     $times[$t] = array('time' => $t, 'available' => false, 'status' => 'available', 'class' => $days[$day]['class']);
                     $times[$t]['from'] = $t;
                     $time = new DateTime($day . ' ' . $times[$t]['from']);
                     $time->add(new DateInterval('PT' . $service_duration . 'M'));
                     $times[$t]['to'] = $time->format('H:i');
                     if ($times[$t]['to'] > $time_end) {
                         $times[$t]['available'] = false;
                         $times[$t]['status'] = 'available';
                         $times[$t]['class'] .= ' time_notavailable';
                         $days[$day]['times_not_available']++;
                     }
                     $days[$day]['times_tot']++;
                     if (!empty($shop->rights_hasCalendar)) {
                         $completed_orders = AphOrderDetail::getBetweenTimes($id_shop, 0, 0, $days[$day]['date_ts'], $times[$t]['from'], $times[$t]['to']);
                         if ($product_need_tools && !empty($products_use_this_tool)) {
                             $completed_orders_about_tool = AphOrderDetail::getBetweenTimes($id_shop, 0, $products_use_this_tool, $days[$day]['date_ts'], $times[$t]['from'], $times[$t]['to']);
                             $t = AphTool::getByDate($id_tool, $available_date);
                             $tool_is_availability = !empty($t) ? true : false;
                         } else {
                             $completed_orders_about_tool = array();
                         }
                         $availabilies_of_shop = AphAvailability::getBetweenTimes($id_shop, 0, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 1);
                         $not_availabilies_of_shop = AphAvailability::getBetweenTimes($id_shop, 0, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 0);
                         if ($product_need_employees && empty($not_availabilies_of_shop)) {
                             $working_employees = AphWorkingDay::getByEmployeeAndDateBetweenTimes($id_shop, $employees, $day, $times[$t]['from'], $times[$t]['to'], 1);
                             $availabilies_of_employees = AphAvailability::getBetweenTimes($id_shop, $employees, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 1);
                             $not_availabilies_of_employees = AphAvailability::getBetweenTimes($id_shop, $employees, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 0);
                         } else {
                             $working_employees = $availabilies_of_employees = $not_availabilies_of_employees = array();
                         }
                     }
                     // chiusura straordinaria
                     if (!empty($not_availabilies_of_shop)) {
                         $times[$t]['available'] = false;
                         $times[$t]['status'] = 'closed';
                         $times[$t]['class'] .= ' time_closed';
                         $days[$day]['times_not_available']++;
                         continue;
                     }
                     // slot di tempo esaurito per mancanza di dipendenti
                     if ($product_need_employees && !empty($completed_orders) && !empty($working_employees) && sizeof($completed_orders) >= sizeof($working_employees) - sizeof($not_availabilies_of_employees)) {
                         $times[$t]['available'] = false;
                         $times[$t]['status'] = 'full';
                         $times[$t]['class'] .= ' time_full';
                         $days[$day]['times_full']++;
                         continue;
                     }
                     // slot di tempo esaurito per mancanza di macchinari
                     if ($product_need_tools && !$tool_is_availability || !empty($necessary_quantity_of_tool) && !empty($completed_orders_about_tool) && sizeof($completed_orders_about_tool) >= $necessary_quantity_of_tool) {
                         $times[$t]['available'] = false;
                         $times[$t]['status'] = 'full';
                         $times[$t]['class'] .= ' time_full';
                         $days[$day]['times_full']++;
                         continue;
                     }
                     // apertura straordinaria (i macchinari sono sempre disponibili)
                     if ($product_need_employees && !empty($availabilies_of_employees) && !empty($completed_orders) && !empty($availabilies_of_employees) && sizeof($completed_orders) >= sizeof($availabilies_of_employees) - sizeof($not_availabilies_of_employees)) {
                         $times[$t]['available'] = false;
                         $times[$t]['status'] = 'full';
                         $times[$t]['class'] .= ' time_full';
                         $days[$day]['times_full']++;
                         continue;
                     }
                     $times[$t]['available'] = true;
                     $times[$t]['status'] = 'available';
                     $times[$t]['class'] .= ' time_available';
                     if (!empty($times[$t]['available'])) {
                         //error_log(var_export(__LINE__,true));
                         //$price = Product::getPriceStatic($id_product, true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, $context, true, $day, $times[$t]['from'], $times[$t]['to']);
                         //$times[$t]['price'] = $price;
                         $times[$t]['price'] = 0;
                         $times[$t]['price_label'] = Tools::displayPrice($times[$t]['price'], $id_currency);
                         if ($times[$t]['price'] < $days[$day]['price_from']) {
                             $days[$day]['price_from'] = $times[$t]['price'];
                         }
                     }
                 }
             }
             $days[$day]['times'] = $times;
             $days[$day]['price_from_label'] = Tools::displayPrice($days[$day]['price_from'], $id_currency);
             if ($days[$day]['times_full'] == $days[$day]['times']) {
                 $days[$day]['available'] = false;
                 $days[$day]['status'] = 'full';
                 $days[$day]['class'] = 'store_full';
             } elseif ($days[$day]['times_not_available'] == $days[$day]['times']) {
                 $days[$day]['available'] = false;
                 $days[$day]['status'] = 'closed';
                 $days[$day]['class'] = 'store_closed';
             }
         }
     }
     $jsVars = array();
     $jsVars['calendar_params'] = array('ajax' => 1, 'ajaxCall' => 'ajaxshowCalendar', 'id_product' => $id_product, 'ids' => $id_shop, 'date' => $dday, 'id_city' => empty($id_city) ? $shop->id_city : $id_city);
     $this->context->smarty->assign(array('days' => $days, 'dday' => $dday, 'first_day' => $days[$first_day], 'last_day' => $days[$last_day], 'jsVars' => $jsVars));
     // $jsVars = array(
     //     'language' => $this->context->language->iso_code,
     //     'slotDuration' => '00:'.Configuration::get('APH_CALENDAR_TIME_SLICE').':00'
     // );
     // $this->content .= '<script>var admin_aphcalendar = '.json_encode($jsVars).';</script>';
     return $this->display(__FILE__, 'availability_calendar.tpl', $this->getCacheId('blockmobilecart-column'));
 }
コード例 #2
0
 public function ajaxProcessEditProductOnOrder()
 {
     // Return value
     $res = true;
     $order = new Order((int) Tools::getValue('id_order'));
     $order_detail = new AphOrderDetail((int) Tools::getValue('product_id_order_detail'));
     if (Tools::isSubmit('product_invoice')) {
         $order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));
     }
     // Check fields validity
     $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
     // If multiple product_quantity, the order details concern a product customized
     $product_quantity = 0;
     if (is_array(Tools::getValue('product_quantity'))) {
         foreach (Tools::getValue('product_quantity') as $id_customization => $qty) {
             // Update quantity of each customization
             Db::getInstance()->update('customization', array('quantity' => (int) $qty), 'id_customization = ' . (int) $id_customization);
             // Calculate the real quantity of the product
             $product_quantity += $qty;
         }
     } else {
         $product_quantity = Tools::getValue('product_quantity');
     }
     $product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);
     $product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);
     $total_products_tax_incl = $product_price_tax_incl * $product_quantity;
     $total_products_tax_excl = $product_price_tax_excl * $product_quantity;
     // Calculate differences of price (Before / After)
     $diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;
     $diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;
     // Apply change on OrderInvoice
     if (isset($order_invoice)) {
         // If OrderInvoice to use is different, we update the old invoice and new invoice
         if ($order_detail->id_order_invoice != $order_invoice->id) {
             $old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);
             // We remove cost of products
             $old_order_invoice->total_products -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
             $old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
             $res &= $old_order_invoice->update();
             $order_invoice->total_products += $order_detail->total_price_tax_excl;
             $order_invoice->total_products_wt += $order_detail->total_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl;
             $order_detail->id_order_invoice = $order_invoice->id;
         }
     }
     if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0) {
         $order_detail->unit_price_tax_excl = $product_price_tax_excl;
         $order_detail->unit_price_tax_incl = $product_price_tax_incl;
         $order_detail->total_price_tax_incl += $diff_price_tax_incl;
         $order_detail->total_price_tax_excl += $diff_price_tax_excl;
         if (isset($order_invoice)) {
             // Apply changes on OrderInvoice
             $order_invoice->total_products += $diff_price_tax_excl;
             $order_invoice->total_products_wt += $diff_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $diff_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $diff_price_tax_incl;
         }
         // Apply changes on Order
         $order = new Order($order_detail->id_order);
         $order->total_products += $diff_price_tax_excl;
         $order->total_products_wt += $diff_price_tax_incl;
         $order->total_paid += $diff_price_tax_incl;
         $order->total_paid_tax_excl += $diff_price_tax_excl;
         $order->total_paid_tax_incl += $diff_price_tax_incl;
         $res &= $order->update();
     }
     $old_quantity = $order_detail->product_quantity;
     $delivery_date_lang = Tools::getValue('product_delivery_date_lang');
     $delivery_time_from = Tools::getValue('product_delivery_time_from');
     $delivery_time_to = Tools::getValue('product_delivery_time_to');
     $id_employee = Tools::getValue('product_id_employee');
     $delivery_date = substr($delivery_date_lang, 6, 4) . '-' . substr($delivery_date_lang, 3, 2) . '-' . substr($delivery_date_lang, 0, 2);
     $order_detail->delivery_time_from = $delivery_time_from;
     $order_detail->delivery_time_to = $delivery_time_to;
     $order_detail->delivery_date = $delivery_date;
     $order_detail->id_employee = $id_employee;
     $order_detail->product_quantity = $product_quantity;
     $order_detail->reduction_percent = 0;
     // update taxes
     $res &= $order_detail->updateTaxAmount($order);
     // Save order detail
     $res &= $order_detail->update();
     // Update weight SUM
     $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
     if (Validate::isLoadedObject($order_carrier)) {
         $order_carrier->weight = (double) $order->getTotalWeight();
         $res &= $order_carrier->update();
         if ($res) {
             $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
         }
     }
     // Save order invoice
     if (isset($order_invoice)) {
         $res &= $order_invoice->update();
     }
     // Update product available quantity
     StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $old_quantity - $order_detail->product_quantity, $order->id_shop);
     $products = $this->getProducts($order);
     // Get the last product
     $product = $products[$order_detail->id];
     $resume = OrderSlip::getProductSlipResume($order_detail->id);
     $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
     $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
     $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']);
     $product['refund_history'] = OrderSlip::getProductSlipDetail($order_detail->id);
     if ($product['id_warehouse'] != 0) {
         $warehouse = new Warehouse((int) $product['id_warehouse']);
         $product['warehouse_name'] = $warehouse->name;
         $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']);
         if (!empty($warehouse_location)) {
             $product['warehouse_location'] = $warehouse_location;
         } else {
             $product['warehouse_location'] = false;
         }
     } else {
         $product['warehouse_name'] = '--';
         $product['warehouse_location'] = false;
     }
     // Get invoices collection
     $invoice_collection = $order->getInvoicesCollection();
     $invoice_array = array();
     foreach ($invoice_collection as $invoice) {
         /** @var OrderInvoice $invoice */
         $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop);
         $invoice_array[] = $invoice;
     }
     $options_time = array();
     $time_slice = Configuration::get('APH_CALENDAR_TIME_SLICE');
     for ($hours = 0; $hours < 24; $hours++) {
         // the interval for hours is '1'
         for ($mins = 0; $mins < 60; $mins += $time_slice) {
             // the interval for mins is 'APH_CALENDAR_TIME_SLICE'
             $options_time[str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT)] = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT);
         }
     }
     $this->context->smarty->assign(array('options_time' => $options_time));
     $employees = array();
     $e = AphEmployeeProduct::getEmployeesByShop((int) Context::getContext()->shop->id);
     foreach ($e as $employee) {
         $employees[$employee['id_employee']] = $employee['fullName'];
     }
     $this->context->smarty->assign(array('employees' => $employees));
     // Assign to smarty informations in order to show the new product line
     $this->context->smarty->assign(array('product' => $product, 'order' => $order, 'currency' => new Currency($order->id_currency), 'can_edit' => $this->tabAccess['edit'], 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex, 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')));
     if (!$res) {
         die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('An error occurred while editing the product line.'))));
     }
     if (is_array(Tools::getValue('product_quantity'))) {
         $view = $this->createTemplate('_customized_data.tpl')->fetch();
     } else {
         $view = $this->createTemplate('_product_line.tpl')->fetch();
     }
     $this->sendChangedNotification($order);
     die(Tools::jsonEncode(array('result' => $res, 'view' => $view, 'can_edit' => $this->tabAccess['add'], 'invoices_collection' => $invoice_collection, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(), 'customized_product' => is_array(Tools::getValue('product_quantity')))));
 }
コード例 #3
0
 public function fetchEmployees()
 {
     $employees = AphEmployeeProduct::getEmployeesByShop(!empty($this->object) ? $this->object->id_shop : Context::getContext()->shop->id);
     $this->context->smarty->assign(array("employees" => $employees));
 }
コード例 #4
0
 public function initContent()
 {
     parent::initContent();
     $specific_price = NULL;
     $date = Tools::getValue('date');
     if (empty($date) || empty($date)) {
         $date = date('Y-m-d', strtotime('+2 day'));
     }
     $id_product = Tools::getValue('id_product');
     if (!empty($date)) {
         $product = new Product($id_product, true, Context::getContext()->language->id, Context::getContext()->shop->id);
     }
     if (empty($product)) {
         $this->setTemplate('availability_no_product.tpl');
         error_log(__LINE__);
         return;
     }
     $id_shop = (int) Tools::getValue('ids');
     $id_city = (int) Tools::getValue('id_city');
     if (empty($id_shop) && empty($id_city)) {
         $this->setTemplate('availability_no_location.tpl');
         error_log(__LINE__);
         return;
     }
     if (!empty($id_shop)) {
         $shop = NULL;
         $alias_shop = (int) Tools::getValue('ash');
         if (!empty($alias_shop)) {
             $_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id);
             $id_shop = $_s['id_shop'];
         } else {
             $id_shop = (int) Tools::getValue('ids');
         }
         $shop = new AphStore($id_shop, Context::getContext()->language->id);
         $cover = NULL;
         $images = AphStoreImage::getImages(Context::getContext()->language->id, $id_shop);
         foreach ($images as &$image) {
             if (!empty($image['cover'])) {
                 $cover = $image;
             }
         }
         if (empty($cover) && !empty($images)) {
             $cover = $images[0];
         }
     }
     if (empty($id_shop) && !empty($id_city)) {
         $city = AphCity::getCity($id_city);
         if (empty($city) && empty($id_shop)) {
             $this->setTemplate('availability_no_city.tpl');
             return;
         }
         $shops = AphStore::getByCity($id_city, Context::getContext()->language->id);
         if (empty($shops)) {
             $shops = array();
             $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
             $_shops = AphStore::getStoresByProduct($id_product, Context::getContext()->language->id, null, 100000);
             foreach ($_shops as &$shop) {
                 if ($this->distance($shop['latitude'], $shop['longitude'], $city['latitude'], $city['longitude'], 'K') > Configuration::get('APH_MAX_KM_FAR_AWAY')) {
                     continue;
                 }
                 $product = new Product($id_product, false, (int) Context::getContext()->language->id, (int) $shop['id_shop']);
                 $price = Product::getPriceStatic($id_product, true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, Context::getContext(), true, $date);
                 if (empty($price)) {
                     $price = $product->price;
                 } else {
                     $price = $price;
                 }
                 $shop['price_from'] = Tools::displayPrice($price, $id_currency);
                 //$url = !empty($ssl) ? 'https://'.$shop['domain_ssl'] : 'http://'.$shop['domain'];
                 //$shop['url'] = $url.$shop['uri'];
                 $shop['url'] = Context::getContext()->link->getModuleLink('blockmobilecart', 'availability', array('id_product' => $id_product, 'date' => $date, 'ids' => $shop['id_shop']));
                 $shop['img_link_rewrite'] = Tools::link_rewrite($shop['legend']);
                 $shops[] = $shop;
             }
             if (empty($shops)) {
                 $this->context->smarty->assign(array('availability_no_closure_shops' => true));
             } else {
                 $this->context->smarty->assign(array('shops' => $shops, 'availability_no_shops' => true, 'availability_no_shops_city' => $city['name'], 'availability_no_shops_km' => Configuration::get('APH_MAX_KM_FAR_AWAY')));
             }
             $this->setTemplate('availability_shops.tpl');
             return;
         }
     } else {
         $shop = new AphStore($id_shop, Context::getContext()->language->id);
         if (empty($shop) && empty($id_city)) {
             $this->setTemplate('availability_no_shop.tpl');
             error_log(__LINE__);
             return;
         }
         // il negozio non offre il servizio
         $product = new Product($id_product, true, Context::getContext()->language->id, $id_shop);
         $employees = AphEmployeeProduct::getEmployeesByShopAndProduct($id_shop, $id_product);
         if (empty($employees)) {
             $products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, 0, 20, 'name', 'asc', $product->id_category_default, true);
             foreach ($products as &$product) {
                 $p = new Product($product['id_product'], false, (int) Context::getContext()->language->id, $id_shop);
                 $price = Product::getPriceStatic($product['id_product'], true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, Context::getContext(), true, $date);
                 if (empty($price)) {
                     $price = $p->price;
                 } else {
                     $price = $price;
                 }
                 $product['price_from'] = Tools::displayPrice($price, $id_currency);
             }
             $this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'products' => $products, 'token' => Tools::getToken(false)));
             $this->setTemplate('availability_no_product_for_shop.tpl');
             return;
         }
     }
     if (empty($product)) {
         $this->setTemplate('availability_no_product.tpl');
         return;
     }
     $this->context->smarty->tpl_vars['meta_title']->value = 'Acquista ' . $product->name . ' presso ' . $shop->name;
     $this->context->smarty->tpl_vars['meta_description']->value = $shop->meta_description;
     // 	$products_by_category = array();
     // 	$categories = Category::getAllCategoriesName(NULL, Context::getContext()->language->id, true);
     // 	if (!empty($categories)){
     // 		foreach ($categories as &$category) {
     // 	 	$products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, NULL, NULL, 'name', 'desc', $category['id_category'], true);
     // 	 	foreach ($products as &$product) {
     // 	 		if (empty($products_by_category[ $category['id_category'] ])){
     // 		 		$products_by_category[ $category['id_category'] ] = array(
     // 		 			'id_category' => $category['id_category'],
     // 		 			'name' => $category['name'],
     // 		 			'class' => Tools::link_rewrite($category['name']),
     // 		 			'products' => array()
     // 		 		);
     // 		 	}
     // 		 	$products_by_category[ $category['id_category'] ]['products'][ $product['id_product'] ] = array(
     // 		 		'id_product' => $product['id_product'],
     // 		 		'name' => $product['name'],
     // 		 		'link' => Context::getContext()->link->getProductLink((int)$product['id_product'], $product['link_rewrite'], $category['id_category'], $product['ean13'])
     // 		 	);
     // 	 	}
     //  	}
     // }
     $jsVars = array();
     $jsVars['calendar_params'] = array('ajax' => 1, 'ajaxCall' => 'ajaxshowCalendar', 'id_product' => $id_product, 'ids' => $id_shop, 'date' => $date, 'id_city' => empty($id_city) ? $shop->id_city : $id_city);
     $this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'product' => $product, 'token' => Tools::getToken(false), 'jsVars' => $jsVars));
     $this->setTemplate('availability_full.tpl');
 }
コード例 #5
0
 /**
  * @param Offer $obj
  * @throws Exception
  * @throws PrestaShopException
  * @throws SmartyException
  */
 public function initFormProducts($obj)
 {
     $employee = $obj;
     $data = $this->createTemplate('products.tpl');
     // Selected products
     $selected_products = array();
     $products = AphEmployeeProduct::getProductsByEmployee($employee->id);
     if (!empty($products)) {
         foreach ($products as $product) {
             $selected_products[] = $product['id_product'];
         }
     }
     // Generate category selection tree
     $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio'));
     $tree->setAttribute('selected_products', $selected_products);
     $tree->setInputName('checkBoxProductAsso_employee');
     $tree->setSelectedProducts($selected_products);
     $tree->setUseShopRestriction(true);
     if (!empty($employee->id)) {
         $shops = $employee->getAssociatedShops();
         if (!empty($shops)) {
             $tree->setShop(new Shop($shops[0]));
         }
     }
     $data->assign('product_tree', $tree->render());
     $data->assign(array('dipendente' => $employee, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP));
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
コード例 #6
0
 public function ajaxProcessEditOrder()
 {
     if ((int) Tools::getValue('id_order_detail') < 1) {
         return 'Appuntamento non trovato.';
     }
     $copy_order = false;
     if ((bool) Tools::getIsset('copyorder')) {
         $copy_order = true;
     }
     $order_detail = new AphOrderDetail(Tools::getValue('id_order_detail'));
     $order = new Order($order_detail->id_order);
     $customer = new Customer($order->id_customer);
     $address = new Address($order->id_address_invoice);
     $this->context->smarty->assign('id_order', empty($copy_order) ? $order_detail->id_order : NULL);
     $this->context->smarty->assign('id_order_detail', empty($copy_order) ? $order_detail->id_order_detail : NULL);
     $this->context->smarty->assign('id_customer', $order->id_customer);
     $this->context->smarty->assign('delivery_date', $order_detail->delivery_date);
     $this->context->smarty->assign('delivery_date_lang', date('d/m/Y', strtotime($order_detail->delivery_date)));
     $this->context->smarty->assign('delivery_time_from', substr($order_detail->delivery_time_from, 0, 5));
     $this->context->smarty->assign('delivery_time_to', substr($order_detail->delivery_time_to, 0, 5));
     $this->context->smarty->assign('id_employee', empty($copy_order) ? $order_detail->id_employee : NULL);
     $this->context->smarty->assign('other', $order_detail->note);
     $this->context->smarty->assign('firstname', $customer->firstname);
     $this->context->smarty->assign('lastname', $customer->lastname);
     $this->context->smarty->assign('id_gender', $customer->id_gender);
     $this->context->smarty->assign('email', $customer->email);
     $this->context->smarty->assign('phone', !empty($address->phone_mobile) ? $address->phone_mobile : $address->phone);
     $selected = array($order_detail->product_id);
     $products = array('selected' => array(), 'unselected' => array());
     $results = Db::getInstance()->executeS('
     SELECT DISTINCT name, p.id_product as id
     FROM ' . _DB_PREFIX_ . 'product p
     LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
         ON (p.`id_product` = pl.`id_product`
         AND pl.`id_lang` = ' . (int) Context::getContext()->language->id . Shop::addSqlRestrictionOnLang('pl') . ')
     ' . Shop::addSqlAssociation('product', 'p') . '
     WHERE id_lang = ' . (int) Context::getContext()->language->id . '
     ORDER BY name');
     foreach ($results as $row) {
         $products[in_array($row['id'], $selected) ? 'selected' : 'unselected'][] = $row;
     }
     $choose_content = Context::getContext()->smarty->createTemplate(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/controllers/calendar/product_itemlist.tpl');
     $choose_content->assign('product_itemlist', $products);
     $this->context->smarty->assign('product_choose_content', $choose_content->fetch());
     $employees = AphEmployeeProduct::getEmployeesByShop((int) $this->context->shop->id);
     $this->context->smarty->assign('employees', $employees);
     $options_time = array();
     $time_slice = Configuration::get('APH_CALENDAR_TIME_SLICE');
     for ($hours = 0; $hours < 24; $hours++) {
         // the interval for hours is '1'
         for ($mins = 0; $mins < 60; $mins += $time_slice) {
             // the interval for mins is 'APH_CALENDAR_TIME_SLICE'
             $options_time[str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT)] = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT);
         }
     }
     $this->context->smarty->assign('options_time', $options_time);
     $this->context->smarty->assign(array('current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex));
     $jsVars = array('language' => $this->context->language->iso_code, 'slotDuration' => '00:' . Configuration::get('APH_CALENDAR_TIME_SLICE') . ':00');
     $this->setJsVars($jsVars);
     $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/controllers/calendar/order.tpl');
     return parent::initContent();
 }
コード例 #7
0
ファイル: AphStore.php プロジェクト: paolobattistella/aphro
 public function add($form, $owner_id = NULL)
 {
     $theme = Theme::getByDirectory('aphrodinet');
     $sql1 = "INSERT INTO `" . _DB_PREFIX_ . "shop` (`id_shop_group`,`name`,`id_theme`) VALUES ('" . $form['id_shop_group'] . "','" . $form['name'] . "','" . $theme->id . "')";
     $res = Db::getInstance()->execute($sql1);
     if (!$res) {
         error_log(__FILE__ . ' on line ' . __LINE__);
     }
     if (!$res) {
         return false;
     }
     $shopid = Db::getInstance()->Insert_ID();
     $sql2 = "INSERT INTO `" . _DB_PREFIX_ . "store` (`name`,`address1`,`address2`,`postcode`,`city`,`id_country`,`id_state`,`id_city`,`latitude`,`longitude`,`phone`,`fax`,`email`,`note`,`active`,`description`,`description_short`,`navigation`,`date_add`,`date_upd`,`rights_hasLogin`,`rights_hasCalendar`,`rights_canEditPrices`,`rights_hasPaymentOffline`,`hours`,`meta_title`,`meta_description`,`link_facebook`,`link_googleplus`,`link_youtube`,`link_instagram`,`link_pinterest`,`link_twitter`,`bo_color`) " . "VALUES ('" . pSQL($form['name']) . "','" . pSQL($form['address1']) . "','" . pSQL($form['address2']) . "','" . $form['postcode'] . "','" . pSQL($form['city']) . "','" . $form['id_country'] . "','" . $form['id_state'] . "','" . $form['id_city'] . "','" . $form['latitude'] . "','" . $form['longitude'] . "','" . $form['phone'] . "','" . $form['fax'] . "','" . $form['email'] . "','" . pSQL($form['note']) . "','" . $form['active'] . "','" . pSQL($form['description']) . "','" . pSQL($form['description_short']) . "','" . pSQL($form['navigation']) . "','" . date('Y-m-d H:i:s') . "','" . date('Y-m-d H:i:s') . "','" . $form['rights_hasLogin'] . "','" . $form['rights_hasCalendar'] . "','" . $form['rights_canEditPrices'] . "','" . $form['rights_hasPaymentOffline'] . "','{$this->hours}','" . $form['meta_title'] . "','" . $form['meta_description'] . "','" . $form['link_facebook'] . "','" . $form['link_googleplus'] . "','" . $form['link_youtube'] . "','" . $form['link_instagram'] . "','" . $form['link_pinterest'] . "','" . $form['link_twitter'] . "','" . $form['bo_color'] . "')";
     $res = Db::getInstance()->execute($sql2);
     if (!$res) {
         error_log(__FILE__ . ' on line ' . __LINE__);
     }
     if (!$res) {
         return false;
     }
     $storeid = Db::getInstance()->Insert_ID();
     $this->id = $storeid;
     if (!empty($form['login'])) {
         $emp = new AphEmployeeProduct(null, Context::getContext()->language->id, $shopid);
         $emp->firstname = $_POST['firstname'];
         $emp->lastname = $_POST['lastname'];
         $emp->email = $_POST['employee_l'];
         $emp->id_lang = Context::getContext()->language->id;
         $emp->passwd = Tools::encrypt($_POST['employee_p']);
         $emp->bo_theme = 'aphrodinet';
         $emp->bo_css = 'admin-theme.css';
         $emp->default_tab = 108;
         $emp->active = 1;
         $emp->bo_color = $_POST['bo_color'];
         $emp->id_profile = Configuration::get('APH_PROFILE_STORE_OWNER');
         $emp->add();
         $sql2 = "DELETE FROM `" . _DB_PREFIX_ . "employee_shop` WHERE `id_employee`='" . $emp->id . "' AND `id_shop`!='" . $shopid . "'";
         $res = Db::getInstance()->execute($sql2);
         if (!$res) {
             error_log(__FILE__ . ' on line ' . __LINE__);
         }
         if (!$res) {
             return false;
         }
         $sql2 = "INSERT INTO `" . _DB_PREFIX_ . "employee_shop` (`id_employee`,`id_shop`) VALUES ('" . $emp->id . "','" . $shopid . "')";
         $res = Db::getInstance()->execute($sql2);
         if (!$res) {
             error_log(__FILE__ . ' on line ' . __LINE__);
         }
         if (!$res) {
             return false;
         }
     }
     $host = Tools::getHttpHost();
     $request_uri = explode('/', rawurldecode($_SERVER['REQUEST_URI']));
     $sql2 = "INSERT INTO `" . _DB_PREFIX_ . "shop_url` (`id_shop`,`domain`,`domain_ssl`,`physical_uri`,`virtual_uri`,`main`,`active`) VALUES ('{$shopid}','" . pSQL($host) . "', '" . pSQL($host) . "', '/','" . $form['link_rewrite'] . "','1','1')";
     $res = Db::getInstance()->execute($sql2);
     if (!$res) {
         error_log($sql2 . ':' . __FILE__ . ' on line ' . __LINE__);
     }
     if (!$res) {
         return false;
     }
     $sql3 = "INSERT INTO `" . _DB_PREFIX_ . "store_shop` (`id_store`,`id_shop`) VALUES ('{$storeid}','{$shopid}')";
     $res = Db::getInstance()->execute($sql3);
     if (!$res) {
         error_log(__FILE__ . ' on line ' . __LINE__);
     }
     if (!$res) {
         return false;
     }
     $this->fillDefaultValues($shopid);
     if (!empty($form['hasPaymentOffline'])) {
         $payment_methods = explode(',', Configuration::get('APH_OFFLINE_PAYMENT_METHODS'));
         $sqlD = 'DELETE FROM `' . _DB_PREFIX_ . 'module_shop` WHERE id_shop=' . $shopid . ' AND `id_module` IN (SELECT `id_module`  FROM `' . _DB_PREFIX_ . 'module` WHERE `name` IN ("' . implode('","', $payment_methods) . '"))';
         Db::getInstance()->execute($sqlD);
         foreach ($payment_methods as &$method) {
             $sql = 'SELECT c.`id_module` FROM `' . _DB_PREFIX_ . 'module` WHERE `name`=`' . $method . '`';
             $items = Db::getInstance()->executeS($sql);
             if ($items) {
                 foreach ($items as $item) {
                     $sqlI = 'INSERT INTO `' . _DB_PREFIX_ . 'module_shop` (`id_shop`,`id_module`,`enable_device`) VALUES (' . $shopid . ',' . $item['id_module'] . ', 1)';
                     Db::getInstance()->execute($sqlI);
                 }
             }
         }
     }
     return true;
 }