/** * Tries to login. * @param session id if logged in successfull, false otherwise. */ public function login() { // get warehouse $warehouse = new Warehouse($this->warehouseId); $vSession = false; if ($warehouse->checkPassword($this->pw)) { $vSession = new Session($warehouse->id, true, false); } elseif ($warehouse->checkPasswordRestricted($this->pw)) { $vSession = new Session($warehouse->id, true); } return $vSession; }
public function getWarehouseList() { /* Load Model of warehouses and setup the list */ App::import('Model', 'Warehouse'); $warehouse = new Warehouse(); /* Set conditions */ $options = array('fields' => array('City.city_name', 'Warehouse.warehouse_name', 'Warehouse.id'), 'joins' => array(array('alias' => 'City', 'table' => 'cities', 'type' => 'LEFT', 'conditions' => array('City.id = WarehouseDesc.city_id'))), 'conditions' => array('WarehouseDesc.is_deleted' => 0)); $getWarehouseAllWithStatus = $warehouse->find('all', $options); $newWarehouseList = array(); if ($warehouse->find('count') > 0) { foreach ($getWarehouseAllWithStatus as $index => $value) { $newWarehouseList[$value["Warehouse"]["id"]] = $value["Warehouse"]["warehouse_name"] . " (" . $value["City"]["city_name"] . ")"; } } return $getWarehouseList = $newWarehouseList; }
public function renderForm() { $warehouses = Warehouse::getWarehouses(); $this->fields_form = array('legend' => array('title' => $this->l('States'), 'icon' => 'icon-globe'), 'input' => array(array('type' => 'text', 'label' => 'Название', 'name' => 'name', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Порядок сортировки', 'name' => 'sort', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Стоимость доставки в разделе декор', 'name' => 'price_decor', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Стоимость доставки обычная', 'name' => 'price_main', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Адрес склада', 'name' => 'address_warehouse', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Режим работы', 'name' => 'mode', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'switch', 'label' => 'Главный', 'name' => 'is_main', 'required' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />'))), array('type' => 'switch', 'label' => 'Московская обл', 'name' => 'is_msk', 'required' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />')))), 'submit' => array('title' => $this->l('Save'))); // foreach ($warehouses as $warehous){ // $this->fields_form['input'][] = array( // 'type' => 'text', // 'label' => 'Время доставки со скдада '.$warehous['name'], // 'name' => 'distance_'.$warehous['id_warehouse'], // 'hint' => 'Время доставки в днях', // ); // $this->fields_form['input'][] = array( // 'type' => 'text', // 'label' => 'Стоимость доставки со склада '.$warehous['name'], // 'name' => 'price_'.$warehous['id_warehouse'], // 'hint' => 'Стоимость доставки в рублях', // ); // if(!empty($this->object->id_city)){ // $fields_value = Db::getInstance()->getRow("SELECT distance,price FROM "._DB_PREFIX_."city_warehous // WHERE id_warehouse={$warehous['id_warehouse']} AND id_city={$this->object->id_city}"); // // $this->fields_value['distance_'.$warehous['id_warehouse']] = isset($fields_value['distance']) ? $fields_value['distance'] : ''; // $this->fields_value['price_'.$warehous['id_warehouse']] = isset($fields_value['price']) ? $fields_value['price'] : ''; // } // } return parent::renderForm(); }
function testClosestWarehouse() { $warehouse = Warehouse::closest_to($this->objFromFixture("Address", "customeraddress1")); $this->assertEquals("Main warehouse", $warehouse->Title); $warehouse = Warehouse::closest_to($this->objFromFixture("Address", "customeraddress2")); $this->assertEquals("NSW depot", $warehouse->Title); }
public function getWarehouseList() { /* Load Model of warehouses and setup the list */ App::import('Model', 'Warehouse'); $warehouse = new Warehouse(); $getWarehouseAllWithStatus = $warehouse->find('all'); $newWarehouseList = array(); if ($warehouse->find('count') > 0) { foreach ($getWarehouseAllWithStatus as $index => $value) { if ($value["WarehouseDesc"]["is_deleted"] == "1") { $newWarehouseList[$value["Warehouse"]["id"]] = $value["Warehouse"]["warehouse_name"] . " (Under Deleted)"; } else { $newWarehouseList[$value["Warehouse"]["id"]] = $value["Warehouse"]["warehouse_name"]; } } } return $getWarehouseList = $newWarehouseList; }
public function run() { //$faker = Faker::create(); //foreach(range(1, 10) as $index) //{ Warehouse::create(['item' => '158-52A', 'quantity' => 800, 'position' => 205]); Warehouse::create(['item' => '158-52B', 'quantity' => 900, 'position' => 213]); Warehouse::create(['item' => '211-19A', 'quantity' => 900, 'position' => 125]); Warehouse::create(['item' => '211-19B', 'quantity' => 900, 'position' => 126]); //} }
public function __construct() { $this->bootstrap = true; $this->className = 'Configuration'; $this->table = 'configuration'; parent::__construct(); $warehouse_list = Warehouse::getWarehouses(); $warehouse_no = array(array('id_warehouse' => 0, 'name' => $this->l('No default warehouse (default setting)'))); $warehouse_list = array_merge($warehouse_no, $warehouse_list); $this->fields_options = array('products' => array('title' => $this->l('Products (general)'), 'fields' => array('PS_CATALOG_MODE' => array('title' => $this->l('Catalog mode'), 'hint' => $this->l('When active, all shopping features will be disabled.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_COMPARATOR_MAX_ITEM' => array('title' => $this->l('Product comparison'), 'hint' => $this->l('Set the maximum number of products that can be selected for comparison. Set to "0" to disable this feature.'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), 'PS_NB_DAYS_NEW_PRODUCT' => array('title' => $this->l('Number of days for which the product is considered \'new\''), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), 'PS_CART_REDIRECT' => array('title' => $this->l('Redirect after adding product to cart'), 'hint' => $this->l('Only for non-AJAX versions of the cart.'), 'cast' => 'intval', 'show' => true, 'required' => false, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Previous page'), 1 => $this->l('Cart summary'))), 'PS_PRODUCT_SHORT_DESC_LIMIT' => array('title' => $this->l('Max size of short description'), 'hint' => $this->l('Set the maximum size of product short description (in characters).'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'suffix' => $this->l('characters')), 'PS_QTY_DISCOUNT_ON_COMBINATION' => array('title' => $this->l('Quantity discounts based on'), 'hint' => $this->l('How to calculate quantity discounts.'), 'cast' => 'intval', 'show' => true, 'required' => false, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Products'), 1 => $this->l('Combinations'))), 'PS_FORCE_FRIENDLY_PRODUCT' => array('title' => $this->l('Force update of friendly URL'), 'hint' => $this->l('When active, friendly URL will be updated on every save.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'))), 'order_by_pagination' => array('title' => $this->l('Pagination'), 'fields' => array('PS_PRODUCTS_PER_PAGE' => array('title' => $this->l('Products per page'), 'hint' => $this->l('Number of products displayed per page. Default is 10.'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), 'PS_PRODUCTS_ORDER_BY' => array('title' => $this->l('Default order by'), 'hint' => $this->l('The order in which products are displayed in the product list.'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Product name')), array('id' => '1', 'name' => $this->l('Product price')), array('id' => '2', 'name' => $this->l('Product add date')), array('id' => '3', 'name' => $this->l('Product modified date')), array('id' => '4', 'name' => $this->l('Position inside category')), array('id' => '5', 'name' => $this->l('Manufacturer')), array('id' => '6', 'name' => $this->l('Product quantity')), array('id' => '7', 'name' => $this->l('Product reference'))), 'identifier' => 'id'), 'PS_PRODUCTS_ORDER_WAY' => array('title' => $this->l('Default order method'), 'hint' => $this->l('Default order method for product list.'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Ascending')), array('id' => '1', 'name' => $this->l('Descending'))), 'identifier' => 'id')), 'submit' => array('title' => $this->l('Save'))), 'fo_product_page' => array('title' => $this->l('Product page'), 'fields' => array('PS_DISPLAY_QTIES' => array('title' => $this->l('Display available quantities on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_LAST_QTIES' => array('title' => $this->l('Display remaining quantities when the quantity is lower than'), 'hint' => $this->l('Set to "0" to disable this feature.'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), 'PS_DISPLAY_JQZOOM' => array('title' => $this->l('Enable JqZoom instead of Fancybox on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_DISP_UNAVAILABLE_ATTR' => array('title' => $this->l('Display unavailable product attributes on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_ATTRIBUTE_CATEGORY_DISPLAY' => array('title' => $this->l('Display the "add to cart" button when a product has attributes'), 'hint' => $this->l('Display or hide the "add to cart" button on category pages for products that have attributes forcing customers to see product details.'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_ATTRIBUTE_ANCHOR_SEPARATOR' => array('title' => $this->l('Separator of attribute anchor on the product links'), 'type' => 'select', 'list' => array(array('id' => '-', 'name' => '-'), array('id' => ',', 'name' => ',')), 'identifier' => 'id'), 'PS_DISPLAY_DISCOUNT_PRICE' => array('title' => $this->l('Display discounted price'), 'desc' => $this->l('In the volume discounts board, display the new price with the applied discount instead of showing the discount (ie. "-5%").'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'))), 'stock' => array('title' => $this->l('Products stock'), 'fields' => array('PS_ORDER_OUT_OF_STOCK' => array('title' => $this->l('Allow ordering of out-of-stock products'), 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_STOCK_MANAGEMENT' => array('title' => $this->l('Enable stock management'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'js' => array('on' => 'onchange="stockManagementActivationAuthorization()"', 'off' => 'onchange="stockManagementActivationAuthorization()"')), 'PS_ADVANCED_STOCK_MANAGEMENT' => array('title' => $this->l('Enable advanced stock management'), 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL, 'js' => array('on' => 'onchange="advancedStockManagementActivationAuthorization()"', 'off' => 'onchange="advancedStockManagementActivationAuthorization()"')), 'PS_FORCE_ASM_NEW_PRODUCT' => array('title' => $this->l('New products use advanced stock management'), 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array('title' => $this->l('Default warehouse on new products'), 'hint' => $this->l('Automatically set a default warehouse when new product is created'), 'type' => 'select', 'list' => $warehouse_list, 'identifier' => 'id_warehouse'), 'PS_PACK_STOCK_TYPE' => array('title' => $this->l('Default pack stock management'), 'type' => 'select', 'list' => array(array('pack_stock' => 0, 'name' => $this->l('Decrement pack only.')), array('pack_stock' => 1, 'name' => $this->l('Decrement products in pack only.')), array('pack_stock' => 2, 'name' => $this->l('Decrement both.'))), 'identifier' => 'pack_stock')), 'bottom' => '<script type="text/javascript">stockManagementActivationAuthorization();advancedStockManagementActivationAuthorization();</script>', 'submit' => array('title' => $this->l('Save')))); }
public function test_accessors() { /** === Test Data === */ $CODE = 'code'; $CUR = 'currency'; $ID = 'id'; $NOTE = 'note'; $STOCK_REF = 'stock'; /** === Call and asserts === */ $this->obj->setCode($CODE); $this->obj->setCurrency($CUR); $this->obj->setNote($NOTE); $this->obj->setStockRef($STOCK_REF); $this->assertEquals($CODE, $this->obj->getCode()); $this->assertEquals($CUR, $this->obj->getCurrency()); $this->assertEquals($NOTE, $this->obj->getNote()); $this->assertEquals($STOCK_REF, $this->obj->getStockRef()); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $rules = array("warehouseId" => "required", "warehouseName" => "required", "firstAddress" => "required", "area" => "required", "region" => "required", "warehousePhone" => "required|numeric", "warehouseFax" => "required|numeric", "warehouseEmail" => "required|email", "warehousePIC" => "required"); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/warehouse/create')->withErrors($validator); } // $warehouse = new Warehouse(); $warehouse->warehouseID = Input::get('warehouseId'); $warehouse->warehouseName = Input::get('warehouseName'); $warehouse->warehouseAddress1 = Input::get('firstAddress'); $warehouse->warehouseAddress2 = Input::get('secondAddress'); $warehouse->areaID = Input::get("area"); $warehouse->regionID = Input::get("region"); $warehouse->warehousePhone = Input::get("warehousePhone"); $warehouse->warehouseFax = Input::get("warehouseFax"); $warehouse->warehouseEmail = Input::get("warehouseEmail"); $warehouse->warehousePIC = Input::get("warehousePIC"); $warehouse->save(); return Redirect::to('/warehouse'); }
/** * postModal (入库确认) */ public function postModal() { //itemReceivedPackageDetail->id $id = Input::get('id'); $position = Input::get('readyposition'); $itemReceivedPackageDetail = ItemReceivedPackageDetail::find($id); $itemReceivedPackageDetail->status = 2; $itemReceivedPackageDetail->readyposition = $position; $itemReceivedPackageDetail->save(); //历史入库记录 $historyWareHouse = new HistoryWarehouse(); $historyWareHouse->identity = $itemReceivedPackageDetail->identity; $historyWareHouse->item = $itemReceivedPackageDetail->item; $historyWareHouse->batch = $itemReceivedPackageDetail->batch; $historyWareHouse->quantity = $itemReceivedPackageDetail->quantity; $historyWareHouse->position = $position; $historyWareHouse->operator = 5; $historyWareHouse->save(); //库存汇总 $wareHouse = Warehouse::where('item', $itemReceivedPackageDetail->item)->where('position', $position)->first(); if ($wareHouse) { $wareHouse->quantity = $wareHouse->quantity + $itemReceivedPackageDetail->quantity; $wareHouse->save(); } else { $wareHouse = new Warehouse(); $wareHouse->item = $itemReceivedPackageDetail->item; $wareHouse->position = $position; $wareHouse->quantity = $itemReceivedPackageDetail->quantity; $wareHouse->save(); } //更新item总库存 $items = Item::where('code', $itemReceivedPackageDetail->item)->first(); $items->stock += $itemReceivedPackageDetail->quantity; $items->readystock -= $itemReceivedPackageDetail->quantity; $items->save(); return Redirect::back(); }
public static function generateId() { $warehouse = Warehouse::orderBy('warehouseID', 'DESC')->get()->first(); $warehouseId = $warehouse->warehouseID; $warehouseId = substr($warehouseId, 2); $newId = (int) $warehouseId; $newId++; $newIdString = (string) $newId; $newIdString = "000000" . $newIdString; if (strlen($newIdString) > 3) { $newIdString = substr($newIdString, strlen($newIdString) - 3); } $newIdString = "wa" . $newIdString; return $newIdString; }
public function __construct() { $this->context = Context::getContext(); $this->table = 'product'; $this->className = 'Product'; $this->lang = true; $this->colorOnBackground = true; $this->multishop_context = Shop::CONTEXT_ALL; $this->fields_list = array('reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 200, 'filter_key' => 'a!reference'), 'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 100, 'filter_key' => 'a!ean13'), 'upc' => array('title' => $this->l('UPC'), 'align' => 'center', 'width' => 100, 'filter_key' => 'a!upc'), 'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'), 'qty_sold' => array('title' => $this->l('Quantity sold'), 'width' => 160, 'orderby' => false, 'search' => false, 'hint' => $this->l('Quantity sold during the defined period.')), 'coverage' => array('title' => $this->l('Coverage'), 'width' => 160, 'orderby' => false, 'search' => false, 'hint' => $this->l('Days left before your stock runs out.')), 'stock' => array('title' => $this->l('Quantity'), 'width' => 80, 'orderby' => false, 'search' => false, 'hint' => $this->l('Physical (usable) quantity.'))); // pre-defines coverage periods $this->stock_cover_periods = array($this->l('One week') => 7, $this->l('Two weeks') => 14, $this->l('Three weeks') => 21, $this->l('One month') => 31, $this->l('Six months') => 186, $this->l('One year') => 365); // gets the list of warehouses available $this->stock_cover_warehouses = Warehouse::getWarehouses(true); // gets the final list of warehouses array_unshift($this->stock_cover_warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses'))); parent::__construct(); }
public function renderDetails() { if (Tools::isSubmit('id_product')) { // override attributes $this->identifier = 'id_product_attribute'; $this->list_id = 'product_attribute'; $this->lang = false; $this->addRowAction('addstock'); $this->addRowAction('removestock'); if (count(Warehouse::getWarehouses()) > 1) { $this->addRowAction('transferstock'); } // no link on list rows $this->list_no_link = true; // inits toolbar $this->toolbar_btn = array(); // get current lang id $lang_id = (int) $this->context->language->id; // Get product id $product_id = (int) Tools::getValue('id_product'); // Load product attributes with sql override $this->table = 'product_attribute'; $this->list_id = 'product_attribute'; $this->_select = 'a.id_product_attribute as id, a.id_product, a.reference, a.ean13, a.upc'; $this->_where = 'AND a.id_product = ' . $product_id; $this->_group = 'GROUP BY a.id_product_attribute'; $this->fields_list = array('reference' => array('title' => $this->l('Product reference'), 'filter_key' => 'a!reference'), 'ean13' => array('title' => $this->l('EAN-13 or JAN barcode'), 'filter_key' => 'a!ean13'), 'upc' => array('title' => $this->l('UPC barcode'), 'filter_key' => 'a!upc'), 'name' => array('title' => $this->l('Name'), 'orderby' => false, 'filter' => false, 'search' => false), 'stock' => array('title' => $this->l('Quantity'), 'orderby' => false, 'filter' => false, 'search' => false, 'class' => 'fixed-width-sm', 'align' => 'center', 'hint' => $this->l('Quantitity total for all warehouses.'))); self::$currentIndex = self::$currentIndex . '&id_product=' . (int) $product_id . '&detailsproduct'; $this->processFilter(); return parent::renderList(); } }
}', 'select' => 'js:function(event, ui){ document.getElementById(\'keterangan\').innerHTML = \'Code : \'+ui.item.code; document.getElementById(\'component_id\').value = ui.item.id; }'), 'htmlOptions' => array('style' => 'height:25px;width:200px;padding:0px 5px;', 'class' => 'mf'), 'htmlOptions' => array('style' => 'width:50%;'))); ?> <input type="hidden" name="component_id" id="component_id"> </div> <div class="row"> <b id="keterangan"> </b></div> <div class="row"> <label>From Warehouse</label> <?php echo CHtml::dropDownList('warehouse_from', '', CHtml::listData(Warehouse::model()->findAll(), 'id', 'name_warehouse'), array('empty' => '-- select warehouse --')); ?> </div> <div class="row"> <label>To Warehouse</label> <?php echo CHtml::dropDownList('warehouse_to', '', CHtml::listData(Warehouse::model()->findAll(), 'id', 'name_warehouse'), array('empty' => '-- select warehouse --')); ?> </div> <div class="row"> <label>Qty</label> <input type="text" id="qty" name="qty" size="8"> </div> </div>
public function getAllocation($ProductId) { $product = Product::find($ProductId); $warehouse = Warehouse::where('id', '<>', $product->warehouse_id)->get(); return View::make('goods.allocation')->with('warehouse', $warehouse)->with('product', $product)->with('good', Good::find($product->good_id)); }
/** * Exports CSV */ public function renderCSV() { if (count($this->_list) <= 0) { return; } // sets warehouse id and warehouse name $id_warehouse = (int) Tools::getValue('id_warehouse'); $warehouse_name = Warehouse::getWarehouseNameById($id_warehouse); // if quantities requested if (Tools::isSubmit('csv_quantities')) { // filename $filename = $this->l('stock_instant_state_quantities') . '_' . $warehouse_name . '.csv'; // header header('Content-type: text/csv'); header('Cache-Control: no-store, no-cache must-revalidate'); header('Content-disposition: attachment; filename="' . $filename); // puts keys $keys = array('id_product', 'id_product_attribute', 'reference', 'ean13', 'upc', 'name', 'physical_quantity', 'usable_quantity', 'real_quantity'); echo sprintf("%s\n", implode(';', $keys)); // puts rows foreach ($this->_list as $row) { $row_csv = array($row['id_product'], $row['id_product_attribute'], $row['reference'], $row['ean13'], $row['upc'], $row['name'], $row['physical_quantity'], $row['usable_quantity'], $row['real_quantity']); // puts one row echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row_csv))); } } elseif (Tools::isSubmit('csv_prices')) { // sets filename $filename = $this->l('stock_instant_state_prices') . '_' . $warehouse_name . '.csv'; // header header('Content-type: text/csv'); header('Cache-Control: no-store, no-cache must-revalidate'); header('Content-disposition: attachment; filename="' . $filename); // puts keys $keys = array('id_product', 'id_product_attribute', 'reference', 'ean13', 'upc', 'name', 'price_te', 'physical_quantity', 'usable_quantity'); echo sprintf("%s\n", implode(';', $keys)); foreach ($this->_list as $row) { $id_product = (int) $row['id_product']; $id_product_attribute = (int) $row['id_product_attribute']; // gets prices $query = new DbQuery(); $query->select('s.price_te, SUM(s.physical_quantity) as physical_quantity, SUM(s.usable_quantity) as usable_quantity'); $query->from('stock', 's'); $query->leftJoin('warehouse', 'w', 'w.id_warehouse = s.id_warehouse'); $query->where('s.id_product = ' . $id_product . ' AND s.id_product_attribute = ' . $id_product_attribute); $query->where('s.id_warehouse = ' . $id_warehouse); $query->groupBy('s.price_te'); $datas = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); // puts data foreach ($datas as $data) { $row_csv = array($row['id_product'], $row['id_product_attribute'], $row['reference'], $row['ean13'], $row['upc'], $row['name'], $data['price_te'], $data['physical_quantity'], $data['usable_quantity']); // puts one row echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row_csv))); } } } }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * @param Product $product The id of the product, or an array with at least the package size and weight * @return array */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null) { if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $address = new Address($id_address); $id_zone = Address::getZoneById($address->id); // Check the country of the address is activated if (!Address::isCountryActiveById($address->id)) { return array(); } } else { $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (!empty($carriers)) { //the product is linked with carriers $carrier_list = array(); foreach ($carriers as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[] = $carrier['id_carrier']; } } if (!empty($carrier_list)) { return $carrier_list; } else { return array(); } //no linked carrier are available for this zone } $carrier_list = array(); // The product is not dirrectly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $customer = new Customer($cart->id_customer); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart); foreach ($carriers as $carrier) { $available_carrier_list[] = $carrier['id_carrier']; } if (empty($warehouse_carrier_list)) { $carrier_list = $available_carrier_list; } else { $carrier_list = array_intersect($warehouse_carrier_list, $available_carrier_list); } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); if ($carrier->max_width > 0 && $carrier->max_width < $product->width || $carrier->max_height > 0 && $carrier->max_height < $product->height || $carrier->max_depth > 0 && $carrier->max_depth < $product->depth || $carrier->max_weight > 0 && $carrier->max_weight < $product->weight) { unset($carrier_list[$key]); } } } return $carrier_list; }
public function postProcess() { if (Tools::getValue('submitAdd' . $this->table)) { /* Checking fields validity */ $this->validateRules(); if (!count($this->errors)) { $id = (int) Tools::getValue('id_' . $this->table); /* Object update */ if (isset($id) && !empty($id)) { try { if ($this->tabAccess['edit'] === '1') { $current_carrier = new Carrier($id); if (!Validate::isLoadedObject($current_carrier)) { throw new PrestaShopException('Cannot load Carrier object'); } // Duplicate current Carrier $new_carrier = $current_carrier->duplicateObject(); if (Validate::isLoadedObject($new_carrier)) { // Set flag deteled to true for historization $current_carrier->deleted = true; $current_carrier->update(); // Fill the new carrier object $this->copyFromPost($new_carrier, $this->table); $new_carrier->position = $current_carrier->position; $new_carrier->update(); $this->updateAssoShop($new_carrier->id); $new_carrier->copyCarrierData((int) $current_carrier->id); $this->changeGroups($new_carrier->id); // Call of hooks Hook::exec('actionCarrierUpdate', array('id_carrier' => (int) $current_carrier->id, 'carrier' => $new_carrier)); $this->postImage($new_carrier->id); $this->changeZones($new_carrier->id); $new_carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group')); Tools::redirectAdmin(self::$currentIndex . '&id_' . $this->table . '=' . $current_carrier->id . '&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . '</b>'; } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } catch (PrestaShopException $e) { $this->errors[] = $e->getMessage(); } } else { if ($this->tabAccess['add'] === '1') { // Create new Carrier $carrier = new Carrier(); $this->copyFromPost($carrier, $this->table); $carrier->position = Carrier::getHigherPosition() + 1; if ($carrier->add()) { if (($_POST['id_' . $this->table] = $carrier->id) && $this->postImage($carrier->id) && $this->_redirect) { $carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group'), true); $this->changeZones($carrier->id); $this->changeGroups($carrier->id); $this->updateAssoShop($carrier->id); Tools::redirectAdmin(self::$currentIndex . '&id_' . $this->table . '=' . $carrier->id . '&conf=3&token=' . $this->token); } } else { $this->errors[] = Tools::displayError('An error occurred while creating an object.') . ' <b>' . $this->table . '</b>'; } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } } parent::postProcess(); } else { if (isset($_GET['isFree' . $this->table])) { $this->processIsFree(); } else { /* if ((Tools::isSubmit('submitDel'.$this->table) && in_array(Configuration::get('PS_CARRIER_DEFAULT'), Tools::getValue('carrierBox'))) || (isset($_GET['delete'.$this->table]) && Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT'))) $this->errors[] = $this->l('Please set another carrier as default before deleting this one.'); else { */ // if deletion : removes the carrier from the warehouse/carrier association if (Tools::isSubmit('delete' . $this->table)) { $id = (int) Tools::getValue('id_' . $this->table); // Delete from the reference_id and not from the carrier id $carrier = new Carrier((int) $id); Warehouse::removeCarrier($carrier->id_reference); } else { if (Tools::isSubmit($this->table . 'Box') && count(Tools::isSubmit($this->table . 'Box')) > 0) { $ids = Tools::getValue($this->table . 'Box'); array_walk($ids, 'intval'); foreach ($ids as $id) { // Delete from the reference_id and not from the carrier id $carrier = new Carrier((int) $id); Warehouse::removeCarrier($carrier->id_reference); } } } parent::postProcess(); Carrier::cleanPositions(); //} } } }
/** * Called once $object is set. * Used to process the associations with address/shops/carriers * @see AdminController::afterAdd() * * @param Warehouse $object * * @return bool */ protected function afterAdd($object) { // handles address association $address = new Address($object->id_address); if (Validate::isLoadedObject($address)) { $address->id_warehouse = (int) $object->id; $address->save(); } // handles carriers associations $ids_carriers_selected = Tools::getValue('ids_carriers_selected'); if (Tools::isSubmit('ids_carriers_selected') && !empty($ids_carriers_selected)) { $object->setCarriers($ids_carriers_selected); } else { $object->setCarriers(Tools::getValue('ids_carriers_available')); } return true; }
public function calculateRate(ShippingPackage $package, Address $address) { $warehouse = Warehouse::closest_to($address); $distance = $warehouse->Address()->distanceTo($address); return $this->getDistanceFare($distance); }
/** * For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity * * @param int $id_product */ public static function synchronize($id_product, $order_id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } // gets warehouse ids grouped by shops $ids_warehouse = Warehouse::getWarehousesGroupedByShops(); if ($order_id_shop !== null) { $order_warehouses = array(); $wh = Warehouse::getWarehouses(false, (int) $order_id_shop); foreach ($wh as $warehouse) { $order_warehouses[] = $warehouse['id_warehouse']; } } // gets all product attributes ids $ids_product_attribute = array(); foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute) { $ids_product_attribute[] = $id_product_attribute['id_product_attribute']; } // Allow to order the product when out of stock? $out_of_stock = StockAvailable::outOfStock($id_product); $manager = StockManagerFactory::getManager(); // loops on $ids_warehouse to synchronize quantities foreach ($ids_warehouse as $id_shop => $warehouses) { // first, checks if the product depends on stock for the given shop $id_shop if (StockAvailable::dependsOnStock($id_product, $id_shop)) { // init quantity $product_quantity = 0; // if it's a simple product if (empty($ids_product_attribute)) { $allowed_warehouse_for_product = WareHouse::getProductWarehouseList((int) $id_product, 0, (int) $id_shop); $allowed_warehouse_for_product_clean = array(); foreach ($allowed_warehouse_for_product as $warehouse) { $allowed_warehouse_for_product_clean[] = (int) $warehouse['id_warehouse']; } $allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses); if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) { continue; } $product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true); } else { foreach ($ids_product_attribute as $id_product_attribute) { $allowed_warehouse_for_combination = WareHouse::getProductWarehouseList((int) $id_product, (int) $id_product_attribute, (int) $id_shop); $allowed_warehouse_for_combination_clean = array(); foreach ($allowed_warehouse_for_combination as $warehouse) { $allowed_warehouse_for_combination_clean[] = (int) $warehouse['id_warehouse']; } $allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses); if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) { continue; } $quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true); $query = new DbQuery(); $query->select('COUNT(*)'); $query->from('stock_available'); $query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop)); if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) { $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop)); Db::getInstance()->update($query['table'], $query['data'], $query['where']); } else { $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity, 'depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute)); StockAvailable::addSqlShopParams($query['data']); Db::getInstance()->insert($query['table'], $query['data']); } $product_quantity += $quantity; Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity)); } } // updates // if $id_product has attributes, it also updates the sum for all attributes $query = array('table' => 'stock_available', 'data' => array('quantity' => $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $id_shop)); Db::getInstance()->update($query['table'], $query['data'], $query['where']); } } // In case there are no warehouses, removes product from StockAvailable if (count($ids_warehouse) == 0) { Db::getInstance()->update('stock_available', array('quantity' => 0), 'id_product = ' . (int) $id_product); } }
/** * For a given pack, returns the warehouse it can be shipped from * * @param int $id_product * @return int|bool id_warehouse or false */ public static function getPackWarehouses($id_product, $id_shop = null) { if (!Pack::isPack($id_product)) { return false; } if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } // warehouses of the pack $pack_warehouses = WarehouseProductLocation::getCollection((int) $id_product); // products in the pack $products = Pack::getItems((int) $id_product, Configuration::get('PS_LANG_DEFAULT')); // array with all warehouses id to check $list = array(); // fills $list foreach ($pack_warehouses as $pack_warehouse) { $list['pack_warehouses'][] = (int) $pack_warehouse->id_warehouse; } // for each products in the pack foreach ($products as $product) { if ($product->advanced_stock_management) { // gets the warehouses of one product $product_warehouses = Warehouse::getProductWarehouseList((int) $product->id, 0, (int) $id_shop); $list[(int) $product->id] = array(); // fills array with warehouses for this product foreach ($product_warehouses as $product_warehouse) { $list[(int) $product->id][] = $product_warehouse['id_warehouse']; } } } $res = false; // returns final list if (count($list) > 1) { $res = call_user_func_array('array_intersect', $list); } return $res; }
public function getPackageIdWarehouse($package, $id_carrier = null) { if ($id_carrier === null) { if (isset($package['id_carrier'])) { $id_carrier = (int) $package['id_carrier']; } } if ($id_carrier == null) { return $package['id_warehouse']; } foreach ($package['warehouse_list'] as $id_warehouse) { $warehouse = new Warehouse((int) $id_warehouse); $available_warehouse_carriers = $warehouse->getCarriers(); if (in_array($id_carrier, $available_warehouse_carriers)) { return (int) $id_warehouse; } } return 0; }
<?php if (cfr('WAREHOUSE')) { $altcfg = $ubillingConfig->getAlter(); if ($altcfg['WAREHOUSE_ENABLED']) { $greed = new Avarice(); $avidity = $greed->runtime('WAREHOUSE'); if (!empty($avidity)) { $warehouse = new Warehouse(); show_window('', $warehouse->{$avidity}['M']['WARLOCK']()); //categories if (wf_CheckGet(array($avidity['S']['C']))) { if (wf_CheckPost(array($avidity['S']['CC']))) { $warehouse->{$avidity}['M']['CC']($_POST[$avidity['S']['CC']]); rcms_redirect($warehouse::URL_ME . '&' . $warehouse::URL_CATEGORIES); } if (wf_CheckGet(array($avidity['S']['CD']))) { $deletionResult = $warehouse->{$avidity}['M']['CD']($_GET[$avidity['S']['CD']]); if ($deletionResult) { rcms_redirect($warehouse::URL_ME . '&' . $warehouse::URL_CATEGORIES); } else { show_error(__('You cant do this')); } } if (wf_CheckPost(array($avidity['S']['CE1'], $avidity['S']['CE2']))) { $warehouse->{$avidity}['M']['CS'](); rcms_redirect($warehouse::URL_ME . '&' . $warehouse::URL_CATEGORIES); } show_window(__('Categories'), $warehouse->{$avidity}['M']['CF']()); show_window(__('Available categories'), $warehouse->{$avidity}['M']['CL']()); $warehouse->{$avidity}['M']['FALL']();
public function ajaxProcessSearchProducts() { Context::getContext()->customer = new Customer((int) Tools::getValue('id_customer')); $currency = new Currency((int) Tools::getValue('id_currency')); if ($products = Product::searchByName((int) $this->context->language->id, pSQL(Tools::getValue('product_search')))) { foreach ($products as &$product) { // Formatted price $product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency); // Concret price $product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2); $product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2); $productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id); $combinations = array(); $attributes = $productObj->getAttributesGroups((int) $this->context->language->id); // Tax rate for this customer if (Tools::isSubmit('id_address')) { $product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address'))); } $product['warehouse_list'] = array(); foreach ($attributes as $attribute) { if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) { $combinations[$attribute['id_product_attribute']]['attributes'] = ''; } $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - '; $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute']; $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on']; if (!isset($combinations[$attribute['id_product_attribute']]['price'])) { $price_tax_incl = Product::getPriceStatic((int) $product['id_product'], true, $attribute['id_product_attribute']); $price_tax_excl = Product::getPriceStatic((int) $product['id_product'], false, $attribute['id_product_attribute']); $combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2); $combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2); $combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency); } if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) { $combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], $attribute['id_product_attribute'], (int) $this->context->shop->id); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) { $product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']); } else { $product['warehouse_list'][$attribute['id_product_attribute']] = array(); } $product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) { $product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']); } else { $product['warehouse_list'][0] = array(); } $product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], 0, (int) $this->context->shop->id); foreach ($combinations as &$combination) { $combination['attributes'] = rtrim($combination['attributes'], ' - '); } $product['combinations'] = $combinations; if ($product['customizable']) { $product_instance = new Product((int) $product['id_product']); $product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id); } } $to_return = array('products' => $products, 'found' => true); } else { $to_return = array('found' => false); } $this->content = Tools::jsonEncode($to_return); }
/** * Verify course * * @param string action (optional) * @return bool true on sucess */ public function verify($action = NULL) { // If action is 'add', make sure that course id/alias is unique if ($action == 'add') { $warehouse = new Warehouse(); $courseIdExists = $warehouse->getCourseByAlias($this->getCourseId()); if ($courseIdExists) { throw new \Exception(Lang::txt('Course with this alias already exists.')); } } parent::verify($action); }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * * @param Product $product The id of the product, or an array with at least the package size and weight * @param int $id_warehouse Warehouse ID * @param int $id_address_delivery Delivery Address ID * @param int $id_shop Shop ID * @param Cart $cart Cart object * @param array &$error contain an error message if an error occurs * * @return array Available Carriers * @throws PrestaShopDatabaseException */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null, &$error = array()) { static $ps_country_default = null; if ($ps_country_default === null) { $ps_country_default = Configuration::get('PS_COUNTRY_DEFAULT'); } if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } if (is_null($error) || !is_array($error)) { $error = array(); } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $id_zone = Address::getZoneById($id_address); // Check the country of the address is activated if (!Address::isCountryActiveById($id_address)) { return array(); } } else { $country = new Country($ps_country_default); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop; if (!Cache::isStored($cache_id)) { $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0 AND c.active = 1'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $carriers_for_product); } else { $carriers_for_product = Cache::retrieve($cache_id); } $carrier_list = array(); if (!empty($carriers_for_product)) { //the product is linked with carriers foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } } if (empty($carrier_list)) { return array(); } //no linked carrier are available for this zone } // The product is not directly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $cache_id = 'Carrier::getAvailableCarrierList_getCarriersForOrder_' . (int) $id_zone . '-' . (int) $cart->id; if (!Cache::isStored($cache_id)) { $customer = new Customer($cart->id_customer); $carrier_error = array(); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart, $carrier_error); Cache::store($cache_id, array($carriers, $carrier_error)); } else { list($carriers, $carrier_error) = Cache::retrieve($cache_id); } $error = array_merge($error, $carrier_error); foreach ($carriers as $carrier) { $available_carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } if ($carrier_list) { $carrier_list = array_intersect($available_carrier_list, $carrier_list); } else { $carrier_list = $available_carrier_list; } if (isset($warehouse_carrier_list)) { $carrier_list = array_intersect($carrier_list, $warehouse_carrier_list); } $cart_quantity = 0; $cart_weight = 0; foreach ($cart->getProducts(false, false) as $cart_product) { if ($cart_product['id_product'] == $product->id) { $cart_quantity += $cart_product['cart_quantity']; } if (isset($cart_product['weight_attribute']) && $cart_product['weight_attribute'] > 0) { $cart_weight += $cart_product['weight_attribute'] * $cart_product['cart_quantity']; } else { $cart_weight += $cart_product['weight'] * $cart_product['cart_quantity']; } } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0 || $cart_weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); // Get the sizes of the carrier and the product and sort them to check if the carrier can take the product. $carrier_sizes = array((int) $carrier->max_width, (int) $carrier->max_height, (int) $carrier->max_depth); $product_sizes = array((int) $product->width, (int) $product->height, (int) $product->depth); rsort($carrier_sizes, SORT_NUMERIC); rsort($product_sizes, SORT_NUMERIC); if ($carrier_sizes[0] > 0 && $carrier_sizes[0] < $product_sizes[0] || $carrier_sizes[1] > 0 && $carrier_sizes[1] < $product_sizes[1] || $carrier_sizes[2] > 0 && $carrier_sizes[2] < $product_sizes[2]) { $error[$carrier->id] = Carrier::SHIPPING_SIZE_EXCEPTION; unset($carrier_list[$key]); } if ($carrier->max_weight > 0 && ($carrier->max_weight < $product->weight * $cart_quantity || $carrier->max_weight < $cart_weight)) { $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; unset($carrier_list[$key]); } } } return $carrier_list; }
public function getDeliveryOptionList(Country $default_country = null, $flush = false) { static $cache = null; if ($cache !== null && !$flush) { return $cache; } $delivery_option_list = array(); $carriers_price = array(); $carrier_collection = array(); $package_list = $this->getPackageList(); // Foreach addresses foreach ($package_list as $id_address => $packages) { // Initialize vars $delivery_option_list[$id_address] = array(); $carriers_price[$id_address] = array(); $common_carriers = null; $best_price_carriers = array(); $best_grade_carriers = array(); $carriers_instance = array(); // Get country if ($id_address) { $address = new Address($id_address); $country = new Country($address->id_country); } else { $country = $default_country; } // Foreach packages, get the carriers with best price, best position and best grade foreach ($packages as $id_package => $package) { // No carriers available if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0) { $package['carrier_list'] = array(103, 96, 97); // $cache = array(); // return $cache; } $carriers_price[$id_address][$id_package] = array(); // Get all common carriers for each packages to the same address if (is_null($common_carriers)) { $common_carriers = $package['carrier_list']; } else { $common_carriers = array_intersect($common_carriers, $package['carrier_list']); } $best_price = null; $best_price_carrier = null; $best_grade = null; $best_grade_carrier = null; // Foreach carriers of the package, calculate his price, check if it the best price, position and grade foreach ($package['carrier_list'] as $id_carrier) { if (!isset($carriers_instance[$id_carrier])) { $carriers_instance[$id_carrier] = new Carrier($id_carrier); } $price_with_tax = $this->getPackageShippingCost($id_carrier, true, $country, $package['product_list']); $price_without_tax = $this->getPackageShippingCost($id_carrier, false, $country, $package['product_list']); if (is_null($best_price) || $price_with_tax < $best_price) { $best_price = $price_with_tax; $best_price_carrier = $id_carrier; } $carriers_price[$id_address][$id_package][$id_carrier] = array('without_tax' => $price_without_tax, 'with_tax' => $price_with_tax); $grade = $carriers_instance[$id_carrier]->grade; if (is_null($best_grade) || $grade > $best_grade) { $best_grade = $grade; $best_grade_carrier = $id_carrier; } } $best_price_carriers[$id_package] = $best_price_carrier; $best_grade_carriers[$id_package] = $best_grade_carrier; } // Reset $best_price_carrier, it's now an array $best_price_carrier = array(); $key = ''; // Get the delivery option with the lower price foreach ($best_price_carriers as $id_package => $id_carrier) { $key .= $id_carrier . ','; if (!isset($best_price_carrier[$id_carrier])) { $best_price_carrier[$id_carrier] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array()); } $best_price_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax']; $best_price_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax']; $best_price_carrier[$id_carrier]['package_list'][] = $id_package; $best_price_carrier[$id_carrier]['product_list'] = array_merge($best_price_carrier[$id_carrier]['product_list'], $packages[$id_package]['product_list']); $best_price_carrier[$id_carrier]['instance'] = $carriers_instance[$id_carrier]; } // Add the delivery option with best price as best price $delivery_option_list[$id_address][$key] = array('carrier_list' => $best_price_carrier, 'is_best_price' => true, 'is_best_grade' => false, 'unique_carrier' => count($best_price_carrier) <= 1); // Reset $best_grade_carrier, it's now an array $best_grade_carrier = array(); $key = ''; // Get the delivery option with the best grade foreach ($best_grade_carriers as $id_package => $id_carrier) { $key .= $id_carrier . ','; if (!isset($best_grade_carrier[$id_carrier])) { $best_grade_carrier[$id_carrier] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array()); } $best_grade_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax']; $best_grade_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax']; $best_grade_carrier[$id_carrier]['package_list'][] = $id_package; $best_grade_carrier[$id_carrier]['product_list'] = array_merge($best_grade_carrier[$id_carrier]['product_list'], $packages[$id_package]['product_list']); $best_grade_carrier[$id_carrier]['instance'] = $carriers_instance[$id_carrier]; } // Add the delivery option with best grade as best grade if (!isset($delivery_option_list[$id_address][$key])) { $delivery_option_list[$id_address][$key] = array('carrier_list' => $best_grade_carrier, 'is_best_price' => false, 'unique_carrier' => count($best_grade_carrier) <= 1); } $delivery_option_list[$id_address][$key]['is_best_grade'] = true; // Get all delivery options with a unique carrier foreach ($common_carriers as $id_carrier) { $key = ''; $package_list = array(); $product_list = array(); $price_with_tax = 0; $price_without_tax = 0; foreach ($packages as $id_package => $package) { $key .= $id_carrier . ','; $price_with_tax += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax']; $price_without_tax += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax']; $package_list[] = $id_package; $product_list = array_merge($product_list, $package['product_list']); } if (!isset($delivery_option_list[$id_address][$key])) { $delivery_option_list[$id_address][$key] = array('is_best_price' => false, 'is_best_grade' => false, 'unique_carrier' => true, 'carrier_list' => array($id_carrier => array('price_with_tax' => $price_with_tax, 'price_without_tax' => $price_without_tax, 'instance' => $carriers_instance[$id_carrier], 'package_list' => $package_list, 'product_list' => $product_list))); } else { $delivery_option_list[$id_address][$key]['unique_carrier'] = count($delivery_option_list[$id_address][$key]['carrier_list']) <= 1; } } } $cart_rules = CartRule::getCustomerCartRules(Context::getContext()->cookie->id_lang, Context::getContext()->cookie->id_customer, true); $free_carriers_rules = array(); foreach ($cart_rules as $cart_rule) { if ($cart_rule['free_shipping'] && $cart_rule['carrier_restriction']) { $cr = new CartRule((int) $cart_rule['id_cart_rule']); if (Validate::isLoadedObject($cr)) { $carriers = $cr->getAssociatedRestrictions('carrier', true, false); if (is_array($carriers) && count($carriers) && isset($carriers['selected'])) { foreach ($carriers['selected'] as $carrier) { if (isset($carrier['id_carrier']) && $carrier['id_carrier']) { $free_carriers_rules[] = (int) $carrier['id_carrier']; } } } } } } $product_stock_1 = false; $product_stock_2 = false; $custom = false; $stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'); if ($stock_management_active) { $products = $this->getProducts(); foreach ($products as $product) { $flag = false; $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']); $manager = StockManagerFactory::getManager(); foreach ($warehouse_list as $key => $warehouse) { $product_real_quantities = $manager->getProductRealQuantities($product['id_product'], $product['id_product_attribute'], array($warehouse['id_warehouse']), true); if ($key == 0 && $product_real_quantities > 0) { $flag = true; $product_stock_1 = true; } if ($key == 1 && $product_real_quantities > 0) { $product_stock_2 = true; $flag = true; } } if (!$flag) { $custom = true; break; } } } $langs = Language::getLanguages(); // For each delivery options : // - Set the carrier list // - Calculate the price // - Calculate the average position foreach ($delivery_option_list as $id_address => $delivery_option) { foreach ($delivery_option as $key => $value) { $total_price_with_tax = 0; $total_price_without_tax = 0; $position = 0; foreach ($value['carrier_list'] as $id_carrier => $data) { $total_price_with_tax += $data['price_with_tax']; $total_price_without_tax += $data['price_without_tax']; $total_price_without_tax_with_rules = in_array($id_carrier, $free_carriers_rules) ? 0 : $total_price_without_tax; if (!isset($carrier_collection[$id_carrier])) { $carrier_collection[$id_carrier] = new Carrier($id_carrier); } switch (true) { case $custom: if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Шарлотенбурге') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2-3 недели'; } } if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Русском доме') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2-3 недели'; } } break; case !$custom && ($product_stock_1 && $product_stock_2): if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Шарлотенбурге') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2 дня'; } } if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Русском доме') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2 дня'; } } break; case !$custom && (!$product_stock_1 && $product_stock_2): if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Шарлотенбурге') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2 дня'; } } if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Русском доме') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '1 день'; } } break; case !$custom && ($product_stock_1 && !$product_stock_2): if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Шарлотенбурге') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '1 день'; } } if ($carrier_collection[$id_carrier]->name == 'Самовывоз в Русском доме') { foreach ($langs as $lang) { $carrier_collection[$id_carrier]->delay[$lang['id_lang']] = '2 дня'; } } break; } $delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance'] = $carrier_collection[$id_carrier]; if (file_exists(_PS_SHIP_IMG_DIR_ . $id_carrier . '.jpg')) { $delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = _THEME_SHIP_DIR_ . $id_carrier . '.jpg'; } else { $delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = false; } $position += $carrier_collection[$id_carrier]->position; } $delivery_option_list[$id_address][$key]['total_price_with_tax'] = $total_price_with_tax; $delivery_option_list[$id_address][$key]['total_price_without_tax'] = $total_price_without_tax; $delivery_option_list[$id_address][$key]['is_free'] = !$total_price_without_tax_with_rules ? true : false; $delivery_option_list[$id_address][$key]['position'] = $position / count($value['carrier_list']); } } // Sort delivery option list foreach ($delivery_option_list as &$array) { uasort($array, array('Cart', 'sortDeliveryOptionList')); } $cache = $delivery_option_list; return $delivery_option_list; }
/** * Exports CSV */ public function renderCSV() { if (!$this->_list) { return; } // header if (Tools::getValue('id_warehouse') != -1) { $filename = $this->l('stock_mvt') . '_' . Warehouse::getWarehouseNameById((int) Tools::getValue('id_warehouse')) . '.csv'; } else { $filename = $this->l('stock_mvt') . '.csv'; } header('Content-type: text/csv'); header('Cache-Control: no-store, no-cache'); header('Content-disposition: attachment; filename="' . $filename); // puts keys $keys = array('id_order', 'id_supply_order', 'emloyee_firstname', 'employee_lastname', 'physical_quantity', 'date_add', 'sign', 'price_te', 'product_name', 'label', 'product_reference', 'product_ean13', 'product_upc'); echo sprintf("%s\n", implode(';', $keys)); // puts rows foreach ($this->_list as $row) { $row_csv = array($row['id_order'], $row['id_supply_order'], $row['employee_firstname'], $row['employee_lastname'], $row['physical_quantity'], $row['date_add'], $row['sign'], $row['price_te'], $row['product_name'], $row['reason'], $row['product_reference'], $row['product_ean13'], $row['product_upc']); // puts one row echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row_csv))); } }
public function initFormWarehouses($obj) { $data = $this->createTemplate($this->tpl_form); if ($obj->id) { if ($this->product_exists_in_shop) { // Get all id_product_attribute $attributes = $obj->getAttributesResume($this->context->language->id); if (empty($attributes)) { $attributes[] = array('id_product' => $obj->id, 'id_product_attribute' => 0, 'attribute_designation' => ''); } $product_designation = array(); foreach ($attributes as $attribute) { $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id] . ' - ' . $attribute['attribute_designation'], ' - '); } // Get all available warehouses $warehouses = Warehouse::getWarehouses(true); // Get already associated warehouses $associated_warehouses_collection = WarehouseProductLocation::getCollection($obj->id); $data->assign(array('attributes' => $attributes, 'warehouses' => $warehouses, 'associated_warehouses' => $associated_warehouses_collection, 'product_designation' => $product_designation, 'product' => $obj, 'link' => $this->context->link, 'token' => $this->token)); } else { $this->displayWarning($this->l('You must save the product in this shop before managing warehouses.')); } } else { $this->displayWarning($this->l('You must save this product before managing warehouses.')); } $this->tpl_form_vars['custom_form'] = $data->fetch(); }