Example #1
0
 /**
  * @param	Product $product
  * @param	integer $qtd
  */
 public function __construct(Product $product, $qtd)
 {
     parent::__construct();
     $resourceBundle = Application::getInstance()->getBundle();
     $idProduct = $product->getIdProduct();
     $moneyformat = $resourceBundle->getString('MONEY_FORMAT');
     $productName = $product->getProductName();
     $productDescription = $product->getProductDescription();
     $productPrice = $product->getProductPrice();
     $form = $this->addChild(new Form('/?c=cart&a=change&p=' . $idProduct));
     //Imagem do produto
     $form->addChild(new Image($product->getProductImage(), $productName))->setTitle($productName)->setAttribute('width', 80)->setAttribute('height', 80);
     //Nome e descrição do produto
     $form->addChild(new Span())->addStyle('name')->addChild(new Text($productName));
     $form->addChild(new Span())->addStyle('desc')->addChild(new Text($productDescription));
     //Input com a quantidade de itens
     $form->addChild(new Label(new Text($resourceBundle->getString('QUANTITY'))))->addChild(new Input('qtd'))->setValue($qtd);
     //Preço unitário
     $form->addChild(new Span())->addStyle('price')->addChild(new Text(money_format($moneyformat, $productPrice)));
     //Preço total
     $form->addChild(new Span())->addStyle('total')->addChild(new Text(money_format($moneyformat, $qtd * $productPrice)));
     //Botões para edição e exclusão do item do carrinho
     $form->addChild(new Input('save', Input::SUBMIT))->setValue($resourceBundle->getString('SAVE'));
     $form->addChild(new Input('del', Input::SUBMIT))->setValue($resourceBundle->getString('DELETE'));
 }
Example #2
0
 /**
  * Initialize order controller
  * @see FrontController::init()
  */
 public function init()
 {
     global $orderTotal;
     parent::init();
     $this->step = (int) Tools::getValue('step');
     if (!$this->nbProducts) {
         $this->step = -1;
     }
     $product = $this->context->cart->checkQuantities(true);
     if ((int) ($id_product = $this->context->cart->checkProductsAccess())) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('An item in your cart is no longer available (%1s). You cannot proceed with your order.'), Product::getProductName((int) $id_product));
     }
     // If some products have disappear
     if (is_array($product)) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('An item (%1s) in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.'), $product['name']);
     }
     // Check minimal amount
     $currency = Currency::getCurrency((int) $this->context->cart->id_currency);
     $orderTotal = $this->context->cart->getOrderTotal();
     $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
     if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step > 0) {
         $this->step = 0;
         $this->errors[] = sprintf(Tools::displayError('A minimum purchase total of %1s (tax excl.) is required to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency));
     }
     if (!$this->context->customer->isLogged(true) && in_array($this->step, array(1, 2, 3))) {
         $params = array();
         if ($this->step) {
             $params['step'] = (int) $this->step;
         }
         if ($multi = (int) Tools::getValue('multi-shipping')) {
             $params['multi-shipping'] = $multi;
         }
         $back_url = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, $params);
         $params = array('back' => $back_url);
         if ($multi) {
             $params['multi-shipping'] = $multi;
         }
         if ($guest = (int) Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
             $params['display_guest_checkout'] = $guest;
         }
         Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params));
     }
     if (Tools::getValue('multi-shipping') == 1) {
         $this->context->smarty->assign('multi_shipping', true);
     } else {
         $this->context->smarty->assign('multi_shipping', false);
     }
     if ($this->context->customer->id) {
         $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
     } else {
         $this->context->smarty->assign('address_list', array());
     }
 }
    /**
     * Method called when an ajax request is made
     * @see AdminController::postProcess()
     */
    public function ajaxProcess()
    {
        if (Tools::isSubmit('id')) {
            $this->lang = false;
            $lang_id = (int) $this->context->language->id;
            $id_product = (int) Tools::getValue('id');
            $period = Tools::getValue('period') ? (int) Tools::getValue('period') : 7;
            $warehouse = Tools::getValue('id_warehouse', -1);
            $where_warehouse = '';
            if ($warehouse != -1) {
                $where_warehouse = ' AND s.id_warehouse = ' . (int) $warehouse;
            }
            $query = new DbQuery();
            $query->select('pa.id_product_attribute as id, pa.id_product, stock_view.reference, stock_view.ean13,
							stock_view.upc, stock_view.usable_quantity as stock');
            $query->from('product_attribute', 'pa');
            $query->join('INNER JOIN
						  (
						  	SELECT SUM(s.usable_quantity) as usable_quantity, s.id_product_attribute, s.reference, s.ean13, s.upc
						   	FROM ' . _DB_PREFIX_ . 'stock s
						   	WHERE s.id_product = ' . $id_product . $where_warehouse . '
						   	GROUP BY s.id_product_attribute
						   )
						   stock_view ON (stock_view.id_product_attribute = pa.id_product_attribute)');
            $query->where('pa.id_product = ' . $id_product);
            $query->groupBy('pa.id_product_attribute');
            $datas = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
            foreach ($datas as &$data) {
                $data['name'] = Product::getProductName($data['id_product'], $data['id']);
                // computes coverage
                $coverage = StockManagerFactory::getManager()->getProductCoverage($data['id_product'], $data['id'], $period, $this->getCurrentCoverageWarehouse() == -1 ? null : $warehouse);
                if ($coverage != -1) {
                    if ($coverage < $this->getCurrentWarning()) {
                        // if highlight needed
                        $data['color'] = '#BDE5F8';
                    }
                    $data['coverage'] = $coverage;
                } else {
                    // infinity
                    $data['coverage'] = '--';
                }
                // computes quantity sold
                $qty_sold = $this->getQuantitySold($data['id_product'], $data['id'], $this->getCurrentCoveragePeriod());
                if (!$qty_sold) {
                    $data['qty_sold'] = '--';
                } else {
                    $data['qty_sold'] = $qty_sold;
                }
            }
            echo Tools::jsonEncode(array('data' => $datas, 'fields_display' => $this->fields_list));
        }
        die;
    }
Example #4
0
 /**
  * @param	Product $product
  */
 public function __construct(Product $product)
 {
     parent::__construct();
     $resourceBundle = Application::getInstance()->getBundle();
     $productName = $product->getProductName();
     $moneyFormat = $resourceBundle->getString('MONEY_FORMAT');
     $buy = $resourceBundle->getString('BUY');
     $definitionList = $this->addChild(new DefinitionList());
     $definitionList->addChild(new DefinitionTerm())->addChild(new Text($productName));
     $definitionList->addChild(new DefinitionDescription())->addStyle('description')->addChild(new Text($product->getProductDescription()));
     $definitionList->addChild(new DefinitionDescription())->addStyle('image')->addChild(new Image($product->getProductImage(), $productName))->setAttribute('width', 190)->setAttribute('height', 190)->setTitle($productName);
     $definitionList->addChild(new DefinitionDescription())->addStyle('price')->addChild(new Text(money_format($moneyFormat, $product->getProductPrice())));
     $this->addChild(new Anchor('/?c=cart&a=add&p=' . $product->getIdProduct()))->setTitle($buy)->addStyle('buy-button')->addChild(new Text($buy));
 }
 public static function getProductDetailsByParcels($parcels)
 {
     $products = array();
     foreach ($parcels as $parcel) {
         if (isset($parcel['id_parcel'])) {
             if ($products_array = self::getProductByIdParcel($parcel['id_parcel'])) {
                 foreach ($products_array as $product) {
                     if (self::isLabelPrinted($parcel['id_parcel'])) {
                         $product_data = self::getProductNameAndWeight($parcel['id_parcel'], $product['id_product'], $product['id_product_attribute']);
                         $products[] = array_merge($product, array('name' => $product_data['name'], 'weight' => (double) $product_data['weight'], 'id_parcel' => (int) $parcel['id_parcel']));
                     } else {
                         $product_obj = new Product($product['id_product']);
                         $combination = new Combination($product['id_product_attribute']);
                         $products[] = array_merge($product, array('name' => version_compare(_PS_VERSION_, '1.5', '<') ? $product_obj->name[(int) Context::getContext()->language->id] : Product::getProductName($product['id_product'], $product['id_product_attribute']), 'weight' => (double) $combination->weight + (double) $product_obj->weight, 'id_parcel' => (int) $parcel['id_parcel']));
                     }
                 }
             }
         }
     }
     return $products;
 }
Example #6
0
 protected function generateGroupProductList($productIds = array())
 {
     if (!$productIds) {
         return '';
     }
     $result = '';
     $langId = Context::getContext()->language->id;
     foreach ($productIds as $productId) {
         if ((int) $productId > 0) {
             $productName = Product::getProductName((int) $productId, null, $langId);
             if ($productName) {
                 $result .= '<li id="manual-product-' . $productId . '" class="manual-product">
                                 <input type="hidden" class="manual_product_id" name="product_ids[]" value="' . $productId . '" />
                                 <span>' . $productName . '</span>
                                 <a href="javascript:void(0)" title="' . $this->l('Delete') . '" class="link-trash-manual-product c-red pull-right" data-id="' . $productId . '"><i class="icon-trash"></i></a>
                             </li>';
             }
         }
     }
     return $result;
 }
Example #7
0
 private function saveProductsIntoParcel(DpdPolandParcel $parcel, $products)
 {
     foreach ($products as $product) {
         if ($product['parcel'] == $parcel->number) {
             $parcelProduct = new DpdPolandParcelProduct();
             $parcelProduct->id_parcel = (int) $parcel->id_parcel;
             $parcelProduct->id_product = (int) $product['id_product'];
             $parcelProduct->id_product_attribute = (int) $product['id_product_attribute'];
             $productObj = new Product((int) $product['id_product']);
             $combination = new Combination((int) $product['id_product_attribute']);
             $parcelProduct->name = version_compare(_PS_VERSION_, '1.5', '<') ? $productObj->name[(int) Context::getContext()->language->id] : Product::getProductName($product['id_product'], $product['id_product_attribute']);
             $parcelProduct->weight = (double) $combination->weight + (double) $productObj->weight;
             if (!$parcelProduct->add()) {
                 self::$errors[] = sprintf($this->l('Unable to save product #%s to parcel #%d'), $parcelProduct->id_product . '-' . $parcelProduct->id_product_attribute, $parcelProduct->id_parcel);
                 return false;
             }
         }
     }
     return true;
 }
 public function ajaxProcessAddDataToCart()
 {
     // for Add Quantity
     $id_room = Tools::getValue('id_room');
     $booking_type = Tools::getValue('booking_type');
     $comment = Tools::getValue('comment');
     // for both (add , delete)
     $id_hotel = Tools::getValue('id_hotel');
     $id_product = Tools::getValue('id_prod');
     $date_from = Tools::getValue('date_from');
     $date_to = Tools::getValue('date_to');
     $search_id_prod = Tools::getValue('search_id_prod');
     $search_date_from = Tools::getValue('search_date_from');
     $search_date_to = Tools::getValue('search_date_to');
     // for delete quantity
     $id_cart = Tools::getValue('id_cart');
     $id_cart_book_data = Tools::getValue('id_cart_book_data');
     $ajax_delete = Tools::getValue('ajax_delete');
     // If delete from cart(not for room list delete(pagebottom tabs))
     $opt = Tools::getValue('opt');
     // if 1 then add quantity or if 0 means delete quantity
     // discuss later
     //
     // $obj_hotel_info = new HotelBranchInformation();
     // $hotel_info = $obj_hotel_info->hotelBranchInfoById($id_hotel);
     // $date_from = date('Y-m-d H:i:s', strtotime("$date_from +".date('H', strtotime($hotel_info['check_in']))." hours +".date('i', strtotime($hotel_info['check_in']))." minutes"));
     // $date_to = date('Y-m-d H:i:s', strtotime("$date_to +".date('H', strtotime($hotel_info['check_out']))." hours +".date('i', strtotime($hotel_info['check_out']))." minutes"));
     $obj_booking_dtl = new HotelBookingDetail();
     $num_day = $obj_booking_dtl->getNumberOfDays($date_from, $date_to);
     //quantity of product
     $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'));
     // $id_product_attribute = $product->getDefaultIdProductAttribute();
     if ($opt) {
         // $cart_rules = $this->context->cart->getCartRules();
         $amount = Product::getPriceStatic($id_product, true, null, 6, null, false, true, $num_day);
     }
     if ($opt) {
         $direction = 'up';
     } else {
         $direction = 'down';
     }
     $this->context->cart->updateQty($num_day, $id_product, null, false, $direction);
     $total_amount = $this->context->cart->getOrderTotal();
     $id_cart = $this->context->cart->id;
     $id_guest = $this->context->cookie->id_guest;
     $obj_cart_book_data = new HotelCartBookingData();
     if ($opt) {
         $obj_cart_book_data->id_cart = $id_cart;
         $obj_cart_book_data->id_guest = $id_guest;
         $obj_cart_book_data->id_product = $id_product;
         $obj_cart_book_data->id_room = $id_room;
         $obj_cart_book_data->id_hotel = $id_hotel;
         $obj_cart_book_data->amount = $amount;
         $obj_cart_book_data->booking_type = $booking_type;
         $obj_cart_book_data->comment = $comment;
         $obj_cart_book_data->date_from = $date_from;
         $obj_cart_book_data->date_to = $date_to;
         $obj_cart_book_data->save();
         $obj_rm_info = new HotelRoomInformation($id_room);
         $rms_in_cart = $obj_cart_book_data->getCountRoomsInCart($id_cart, $id_guest);
         $booking_stats = $obj_booking_dtl->getBookingData($date_from, $date_to, $id_hotel, $search_id_prod, 0, 0, 1, 1, 1, 1, 0, 0, $id_cart, $id_guest, 1);
         $cart_data = array('room_num' => $obj_rm_info->room_num, 'room_type' => Product::getProductName((int) $id_product), 'date_from' => date('Y-M-d', strtotime($date_from)), 'date_to' => date('Y-M-d', strtotime($date_to)), 'amount' => $amount, 'qty' => $num_day, 'rms_in_cart' => $rms_in_cart, 'total_amount' => $total_amount, 'booking_stats' => $booking_stats, 'id_cart_book_data' => $obj_cart_book_data->id);
         if ($obj_cart_book_data->id) {
             die(Tools::jsonEncode($cart_data));
         } else {
             die(0);
         }
     } else {
         $data_dlt = $obj_cart_book_data->deleteRowById($id_cart_book_data);
         if ($data_dlt) {
             $rms_in_cart = $obj_cart_book_data->getCountRoomsInCart($id_cart, $id_guest);
             if (!$ajax_delete) {
                 $booking_stats = $obj_booking_dtl->getBookingData($date_from, $date_to, $id_hotel, $search_id_prod, 0, 0, 1, 1, 1, 1, 0, 0, $id_cart, $id_guest, 1);
                 $cart_data = array('total_amount' => $total_amount, 'rms_in_cart' => $rms_in_cart, 'booking_stats' => $booking_stats);
             }
             if ($ajax_delete) {
                 $obj_htl_info = new HotelBranchInformation();
                 $obj_rm_type = new HotelRoomType();
                 $this->context->smarty->assign(array('id_cart' => $id_cart, 'id_guest' => $id_guest));
                 // No use of adult, child, num_rooms
                 $adult = 0;
                 $children = 0;
                 $num_rooms = 1;
                 $booking_data = array();
                 $booking_data = $obj_booking_dtl->getBookingData($search_date_from, $search_date_to, $id_hotel, $search_id_prod, $adult, $children, $num_rooms, 0, 1, 1, 1, 1, $id_cart, $id_guest, 1);
                 $this->context->smarty->assign(array('date_from' => $date_from, 'date_to' => $date_to, 'booking_data' => $booking_data, 'ajax_delete' => $ajax_delete));
                 $tpl_path = 'hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/view.tpl';
                 $room_tpl = $this->context->smarty->fetch(_PS_MODULE_DIR_ . $tpl_path);
                 $cart_data = array('total_amount' => $total_amount, 'room_tpl' => $room_tpl, 'rms_in_cart' => $rms_in_cart, 'booking_data' => $booking_data);
             }
             die(Tools::jsonEncode($cart_data));
         } else {
             die(0);
         }
     }
 }
Example #9
0
 public function initFormInformations($product)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $currency = $this->context->currency;
     $data->assign('languages', $this->_languages);
     $data->assign('default_form_language', $this->default_form_language);
     $data->assign('currency', $currency);
     $this->object = $product;
     //$this->display = 'edit';
     $data->assign('product_name_redirected', Product::getProductName((int) $product->id_product_redirected, null, (int) $this->context->language->id));
     /*
      * Form for adding a virtual product like software, mp3, etc...
      */
     $product_download = new ProductDownload();
     if ($id_product_download = $product_download->getIdFromIdProduct($this->getFieldValue($product, 'id'))) {
         $product_download = new ProductDownload($id_product_download);
     }
     $product->{'productDownload'} = $product_download;
     $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute');
     $product_props = array();
     // global informations
     array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order', 'show_price', 'online_only', 'id_manufacturer');
     // specific / detailled information
     array_push($product_props, 'width', 'height', 'weight', 'active', 'is_virtual', 'cache_default_attribute', 'uploadable_files', 'text_fields');
     // prices
     array_push($product_props, 'price', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale', 'unity', 'minimum_quantity', 'additional_shipping_cost', 'available_now', 'available_later', 'available_date');
     if (Configuration::get('PS_USE_ECOTAX')) {
         array_push($product_props, 'ecotax');
     }
     foreach ($product_props as $prop) {
         $product->{$prop} = $this->getFieldValue($product, $prop);
     }
     $product->name['class'] = 'updateCurrentText';
     if (!$product->id || Configuration::get('PS_FORCE_FRIENDLY_PRODUCT')) {
         $product->name['class'] .= ' copy2friendlyUrl';
     }
     $images = Image::getImages($this->context->language->id, $product->id);
     if (is_array($images)) {
         foreach ($images as $k => $image) {
             $images[$k]['src'] = $this->context->link->getImageLink($product->link_rewrite[$this->context->language->id], $product->id . '-' . $image['id_image'], 'small_default');
         }
         $data->assign('images', $images);
     }
     $data->assign('imagesTypes', ImageType::getImagesTypes('products'));
     $product->tags = Tag::getProductTags($product->id);
     $data->assign('product_type', (int) Tools::getValue('type_product', $product->getType()));
     $data->assign('is_in_pack', (int) Pack::isPacked($product->id));
     $check_product_association_ajax = false;
     if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) {
         $check_product_association_ajax = true;
     }
     // TinyMCE
     $iso_tiny_mce = $this->context->language->iso_code;
     $iso_tiny_mce = file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en';
     $data->assign('ad', dirname($_SERVER['PHP_SELF']));
     $data->assign('iso_tiny_mce', $iso_tiny_mce);
     $data->assign('check_product_association_ajax', $check_product_association_ajax);
     $data->assign('id_lang', $this->context->language->id);
     $data->assign('product', $product);
     $data->assign('token', $this->token);
     $data->assign('currency', $currency);
     $data->assign($this->tpl_form_vars);
     $data->assign('link', $this->context->link);
     $data->assign('PS_PRODUCT_SHORT_DESC_LIMIT', Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT') ? Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT') : 400);
     $this->tpl_form_vars['product'] = $product;
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
 public function ajaxGetProducts()
 {
     if (Tools::isSubmit('id_order')) {
         $product_return_template = array();
         require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/order/ErpOrder.php';
         $objOrder = new ErpOrder((int) Tools::getValue('id_order'));
         $produits = $objOrder->getListOfProductsWithQuantity();
         if (!empty($produits)) {
             foreach ($produits as $key => &$prod) {
                 $objProd = new Product($prod['product_id']);
                 // If order is neither sent, nor cancelled, nor the current one
                 $product_return_template[$key]['reference'] = $objProd->reference;
                 $product_return_template[$key]['name'] = $objProd->getProductName($prod['product_id'], $prod['product_attribute_id']);
                 $product_return_template[$key]['quantity'] = $prod['product_quantity'];
                 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                     $manager = StockManagerFactory::getManager();
                     $product_return_template[$key]['physical_stock'] = $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id']);
                     $product_return_template[$key]['usable_stock'] = $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id'], null, true);
                     $product_return_template[$key]['real_stock'] = $manager->getProductRealQuantities($prod['product_id'], $prod['product_attribute_id']);
                 } else {
                     $product_return_template[$key]['stock'] = StockAvailable::getQuantityAvailableByProduct($prod['product_id'], $prod['product_attribute_id']);
                 }
             }
         }
         $this->context->smarty->assign(array('products' => $product_return_template));
         echo $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/advanced_order/quick_view.tpl');
         die;
     }
 }
Example #11
0
    protected function getGroupCategoryProduct($products = array())
    {
        $result = '';
        if ($products) {
            foreach ($products as $productId) {
                $productName = Product::getProductName($productId);
                $result .= '<li id="manual-product-' . $productId . '">
								<input type="hidden" class="manual_product_id" name="product_ids[]" value="' . $productId . '" />
								<span>' . $productName . '</span>
								<a class="manual-product-delete pull-right" data-id="' . $productId . '"><i class="icon-trash "></i></a>
							</li>';
            }
        }
        return $result;
    }
Example #12
0
								<th>' . $erpip->l('SKU') . '</th>
								<th>' . $erpip->l('Description') . '</th>
								<th>' . $erpip->l('Quantity') . '</th>';
            if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                $message .= '<th>' . $erpip->l('Physical Stock') . '</th>
							 <th>' . $erpip->l('Usable Stock') . '</th>
							 <th>' . $erpip->l('Real Stock') . '</th>';
            } else {
                $message .= '<th>' . $erpip->l('Stock') . '</th>';
            }
            $message .= '</tr>';
            foreach ($produits as &$prod) {
                $objProd = new Product($prod['product_id']);
                $message .= '<tr>';
                /*  If order neither sent nor cancelled nor current order */
                $message .= '<td>' . $objProd->reference . '</td><td>' . $objProd->getProductName($prod['product_id'], $prod['product_attribute_id']) . '</td><td>' . $prod['product_quantity'] . '</td>';
                if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                    $manager = StockManagerFactory::getManager();
                    $message .= '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>' . '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id'], null, true) . '</td>' . '<td>' . $manager->getProductRealQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>';
                } else {
                    $message .= '<td>' . StockAvailable::getQuantityAvailableByProduct($prod['product_id'], $prod['product_attribute_id']) . '</td>';
                }
                $message .= '</tr>';
            }
            $message .= '</table>';
            print $message;
        }
        break;
    case 'productSupplierPrice':
        /*  If we have called the script with a term to search */
        if (Tools::isSubmit('id_product') && Tools::isSubmit('id_product_attribute')) {
 /**
  * Ths method manage associated products to the order when updating it
  */
 public function manageOrderProducts()
 {
     // load supply order
     $id_supply_order = (int) Tools::getValue('id_supply_order', null);
     $products_already_in_order = array();
     if ($id_supply_order != null) {
         $supply_order = new SupplyOrder($id_supply_order);
         if (Validate::isLoadedObject($supply_order)) {
             // tests if the supplier or currency have changed in the supply order
             $new_supplier_id = (int) Tools::getValue('id_supplier');
             $new_currency_id = (int) Tools::getValue('id_currency');
             if ($new_supplier_id != $supply_order->id_supplier || $new_currency_id != $supply_order->id_currency) {
                 // resets all products in this order
                 $supply_order->resetProducts();
             } else {
                 $products_already_in_order = $supply_order->getEntries();
                 $currency = new Currency($supply_order->id_ref_currency);
                 // gets all product ids to manage
                 $product_ids_str = Tools::getValue('product_ids', null);
                 $product_ids = explode('|', $product_ids_str);
                 $product_ids_to_delete_str = Tools::getValue('product_ids_to_delete', null);
                 $product_ids_to_delete = array_unique(explode('|', $product_ids_to_delete_str));
                 //delete products that are not managed anymore
                 foreach ($products_already_in_order as $paio) {
                     $product_ok = false;
                     foreach ($product_ids_to_delete as $id) {
                         $id_check = $paio['id_product'] . '_' . $paio['id_product_attribute'];
                         if ($id_check == $id) {
                             $product_ok = true;
                         }
                     }
                     if ($product_ok === true) {
                         $entry = new SupplyOrderDetail($paio['id_supply_order_detail']);
                         $entry->delete();
                         //--ERP information
                         // delete bind in erp_supply_order_detail table
                         $id_erpip_supply_order_detail = ErpSupplyOrderDetail::getErpSupplierOrderDetailIdBySupplierOrderDetailId((int) $paio['id_supply_order_detail']);
                         if ((int) $id_erpip_supply_order_detail > 0) {
                             $erp_supply_order_detail = new ErpSupplyOrderDetail((int) $id_erpip_supply_order_detail);
                             $erp_supply_order_detail->delete();
                         }
                     }
                 }
                 // manage each product
                 foreach ($product_ids as $id) {
                     // if quantity is null, we dont save product in supply order
                     if (Tools::getValue('input_quantity_expected_' . $id, 0) == '0') {
                         continue;
                     }
                     $errors = array();
                     // check if a checksum is available for this product and test it
                     $check = Tools::getValue('input_check_' . $id, '');
                     $check_valid = md5(_COOKIE_KEY_ . $id);
                     if ($check_valid != $check) {
                         continue;
                     }
                     $pos = strpos($id, '_');
                     if ($pos === false) {
                         continue;
                     }
                     // Load / Create supply order detail
                     $entry = new SupplyOrderDetail();
                     $id_supply_order_detail = (int) Tools::getValue('input_id_' . $id, 0);
                     if ($id_supply_order_detail > 0) {
                         $existing_entry = new SupplyOrderDetail($id_supply_order_detail);
                         if (Validate::isLoadedObject($supply_order)) {
                             $entry =& $existing_entry;
                         }
                     }
                     // get product informations
                     $entry->id_product = Tools::substr($id, 0, $pos);
                     $entry->id_product_attribute = Tools::substr($id, $pos + 1);
                     $entry->unit_price_te = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('input_unit_price_te_' . $id, 0));
                     $entry->quantity_expected = (int) str_replace(array(' ', ','), array('', '.'), Tools::getValue('input_quantity_expected_' . $id, 0));
                     $entry->discount_rate = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('input_discount_rate_' . $id, 0));
                     $entry->tax_rate = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('input_tax_rate_' . $id, 0));
                     $entry->reference = Tools::getValue('input_reference_' . $id, '');
                     $entry->supplier_reference = Tools::getValue('input_supplier_reference_' . $id, '');
                     $entry->ean13 = Tools::getValue('input_ean13_' . $id, '');
                     $entry->upc = Tools::getValue('input_upc_' . $id, '');
                     // fixed bug of discount_value_te field while % is null
                     if ($entry->discount_rate == '0.000000') {
                         $entry->discount_value_te = '0.000000';
                     }
                     //get the product name in the order language
                     $entry->name = Product::getProductName($entry->id_product, $entry->id_product_attribute, $supply_order->id_lang);
                     if (empty($entry->name)) {
                         $entry->name = '';
                     }
                     if ($entry->supplier_reference == null) {
                         $entry->supplier_reference = '';
                     }
                     $entry->exchange_rate = $currency->conversion_rate;
                     $entry->id_currency = $currency->id;
                     $entry->id_supply_order = $supply_order->id;
                     $errors = $entry->validateController();
                     //get the product name displayed in the backoffice according to the employee language
                     $entry->name_displayed = Tools::getValue('input_name_displayed_' . $id, '');
                     // if there is a problem, handle error for the current product
                     if (count($errors) > 0) {
                         // add the product to error array => display again product line
                         $this->order_products_errors[] = array('id_product' => $entry->id_product, 'id_product_attribute' => $entry->id_product_attribute, 'unit_price_te' => $entry->unit_price_te, 'quantity_expected' => $entry->quantity_expected, 'discount_rate' => $entry->discount_rate, 'tax_rate' => $entry->tax_rate, 'name' => $entry->name, 'name_displayed' => $entry->name_displayed, 'reference' => $entry->reference, 'supplier_reference' => $entry->supplier_reference, 'ean13' => $entry->ean13, 'upc' => $entry->upc);
                         $error_str = '<ul>';
                         foreach ($errors as $e) {
                             $error_str .= '<li>' . $this->l('Field') . $e . '</li>';
                         }
                         $error_str .= '</ul>';
                         $this->errors[] = Tools::displayError($this->l('Please check the product information:') . $entry->name . ' ' . $error_str);
                     } else {
                         $entry->save();
                     }
                     //-ERP information
                     // updates/creates erp_supplier_order_detail if it does not exist
                     if (Tools::isSubmit('id_erpip_supply_order_detail_' . $id) && (int) Tools::getValue('id_erpip_supply_order_detail_' . $id) > 0) {
                         $erp_supply_order_detail = new ErpSupplyOrderDetail((int) Tools::getValue('id_erpip_supply_order_detail_' . $id));
                     } else {
                         $erp_supply_order_detail = new ErpSupplyOrderDetail();
                     }
                     // creates erp_supplier_order_detail
                     $erp_supply_order_detail->comment = Tools::getValue('input_comment_' . $id, '');
                     $validation_esod = $erp_supply_order_detail->validateController();
                     // checks erp_supplier_order_detail validity
                     if (count($validation_esod) > 0) {
                         foreach ($validation_esod as $item) {
                             $this->errors[] = $item;
                         }
                         $this->errors[] = Tools::displayError('The ErpIllicopresta Supplier Order Detail is not correct. Please make sure all of the required fields are completed.');
                     } else {
                         if (Tools::isSubmit('id_erpip_supply_order_detail_' . $id) && Tools::getValue('id_erpip_supply_order_detail_' . $id) > 0) {
                             $erp_supply_order_detail->update();
                         } else {
                             $erp_supply_order_detail->save();
                             $_POST['id_erpip_supply_order_detail'][$erp_supply_order_detail->id] = $entry->id;
                         }
                     }
                 }
             }
         }
     }
 }
Example #14
0
 /**
  * Webservice : getter for the product name
  */
 public function getWSProductName()
 {
     $res = array();
     foreach (Language::getIDs(true) as $id_lang) {
         $res[$id_lang] = Product::getProductName($this->id_product, $this->id_product_attribute, $id_lang);
     }
     return $res;
 }
 /**
  * Webservice : getter for the product name
  */
 public function getWSProductName()
 {
     $languages = Language::getLanguages(true);
     $res = array();
     foreach ($languages as $language) {
         $res[$language['id_lang']] = Product::getProductName($this->id_product, $this->id_product_attribute, $language['id_lang']);
     }
     return $res;
 }
    /**
     * Loads products which quantity (hysical quantity) is equal or less than $threshold
     * @param int $threshold
     */
    protected function loadProducts($threshold)
    {
        // if there is already an order
        if (Tools::getValue('id_supply_order')) {
            $supply_order = new SupplyOrder((int) Tools::getValue('id_supply_order'));
        } else {
            // else, we just created a new order
            $supply_order = $this->object;
        }
        // if order is not valid, return;
        if (!Validate::isLoadedObject($supply_order)) {
            return;
        }
        // resets products if needed
        if (Tools::getValue('id_supply_order')) {
            $supply_order->resetProducts();
        }
        // gets products
        $query = new DbQuery();
        $query->select('
			ps.id_product,
			ps.id_product_attribute,
			ps.product_supplier_reference as supplier_reference,
			ps.product_supplier_price_te as unit_price_te,
			ps.id_currency,
			IFNULL(pa.reference, IFNULL(p.reference, \'\')) as reference,
			IFNULL(pa.ean13, IFNULL(p.ean13, \'\')) as ean13,
			IFNULL(pa.upc, IFNULL(p.upc, \'\')) as upc');
        $query->from('product_supplier', 'ps');
        $query->leftJoin('stock', 's', '
			s.id_product = ps.id_product
			AND s.id_product_attribute = ps.id_product_attribute
			AND s.id_warehouse = ' . (int) $supply_order->id_warehouse);
        $query->innerJoin('warehouse_product_location', 'wpl', '
			wpl.id_product = ps.id_product
			AND wpl.id_product_attribute = ps.id_product_attribute
			AND wpl.id_warehouse = ' . (int) $supply_order->id_warehouse . '
		');
        $query->leftJoin('product', 'p', 'p.id_product = ps.id_product');
        $query->leftJoin('product_attribute', 'pa', '
			pa.id_product_attribute = ps.id_product_attribute
			AND p.id_product = ps.id_product
		');
        $query->where('ps.id_supplier = ' . (int) $supply_order->id_supplier);
        // gets items
        $items = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        // loads order currency
        $order_currency = new Currency($supply_order->id_currency);
        if (!Validate::isLoadedObject($order_currency)) {
            return;
        }
        $manager = StockManagerFactory::getManager();
        foreach ($items as $item) {
            $diff = (int) $threshold;
            if ($supply_order->is_template != 1) {
                $real_quantity = (int) $manager->getProductRealQuantities($item['id_product'], $item['id_product_attribute'], $supply_order->id_warehouse, true);
                $diff = (int) $threshold - (int) $real_quantity;
            }
            if ($diff >= 0) {
                // sets supply_order_detail
                $supply_order_detail = new SupplyOrderDetail();
                $supply_order_detail->id_supply_order = $supply_order->id;
                $supply_order_detail->id_currency = $order_currency->id;
                $supply_order_detail->id_product = $item['id_product'];
                $supply_order_detail->id_product_attribute = $item['id_product_attribute'];
                $supply_order_detail->reference = $item['reference'];
                $supply_order_detail->supplier_reference = $item['supplier_reference'];
                $supply_order_detail->name = Product::getProductName($item['id_product'], $item['id_product_attribute'], $supply_order->id_lang);
                $supply_order_detail->ean13 = $item['ean13'];
                $supply_order_detail->upc = $item['upc'];
                $supply_order_detail->quantity_expected = (int) $diff == 0 ? 1 : (int) $diff;
                $supply_order_detail->exchange_rate = $order_currency->conversion_rate;
                $product_currency = new Currency($item['id_currency']);
                if (Validate::isLoadedObject($product_currency)) {
                    $supply_order_detail->unit_price_te = Tools::convertPriceFull($item['unit_price_te'], $product_currency, $order_currency);
                } else {
                    $supply_order_detail->unit_price_te = 0;
                }
                $supply_order_detail->save();
                unset($product_currency);
            }
        }
        // updates supply order
        $supply_order->update();
    }
Example #17
0
 public function hookActionProductCoverage($params)
 {
     // if not advanced stock management, nothing to do
     if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
         return;
     }
     // retrieves informations
     $id_product = (int) $params['id_product'];
     $id_product_attribute = (int) $params['id_product_attribute'];
     $warehouse = $params['warehouse'];
     $product = new Product($id_product);
     if (!Validate::isLoadedObject($product)) {
         return;
     }
     if (!$product->advanced_stock_management) {
         return;
     }
     // sets warehouse id to get the coverage
     if (!Validate::isLoadedObject($warehouse)) {
         $id_warehouse = 0;
     } else {
         $id_warehouse = (int) $warehouse->id;
     }
     // coverage of the product
     $warning_coverage = (int) Configuration::getGlobalValue('MA_PRODUCT_COVERAGE');
     $coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse);
     // if we need to send a notification
     if ($product->active == 1 && $coverage < $warning_coverage && !empty($this->merchant_mails) && Configuration::getGlobalValue('MA_MERCHANT_COVERAGE')) {
         $context = Context::getContext();
         $id_lang = (int) $context->language->id;
         $id_shop = (int) $context->shop->id;
         $iso = Language::getIsoById($id_lang);
         $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
         $template_vars = array('{current_coverage}' => $coverage, '{warning_coverage}' => $warning_coverage, '{product}' => pSQL($product_name));
         if (file_exists(dirname(__FILE__) . '/mails/' . $iso . '/productcoverage.txt') && file_exists(dirname(__FILE__) . '/mails/' . $iso . '/productcoverage.html')) {
             // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
             $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
             foreach ($merchant_mails as $merchant_mail) {
                 Mail::Send($id_lang, 'productcoverage', Mail::l('Stock coverage', $id_lang), $template_vars, $merchant_mail, null, (string) Configuration::get('PS_SHOP_EMAIL'), (string) Configuration::get('PS_SHOP_NAME'), null, null, dirname(__FILE__) . '/mails/', null, $id_shop);
             }
         }
     }
 }
Example #18
0
    protected function supplyOrdersDetailsImportOne($info, &$products, &$reset, $force_ids, $current_line, $validateOnly = false)
    {
        // sets default values if needed
        AdminImportController::setDefaultValues($info);
        // gets the supply order
        if (array_key_exists('supply_order_reference', $info) && pSQL($info['supply_order_reference']) && SupplyOrder::exists(pSQL($info['supply_order_reference']))) {
            $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['supply_order_reference']));
        } else {
            $this->errors[] = sprintf($this->l('Supply Order (%s) could not be loaded (at line %d).'), $info['supply_order_reference'], $current_line + 1);
        }
        if (empty($this->errors)) {
            // sets parameters
            $id_product = (int) $info['id_product'];
            if (!$info['id_product_attribute']) {
                $info['id_product_attribute'] = 0;
            }
            $id_product_attribute = (int) $info['id_product_attribute'];
            $unit_price_te = (double) $info['unit_price_te'];
            $quantity_expected = (int) $info['quantity_expected'];
            $discount_rate = (double) $info['discount_rate'];
            $tax_rate = (double) $info['tax_rate'];
            // checks if one product/attribute is there only once
            if (isset($products[$id_product][$id_product_attribute])) {
                $this->errors[] = sprintf($this->l('Product/Attribute (%d/%d) cannot be added twice (at line %d).'), $id_product, $id_product_attribute, $current_line + 1);
            } else {
                $products[$id_product][$id_product_attribute] = $quantity_expected;
            }
            // checks parameters
            if (false === ($supplier_reference = ProductSupplier::getProductSupplierReference($id_product, $id_product_attribute, $supply_order->id_supplier))) {
                $this->errors[] = sprintf($this->l('Product (%d/%d) is not available for this order (at line %d).'), $id_product, $id_product_attribute, $current_line + 1);
            }
            if ($unit_price_te < 0) {
                $this->errors[] = sprintf($this->l('Unit Price (tax excl.) (%d) is not valid (at line %d).'), $unit_price_te, $current_line + 1);
            }
            if ($quantity_expected < 0) {
                $this->errors[] = sprintf($this->l('Quantity Expected (%d) is not valid (at line %d).'), $quantity_expected, $current_line + 1);
            }
            if ($discount_rate < 0 || $discount_rate > 100) {
                $this->errors[] = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
            }
            if ($tax_rate < 0 || $tax_rate > 100) {
                $this->errors[] = sprintf($this->l('Quantity Expected (%d) is not valid (at line %d).'), $tax_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
            }
            // if no errors, sets supply order details
            if (empty($this->errors)) {
                // resets order if needed
                if (!$validateOnly && $reset) {
                    $supply_order->resetProducts();
                    $reset = false;
                }
                // creates new product
                $supply_order_detail = new SupplyOrderDetail();
                AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order_detail);
                // sets parameters
                $supply_order_detail->id_supply_order = $supply_order->id;
                $currency = new Currency($supply_order->id_ref_currency);
                $supply_order_detail->id_currency = $currency->id;
                $supply_order_detail->exchange_rate = $currency->conversion_rate;
                $supply_order_detail->supplier_reference = $supplier_reference;
                $supply_order_detail->name = Product::getProductName($id_product, $id_product_attribute, $supply_order->id_lang);
                // gets ean13 / ref / upc
                $query = new DbQuery();
                $query->select('
					IFNULL(pa.reference, IFNULL(p.reference, \'\')) as reference,
					IFNULL(pa.ean13, IFNULL(p.ean13, \'\')) as ean13,
					IFNULL(pa.upc, IFNULL(p.upc, \'\')) as upc
				');
                $query->from('product', 'p');
                $query->leftJoin('product_attribute', 'pa', 'pa.id_product = p.id_product AND id_product_attribute = ' . (int) $id_product_attribute);
                $query->where('p.id_product = ' . (int) $id_product);
                $query->where('p.is_virtual = 0 AND p.cache_is_pack = 0');
                $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
                $product_infos = $res['0'];
                $supply_order_detail->reference = $product_infos['reference'];
                $supply_order_detail->ean13 = $product_infos['ean13'];
                $supply_order_detail->upc = $product_infos['upc'];
                $supply_order_detail->force_id = (bool) $force_ids;
                if (!$validateOnly) {
                    $supply_order_detail->add();
                    $supply_order->update();
                }
                unset($supply_order_detail);
            }
        }
    }
    public function supplyOrdersDetailsImport()
    {
        // opens CSV & sets locale
        $this->receiveTab();
        $handle = $this->openCsvFile();
        AdminImportController::setLocale();
        $products = array();
        $reset = true;
        // main loop, for each supply orders details to import
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); ++$current_line) {
            // if convert requested
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            // sets default values if needed
            AdminImportController::setDefaultValues($info);
            // gets the supply order
            if (array_key_exists('supply_order_reference', $info) && pSQL($info['supply_order_reference']) && SupplyOrder::exists(pSQL($info['supply_order_reference']))) {
                $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['supply_order_reference']));
            } else {
                $this->errors[] = sprintf($this->l('Supply Order (%s) could not be loaded (at line %d).'), (int) $info['supply_order_reference'], $current_line + 1);
            }
            if (empty($this->errors)) {
                // sets parameters
                $id_product = (int) $info['id_product'];
                if (!$info['id_product_attribute']) {
                    $info['id_product_attribute'] = 0;
                }
                $id_product_attribute = (int) $info['id_product_attribute'];
                $unit_price_te = (double) $info['unit_price_te'];
                $quantity_expected = (int) $info['quantity_expected'];
                $discount_rate = (double) $info['discount_rate'];
                $tax_rate = (double) $info['tax_rate'];
                // checks if one product is there only once
                if (isset($product['id_product'])) {
                    if ($product['id_product'] == $id_product_attribute) {
                        $this->errors[] = sprintf($this->l('Product (%d/%D) cannot be added twice (at line %d).'), $id_product, $id_product_attribute, $current_line + 1);
                    } else {
                        $product['id_product'] = $id_product_attribute;
                    }
                } else {
                    $product['id_product'] = 0;
                }
                // checks parameters
                if (false === ($supplier_reference = ProductSupplier::getProductSupplierReference($id_product, $id_product_attribute, $supply_order->id_supplier))) {
                    $this->errors[] = sprintf($this->l('Product (%d/%d) is not available for this order (at line %d).'), $id_product, $id_product_attribute, $current_line + 1);
                }
                if ($unit_price_te < 0) {
                    $this->errors[] = sprintf($this->l('Unit Price (tax excl.) (%d) is not valid (at line %d).'), $unit_price_te, $current_line + 1);
                }
                if ($quantity_expected < 0) {
                    $this->errors[] = sprintf($this->l('Quantity Expected (%d) is not valid (at line %d).'), $quantity_expected, $current_line + 1);
                }
                if ($discount_rate < 0 || $discount_rate > 100) {
                    $this->errors[] = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
                }
                if ($tax_rate < 0 || $tax_rate > 100) {
                    $this->errors[] = sprintf($this->l('Quantity Expected (%d) is not valid (at line %d).'), $tax_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
                }
                // if no errors, sets supply order details
                if (empty($this->errors)) {
                    // resets order if needed
                    if ($reset) {
                        $supply_order->resetProducts();
                        $reset = false;
                    }
                    // creates new product
                    $supply_order_detail = new SupplyOrderDetail();
                    AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order_detail);
                    // sets parameters
                    $supply_order_detail->id_supply_order = $supply_order->id;
                    $currency = new Currency($supply_order->id_ref_currency);
                    $supply_order_detail->id_currency = $currency->id;
                    $supply_order_detail->exchange_rate = $currency->conversion_rate;
                    $supply_order_detail->supplier_reference = $supplier_reference;
                    $supply_order_detail->name = Product::getProductName($id_product, $id_product_attribute, $supply_order->id_lang);
                    // gets ean13 / ref / upc
                    $query = new DbQuery();
                    $query->select('
						IFNULL(pa.reference, IFNULL(p.reference, \'\')) as reference,
						IFNULL(pa.ean13, IFNULL(p.ean13, \'\')) as ean13,
						IFNULL(pa.upc, IFNULL(p.upc, \'\')) as upc
					');
                    $query->from('product', 'p');
                    $query->leftJoin('product_attribute', 'pa', 'pa.id_product = p.id_product AND id_product_attribute = ' . (int) $id_product_attribute);
                    $query->where('p.id_product = ' . (int) $id_product);
                    $query->where('p.is_virtual = 0 AND p.cache_is_pack = 0');
                    $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
                    $product_infos = $res['0'];
                    $supply_order_detail->reference = $product_infos['reference'];
                    $supply_order_detail->ean13 = $product_infos['ean13'];
                    $supply_order_detail->upc = $product_infos['upc'];
                    $supply_order_detail->add();
                    $supply_order->update();
                    unset($supply_order_detail);
                }
            }
        }
        // closes
        $this->closeCsvFile($handle);
    }
 /**
  * AdminController::getList() override
  * @see AdminController::getList()
  *
  * @param int         $id_lang
  * @param string|null $order_by
  * @param string|null $order_way
  * @param int         $start
  * @param int|null    $limit
  * @param int|bool    $id_lang_shop
  *
  * @throws PrestaShopException
  */
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
 {
     parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
     if ($this->display == 'details') {
         $nb_items = count($this->_list);
         for ($i = 0; $i < $nb_items; ++$i) {
             $item =& $this->_list[$i];
             $item['name'] = Product::getProductName($item['id_product'], $item['id']);
             // computes coverage
             $coverage = StockManagerFactory::getManager()->getProductCoverage($item['id_product'], $item['id'], Tools::getValue('period') ? (int) Tools::getValue('period') : 7, $this->getCurrentCoverageWarehouse() == -1 ? null : Tools::getValue('id_warehouse', -1));
             if ($coverage != -1) {
                 // if coverage is available
                 if ($coverage < $this->getCurrentWarning()) {
                     // if highlight needed
                     $item['color'] = '#BDE5F8';
                 }
                 $item['coverage'] = $coverage;
             } else {
                 // infinity
                 $item['coverage'] = '--';
             }
             // computes quantity sold
             $qty_sold = $this->getQuantitySold($item['id_product'], $item['id'], $this->getCurrentCoveragePeriod());
             if (!$qty_sold) {
                 $item['qty_sold'] = '--';
             } else {
                 $item['qty_sold'] = $qty_sold;
             }
         }
     } else {
         $nb_items = count($this->_list);
         for ($i = 0; $i < $nb_items; ++$i) {
             $item =& $this->_list[$i];
             if (array_key_exists('variations', $item) && (int) $item['variations'] <= 0) {
                 // computes coverage and displays (highlights if needed)
                 $coverage = StockManagerFactory::getManager()->getProductCoverage($item['id'], 0, $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse() == -1 ? null : $this->getCurrentCoverageWarehouse());
                 if ($coverage != -1) {
                     // coverage is available
                     if ($coverage < $this->getCurrentWarning()) {
                         $item['color'] = '#BDE5F8';
                     }
                     $item['coverage'] = $coverage;
                 } else {
                     // infinity
                     $item['coverage'] = '--';
                 }
                 // computes quantity sold
                 $qty_sold = $this->getQuantitySold($item['id'], 0, $this->getCurrentCoveragePeriod());
                 if (!$qty_sold) {
                     $item['qty_sold'] = '--';
                 } else {
                     $item['qty_sold'] = $qty_sold;
                 }
                 // removes 'details' action on products without attributes
                 $this->addRowActionSkipList('details', array($item['id']));
             } else {
                 $item['stock'] = $this->l('See details');
                 $item['reference'] = '--';
                 $item['ean13'] = '--';
                 $item['upc'] = '--';
             }
         }
     }
 }
Example #21
0
 public function quoteProject($args, $project_name = null, $id_product = false)
 {
     $textMasterProject = new TextMasterProject();
     $textMasterProject->ctype = $textMasterProject->type = $args['ctype'];
     if (!is_array($id_product) && $id_product) {
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             $current_product = new Product((int) $id_product);
             $project_name = $current_product->name[(int) $this->context->language->id];
         } else {
             $project_name = Product::getProductName($id_product, null, $this->context->language->id);
         }
     }
     $textMasterProject->name = pSQL($project_name);
     if (isset($args['same_author_must_do_entire_project'])) {
         $textMasterProject->same_author_must_do_entire_project = $args['same_author_must_do_entire_project'];
     }
     $textMasterProject->language_level = $args['language_level'];
     $textMasterProject->quality = $args['quality'];
     $textMasterProject->expertise = $args['expertise'];
     $textMasterProject->language_from = $args['language_from'];
     $textMasterProject->category = $args['category'];
     $textMasterProject->project_briefing = pSQL($args['project_briefing']);
     $textMasterProject->vocabulary_type = $args['vocabulary_type'];
     $textMasterProject->target_reader_groups = $args['target_reader_groups'];
     $textMasterProject->grammatical_person = $args['grammatical_person'];
     $textMasterProject->textmasters = $args['textmasters'];
     if ($textMasterProject->type == 'translation') {
         $textMasterProject->language_to = $args['language_to'];
     }
     $words = 0;
     if ($args['project_data']) {
         $word_counts = $this->countProductWords($id_product);
         foreach ($args['project_data'] as $element) {
             if (isset($word_counts[$element]) && isset($word_counts[$element][$args['language_from']])) {
                 $words += $word_counts[$element][$args['language_from']];
             }
         }
     }
     $textMasterProject->total_word_count = $words;
     return $textMasterProject->quote();
 }
 /**
  * AdminController::getList() override
  * @see AdminController::getList()
  *
  * @param int         $id_lang
  * @param string|null $order_by
  * @param string|null $order_way
  * @param int         $start
  * @param int|null    $limit
  * @param int|bool    $id_lang_shop
  *
  * @throws PrestaShopException
  */
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
 {
     parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
     // Check each row to see if there are combinations and get the correct action in consequence
     $nb_items = count($this->_list);
     for ($i = 0; $i < $nb_items; $i++) {
         $item =& $this->_list[$i];
         // if it's an ajax request we have to consider manipulating a product variation
         if (Tools::isSubmit('id_product')) {
             $item['name'] = Product::getProductName($item['id_product'], $item['id']);
             // no details for this row
             $this->addRowActionSkipList('details', array($item['id']));
             // specify actions in function of stock
             $this->skipActionByStock($item, true);
         } elseif (array_key_exists('variations', $item) && (int) $item['variations'] > 0) {
             // we have to desactivate stock actions on current row
             $this->addRowActionSkipList('addstock', array($item['id']));
             $this->addRowActionSkipList('removestock', array($item['id']));
             $this->addRowActionSkipList('transferstock', array($item['id']));
             // does not display these informaions because this product has combinations
             $item['reference'] = '--';
             $item['ean13'] = '--';
             $item['upc'] = '--';
         } else {
             //there are no variations of current product, so we don't want to show details action
             $this->addRowActionSkipList('details', array($item['id']));
             // specify actions in function of stock
             $this->skipActionByStock($item, false);
         }
         // Checks access
         if (!($this->tabAccess['add'] === '1')) {
             $this->addRowActionSkipList('addstock', array($item['id']));
         }
         if (!($this->tabAccess['delete'] === '1')) {
             $this->addRowActionSkipList('removestock', array($item['id']));
         }
         if (!($this->tabAccess['edit'] === '1')) {
             $this->addRowActionSkipList('transferstock', array($item['id']));
         }
     }
 }
Example #23
0
 protected function _getPaymentMethods()
 {
     if (!$this->isLogged) {
         return '<p class="warning">' . Tools::displayError('Please sign in to see payment methods.') . '</p>';
     }
     if ($this->context->cart->OrderExists()) {
         return '<p class="warning">' . Tools::displayError('Error: This order has already been validated.') . '</p>';
     }
     if (!$this->context->cart->id_customer || !Customer::customerIdExistsStatic($this->context->cart->id_customer) || Customer::isBanned($this->context->cart->id_customer)) {
         return '<p class="warning">' . Tools::displayError('Error: No customer.') . '</p>';
     }
     $address_delivery = new Address($this->context->cart->id_address_delivery);
     $address_invoice = $this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice);
     // if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted)
     // 	return '<p class="warning">'.Tools::displayError('Error: Please select an address.').'</p>';
     if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) {
         if ($this->context->cart->isMultiAddressDelivery()) {
             return '<p class="warning">' . Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you have selected.') . '</p>';
         } else {
             return '<p class="warning">' . Tools::displayError('Error: None of your chosen carriers deliver to the address you have selected.') . '</p>';
         }
     }
     if (!$this->context->cart->getDeliveryOption(null, false) && !$this->context->cart->isVirtualCart()) {
         return '<p class="warning">' . Tools::displayError('Error: Please choose a carrier.') . '</p>';
     }
     if (!$this->context->cart->id_currency) {
         return '<p class="warning">' . Tools::displayError('Error: No currency has been selected.') . '</p>';
     }
     if (!$this->context->cookie->checkedTOS && Configuration::get('PS_CONDITIONS')) {
         return '<p class="warning">' . Tools::displayError('Please accept the Terms of Service.') . '</p>';
     }
     /* If some products have disappear */
     if (is_array($product = $this->context->cart->checkQuantities(true))) {
         return '<p class="warning">' . sprintf(Tools::displayError('An item (%s) in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.'), $product['name']) . '</p>';
     }
     if ((int) ($id_product = $this->context->cart->checkProductsAccess())) {
         return '<p class="warning">' . sprintf(Tools::displayError('An item in your cart is no longer available (%s). You cannot proceed with your order.'), Product::getProductName((int) $id_product)) . '</p>';
     }
     /* Check minimal amount */
     $currency = Currency::getCurrency((int) $this->context->cart->id_currency);
     $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
     if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase) {
         return '<p class="warning">' . sprintf(Tools::displayError('A minimum purchase total of %1s (tax excl.) is required to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency)) . '</p>';
     }
     /* Bypass payment step if total is 0 */
     if ($this->context->cart->getOrderTotal() <= 0) {
         return '<p class="center"><button class="button btn btn-default button-medium" name="confirmOrder" id="confirmOrder" onclick="confirmFreeOrder();" type="submit"> <span>' . Tools::displayError('I confirm my order.') . '</span></button></p>';
     }
     $return = Hook::exec('displayPayment');
     if (!$return) {
         return '<p class="warning">' . Tools::displayError('No payment method is available for use at this time. ') . '</p>';
     }
     return $return;
 }