本文整理汇总了PHP中Warehouse::getWarehousesByProductId方法的典型用法代码示例。如果您正苦于以下问题:PHP Warehouse::getWarehousesByProductId方法的具体用法?PHP Warehouse::getWarehousesByProductId怎么用?PHP Warehouse::getWarehousesByProductId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Warehouse
的用法示例。
在下文中一共展示了Warehouse::getWarehousesByProductId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderForm
/**
* AdminController::renderForm() override
* @see AdminController::renderForm()
*/
public function renderForm()
{
// gets the product
$id_product = (int) Tools::getValue('id_product');
$id_product_attribute = (int) Tools::getValue('id_product_attribute');
// gets warehouses
$warehouses_add = Warehouse::getWarehouses(true);
$warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
// displays warning if no warehouses
if (!$warehouses_add) {
$this->displayWarning($this->l('You must choose a warehouses before adding stock. See Stock/Warehouses'));
}
//get currencies list
$currencies = Currency::getCurrencies();
$id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
$default_currency = Currency::getCurrency($id_default_currency);
if ($default_currency) {
$currencies = array_merge(array($default_currency, '-'), $currencies);
}
// switch, in order to display the form corresponding to the current action
switch ($this->display) {
case 'addstock':
// gets the last stock mvt for this product, so we can display the last unit price te and the last quantity added
$last_sm_unit_price_te = $this->l('N/A');
$last_sm_quantity = 0;
$last_sm_quantity_is_usable = -1;
$last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
// if there is a stock mvt
if ($last_sm != false) {
$last_sm_currency = new Currency((int) $last_sm['id_currency']);
$last_sm_quantity = (int) $last_sm['physical_quantity'];
$last_sm_quantity_is_usable = (int) $last_sm['is_usable'];
if (Validate::isLoadedObject($last_sm_currency)) {
$last_sm_unit_price_te = Tools::displayPrice((double) $last_sm['price_te'], $last_sm_currency);
}
}
$this->displayInformation($this->l('Rolling over the quantity and price fields will give you the details about the last stock movement.'));
// fields in the form
$this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Add a product to your stock.'), 'image' => '../img/admin/add_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('UPC:'), 'name' => 'upc', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to add:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to add'), 'hint' => sprintf($this->l('Last physical quantity added : %s (%s)'), $last_sm_quantity > 0 ? $last_sm_quantity : $this->l('N/A'), $last_sm_quantity > 0 ? $last_sm_quantity_is_usable >= 0 ? $this->l('Usable') : $this->l('Not usable') : $this->l('N/A'))), array('type' => 'radio', 'label' => $this->l('Usable for sale?'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this quantity ready to be displayed in your shop, or is it reserved in the warehouse for other purposes?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Please select the warehouse that you\'ll be adding products to. ')), array('type' => 'text', 'label' => $this->l('Unit price (tax excl.):'), 'name' => 'price', 'required' => true, 'size' => 10, 'maxlength' => 10, 'desc' => $this->l('Unit purchase price or unit manufacturing cost for this product (tax excl.)'), 'hint' => sprintf($this->l('Last unit price (tax excl.): %s'), $last_sm_unit_price_te)), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'desc' => $this->l('The currency associated to the product unit price.')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')), 1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Add to stock'), 'class' => 'button'));
$this->fields_value['usable'] = 1;
break;
case 'removestock':
$this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Remove the product from your stock.'), 'image' => '../img/admin/remove_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to remove:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to remove')), array('type' => 'radio', 'label' => $this->l('Usable for sale:'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want to remove this quantity from the usable quantity (yes) or the physical quantity (no)?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to remove the product from.')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')), -1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Remove from stock'), 'class' => 'button'));
break;
case 'transferstock':
$this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Transfer a product from one warehouse to another'), 'image' => '../img/admin/transfer_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to transfer:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Quantity to transfer:')), array('type' => 'select', 'label' => $this->l('Source Warehouse:'), 'name' => 'id_warehouse_from', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to transfer the product from.')), array('type' => 'radio', 'label' => $this->l('Is this product usable in your source warehouse?'), 'name' => 'usable_from', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this the usable quantity for sale?')), array('type' => 'select', 'label' => $this->l('Destination warehouse:'), 'name' => 'id_warehouse_to', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to transfer your product(s) to. ')), array('type' => 'radio', 'label' => $this->l('Is this product for sale in your destination warehouse?'), 'name' => 'usable_to', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want it to be for sale/useable?'))), 'submit' => array('title' => $this->l('Transfer'), 'class' => 'button'));
break;
}
$this->initToolbar();
}
示例2: generateProductsData
protected function generateProductsData()
{
$delimiter = ';';
$titles = array();
$id_lang = $this->use_lang;
$new_path = new Sampledatainstall();
$f = fopen($new_path->sendPath() . 'output/products.vsc', 'w');
foreach ($this->product_fields as $field => $array) {
$titles[] = $array['label'];
}
fputcsv($f, $titles, $delimiter, '"');
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true);
foreach ($products as $product) {
$line = array();
$p = new Product($product['id_product'], true, $id_lang, 1);
foreach ($this->product_fields as $field => $array) {
$line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : '';
}
$cats = $p->getProductCategoriesFull($p->id, 1);
$cat_array = array();
foreach ($cats as $cat) {
$cat_array[] = $cat['id_category'];
}
$line['categories'] = implode(',', $cat_array);
$line['price_tex'] = $p->getPrice(false);
$line['price_tin'] = $p->getPrice(true);
$line['upc'] = $p->upc ? $p->upc : '';
$line['features'] = '';
$features = $p->getFrontFeatures($id_lang);
$position = 1;
$devider = '';
foreach ($features as $feature) {
$sql = 'SELECT `id_feature`
FROM ' . _DB_PREFIX_ . 'feature_lang
WHERE `name` = "' . pSql($feature['name']) . '"';
$sql1 = 'SELECT `id_feature_value`
FROM ' . _DB_PREFIX_ . 'feature_value_lang
WHERE `value` = "' . pSql($feature['value']) . '"';
$id_feature = Db::getInstance()->getValue($sql);
$id_feature_value = Db::getInstance()->getValue($sql1);
$line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position;
$devider = ',';
$position++;
}
$specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0);
$line['reduction_price'] = '';
$line['reduction_percent'] = '';
$line['reduction_from'] = '';
$line['reduction_to'] = '';
if ($specificPrice) {
if ($specificPrice['reduction_type'] == 'amount') {
$line['reduction_price'] = $specificPrice['reduction'];
} elseif ($specificPrice['reduction_type'] == 'percent') {
$line['reduction_percent'] = $specificPrice['reduction'];
}
if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
$line['reduction_from'] = $specificPrice['from'];
$line['reduction_to'] = $specificPrice['to'];
}
}
$tags = $p->getTags($id_lang);
$line['tags'] = $tags;
$link = new Link();
$imagelinks = array();
$images = $p->getImages($id_lang);
foreach ($images as $image) {
$imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
$this->copyConverFileName($imagelink);
$imagelinks[] = $imagelink;
}
$line['image'] = implode(',', $imagelinks);
$line['delete_existing_images'] = 0;
$line['shop'] = 1;
$warehouses = Warehouse::getWarehousesByProductId($p->id);
$line['warehouse'] = '';
if (!empty($warehouses)) {
$line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
}
$values = array();
$accesories = $p->getAccessories($id_lang);
if (isset($accesories) && $accesories && count($accesories)) {
foreach ($accesories as $accesorie) {
$values[] = $accesorie['id_product'];
}
}
$line['accessories'] = $values ? implode(',', $values) : '';
$values = array();
$carriers = $p->getCarriers();
if (isset($carriers) && $carriers && count($carriers)) {
foreach ($carriers as $carrier) {
$values[] = $carrier['id_carrier'];
}
}
$line['carriers'] = $values ? implode(',', $values) : '';
$values = array();
$customization_fields_ids = $p->getCustomizationFieldIds();
if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) {
foreach ($customization_fields_ids as $customization_field_id) {
$cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang);
$values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name;
//.........这里部分代码省略.........
示例3: renderView
public function renderView()
{
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order)) {
$this->errors[] = Tools::displayError('The order cannot be found within your database.');
}
$customer = new Customer($order->id_customer);
$carrier = new Carrier($order->id_carrier);
$products = $this->getProducts($order);
$order_details = AphOrderDetail::getList($order->id);
foreach ($order_details as &$order_detail) {
$products[$order_detail['id_order_detail']]['delivery_date'] = $order_detail['delivery_date'];
$products[$order_detail['id_order_detail']]['delivery_time_from'] = $order_detail['delivery_time_from'];
$products[$order_detail['id_order_detail']]['delivery_time_to'] = $order_detail['delivery_time_to'];
}
$currency = new Currency((int) $order->id_currency);
// Carrier module call
$carrier_module_call = null;
if ($carrier->is_module) {
$module = Module::getInstanceByName($carrier->external_module_name);
if (method_exists($module, 'displayInfoByCart')) {
$carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
}
}
// Retrieve addresses information
$addressInvoice = new Address($order->id_address_invoice, $this->context->language->id);
if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) {
$invoiceState = new State((int) $addressInvoice->id_state);
}
if ($order->id_address_invoice == $order->id_address_delivery) {
$addressDelivery = $addressInvoice;
if (isset($invoiceState)) {
$deliveryState = $invoiceState;
}
} else {
$addressDelivery = new Address($order->id_address_delivery, $this->context->language->id);
if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) {
$deliveryState = new State((int) $addressDelivery->id_state);
}
}
$this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname);
if (Shop::isFeatureActive()) {
$shop = new Shop((int) $order->id_shop);
$this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name);
}
// gets warehouses to ship products, if and only if advanced stock management is activated
$warehouse_list = null;
$order_details = $order->getOrderDetailList();
foreach ($order_details as $order_detail) {
$product = new Product($order_detail['product_id']);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) {
$warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
foreach ($warehouses as $warehouse) {
if (!isset($warehouse_list[$warehouse['id_warehouse']])) {
$warehouse_list[$warehouse['id_warehouse']] = $warehouse;
}
}
}
}
$payment_methods = array();
foreach (PaymentModule::getInstalledPaymentModules() as $payment) {
$module = Module::getInstanceByName($payment['name']);
if (Validate::isLoadedObject($module) && $module->active) {
$payment_methods[] = $module->displayName;
}
}
// display warning if there are products out of stock
$display_out_of_stock_warning = false;
$current_order_state = $order->getCurrentOrderState();
if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) {
$display_out_of_stock_warning = true;
}
// products current stock (from stock_available)
foreach ($products as &$product) {
// Get total customized quantity for current product
$customized_product_quantity = 0;
if (is_array($product['customizedDatas'])) {
foreach ($product['customizedDatas'] as $customizationPerAddress) {
foreach ($customizationPerAddress as $customizationId => $customization) {
$customized_product_quantity += (int) $customization['quantity'];
}
}
}
$product['customized_product_quantity'] = $customized_product_quantity;
$product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
$resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
$product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
$product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
$product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
$product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
$product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']);
$product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']);
// if the current stock requires a warning
if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) {
$this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']);
}
if ($product['id_warehouse'] != 0) {
$warehouse = new Warehouse((int) $product['id_warehouse']);
$product['warehouse_name'] = $warehouse->name;
$warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']);
//.........这里部分代码省略.........
示例4: getStockByCarrier
/**
* For a given product, retrieves the stock in function of the delivery option
*
* @param int $id_product
* @param int $id_product_attribute optional
* @param array $delivery_option
* @return int quantity
*/
public static function getStockByCarrier($id_product = 0, $id_product_attribute = 0, $delivery_option = null)
{
if (!(int) $id_product || !is_array($delivery_option) || !is_int($id_product_attribute)) {
return false;
}
$results = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
$stock_quantity = 0;
foreach ($results as $result) {
if (isset($result['id_warehouse']) && (int) $result['id_warehouse']) {
$ws = new Warehouse((int) $result['id_warehouse']);
$carriers = $ws->getWsCarriers();
if (is_array($carriers) && !empty($carriers)) {
$stock_quantity += Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT SUM(s.`usable_quantity`) as quantity
FROM ' . _DB_PREFIX_ . 'stock s
LEFT JOIN ' . _DB_PREFIX_ . 'warehouse_carrier wc ON wc.`id_warehouse` = s.`id_warehouse`
LEFT JOIN ' . _DB_PREFIX_ . 'carrier c ON wc.`id_carrier` = c.`id_reference`
WHERE s.`id_product` = ' . (int) $id_product . ' AND s.`id_product_attribute` = ' . (int) $id_product_attribute . ' AND s.`id_warehouse` = ' . $result['id_warehouse'] . ' AND c.`id_carrier` IN (' . rtrim($delivery_option[(int) Context::getContext()->cart->id_address_delivery], ',') . ') GROUP BY s.`id_product`');
} else {
$stock_quantity += Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT SUM(s.`usable_quantity`) as quantity
FROM ' . _DB_PREFIX_ . 'stock s
WHERE s.`id_product` = ' . (int) $id_product . ' AND s.`id_product_attribute` = ' . (int) $id_product_attribute . ' AND s.`id_warehouse` = ' . $result['id_warehouse'] . ' GROUP BY s.`id_product`');
}
}
}
return $stock_quantity;
}
示例5: renderView
public function renderView()
{
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order)) {
$this->errors[] = Tools::displayError('The order cannot be found within your database.');
}
$customer = new Customer($order->id_customer);
$carrier = new Carrier($order->id_carrier);
$products = $this->getProducts($order);
$currency = new Currency((int) $order->id_currency);
// Carrier module call
$carrier_module_call = null;
if ($carrier->is_module) {
$module = Module::getInstanceByName($carrier->external_module_name);
if (method_exists($module, 'displayInfoByCart')) {
$carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
}
}
// Retrieve addresses information
$addressInvoice = new Address($order->id_address_invoice, $this->context->language->id);
if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) {
$invoiceState = new State((int) $addressInvoice->id_state);
}
if ($order->id_address_invoice == $order->id_address_delivery) {
$addressDelivery = $addressInvoice;
if (isset($invoiceState)) {
$deliveryState = $invoiceState;
}
} else {
$addressDelivery = new Address($order->id_address_delivery, $this->context->language->id);
if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) {
$deliveryState = new State((int) $addressDelivery->id_state);
}
}
$this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname);
if (Shop::isFeatureActive()) {
$shop = new Shop((int) $order->id_shop);
$this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name);
}
// gets warehouses to ship products, if and only if advanced stock management is activated
$warehouse_list = null;
$order_details = $order->getOrderDetailList();
foreach ($order_details as $order_detail) {
$product = new Product($order_detail['product_id']);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) {
$warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
foreach ($warehouses as $warehouse) {
if (!isset($warehouse_list[$warehouse['id_warehouse']])) {
$warehouse_list[$warehouse['id_warehouse']] = $warehouse;
}
}
}
}
$payment_methods = array();
foreach (PaymentModule::getInstalledPaymentModules() as $payment) {
$module = Module::getInstanceByName($payment['name']);
if (Validate::isLoadedObject($module) && $module->active) {
$payment_methods[] = $module->displayName;
}
}
// display warning if there are products out of stock
$display_out_of_stock_warning = false;
$current_order_state = $order->getCurrentOrderState();
if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) {
$display_out_of_stock_warning = true;
}
// products current stock (from stock_available)
foreach ($products as &$product) {
// Get total customized quantity for current product
$customized_product_quantity = 0;
if (is_array($product['customizedDatas'])) {
foreach ($product['customizedDatas'] as $customizationPerAddress) {
foreach ($customizationPerAddress as $customizationId => $customization) {
$customized_product_quantity += (int) $customization['quantity'];
}
}
}
$product['customized_product_quantity'] = $customized_product_quantity;
$product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
$resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
$product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
$product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
$product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
$product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
$product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']);
$product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']);
// if the current stock requires a warning
if ($product['current_stock'] == 0 && $display_out_of_stock_warning) {
$this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']);
}
if ($product['id_warehouse'] != 0) {
$warehouse = new Warehouse((int) $product['id_warehouse']);
$product['warehouse_name'] = $warehouse->name;
$warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']);
if (!empty($warehouse_location)) {
$product['warehouse_location'] = $warehouse_location;
} else {
$product['warehouse_location'] = false;
}
} else {
//.........这里部分代码省略.........
示例6: postProcess
public function postProcess()
{
if (Tools::isSubmit('submitExport')) {
$delimiter = Tools::getValue('export_delimiter');
$id_lang = Tools::getValue('export_language');
$id_shop = (int) $this->context->shop->id;
set_time_limit(0);
$fileName = 'products_' . date("Y_m_d_H_i_s") . '.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$f = fopen('php://output', 'w');
foreach ($this->available_fields as $field => $array) {
$titles[] = $array['label'];
}
fputcsv($f, $titles, $delimiter, '"');
$export_active = Tools::getValue('export_active') == 0 ? false : true;
$export_category = Tools::getValue('export_category') == 99999 ? false : Tools::getValue('export_category');
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', $export_category, $export_active);
foreach ($products as $product) {
$line = array();
$p = new Product($product['id_product'], true, $id_lang, $id_shop);
$p->loadStockData();
foreach ($this->available_fields as $field => $array) {
if (isset($p->{$field}) && !is_array($p->{$field})) {
$line[$field] = $p->{$field} ? $p->{$field} : ' ';
} else {
switch ($field) {
case 'categories':
$cats = $p->getProductCategoriesFull($p->id, $id_lang);
$cat_array = array();
foreach ($cats as $cat) {
$cat_array[] = $cat['name'];
}
$line['categories'] = implode(",", $cat_array);
break;
case 'price_tex':
$line['price_tex'] = $p->getPrice(false);
$line['price_tin'] = $p->getPrice(true);
break;
case 'upc':
$line['upc'] = $p->upc ? $p->upc : ' ';
break;
case 'features':
$line['features'] = '';
$features = $p->getFrontFeatures($id_lang);
$position = 1;
foreach ($features as $feature) {
$line['features'] .= $feature['name'] . ':' . $feature['value'] . ':' . $position;
$position++;
}
break;
case 'reduction_price':
$specificPrice = SpecificPrice::getSpecificPrice($p->id, $id_shop, 0, 0, 0, 0);
$line['reduction_price'] = '';
$line['reduction_percent'] = '';
$line['reduction_from'] = '';
$line['reduction_to'] = '';
if ($specificPrice['reduction_type'] == "amount") {
$line['reduction_price'] = $specificPrice['reduction'];
} elseif ($specificPrice['reduction_type'] == "percent") {
$line['reduction_percent'] = $specificPrice['reduction'];
}
if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
$line['reduction_from'] = date_format(date_create($specificPrice['from']), "Y-m-d");
$line['reduction_to'] = date_format(date_create($specificPrice['to']), "Y-m-d");
}
break;
case 'tags':
$tags = $p->getTags($id_lang);
$line['tags'] = $tags;
break;
case 'image':
$link = new Link();
$imagelinks = array();
$images = $p->getImages($id_lang);
foreach ($images as $image) {
$imagelinks[] = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
}
$line['image'] = implode(",", $imagelinks);
break;
case 'delete_existing_images':
$line['delete_existing_images'] = 0;
break;
case 'shop':
$line['shop'] = $id_shop;
break;
case 'warehouse':
$warehouses = Warehouse::getWarehousesByProductId($p->id);
$line['warehouse'] = '';
if (!empty($warehouses)) {
$line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
}
break;
case 'date_added':
$date = new DateTime($p->date_add);
$line['date_add'] = $date->format("Y-m-d");
//.........这里部分代码省略.........
示例7: renderView
public function renderView()
{
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order)) {
$this->errors[] = $this->trans('The order cannot be found within your database.', array(), 'Admin.OrdersCustomers.Notification');
}
$customer = new Customer($order->id_customer);
$carrier = new Carrier($order->id_carrier);
$products = $this->getProducts($order);
$currency = new Currency((int) $order->id_currency);
// Carrier module call
$carrier_module_call = null;
if ($carrier->is_module) {
$module = Module::getInstanceByName($carrier->external_module_name);
if (method_exists($module, 'displayInfoByCart')) {
$carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
}
}
// Retrieve addresses information
$addressInvoice = new Address($order->id_address_invoice, $this->context->language->id);
if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) {
$invoiceState = new State((int) $addressInvoice->id_state);
}
if ($order->id_address_invoice == $order->id_address_delivery) {
$addressDelivery = $addressInvoice;
if (isset($invoiceState)) {
$deliveryState = $invoiceState;
}
} else {
$addressDelivery = new Address($order->id_address_delivery, $this->context->language->id);
if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) {
$deliveryState = new State((int) $addressDelivery->id_state);
}
}
$this->toolbar_title = $this->trans('Order #%id% (%ref%) - %firstname% %lastname%', array('%id%' => $order->id, '%ref%' => $order->reference, '%firstname%' => $customer->firstname, '%lastname%' => $customer->lastname), 'Admin.OrdersCustomers.Feature');
if (Shop::isFeatureActive()) {
$shop = new Shop((int) $order->id_shop);
$this->toolbar_title .= ' - ' . sprintf($this->trans('Shop: %s', array(), 'Admin.OrdersCustomers.Feature'), $shop->name);
}
// gets warehouses to ship products, if and only if advanced stock management is activated
$warehouse_list = null;
$order_details = $order->getOrderDetailList();
foreach ($order_details as $order_detail) {
$product = new Product($order_detail['product_id']);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) {
$warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
foreach ($warehouses as $warehouse) {
if (!isset($warehouse_list[$warehouse['id_warehouse']])) {
$warehouse_list[$warehouse['id_warehouse']] = $warehouse;
}
}
}
}
$payment_methods = array();
foreach (PaymentModule::getInstalledPaymentModules() as $payment) {
$module = Module::getInstanceByName($payment['name']);
if (Validate::isLoadedObject($module) && $module->active) {
$payment_methods[] = $module->displayName;
}
}
// display warning if there are products out of stock
$display_out_of_stock_warning = false;
$current_order_state = $order->getCurrentOrderState();
if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) {
$display_out_of_stock_warning = true;
}
// products current stock (from stock_available)
foreach ($products as &$product) {
// Get total customized quantity for current product
$customized_product_quantity = 0;
if (is_array($product['customizedDatas'])) {
foreach ($product['customizedDatas'] as $customizationPerAddress) {
foreach ($customizationPerAddress as $customizationId => $customization) {
$customized_product_quantity += (int) $customization['quantity'];
}
}
}
$product['customized_product_quantity'] = $customized_product_quantity;
$product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
$resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
$product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
$product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
$product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
$product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
$product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']);
$product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']);
// if the current stock requires a warning
if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) {
$this->displayWarning($this->trans('This product is out of stock: ', array(), 'Admin.OrdersCustomers.Notification') . ' ' . $product['product_name']);
}
if ($product['id_warehouse'] != 0) {
$warehouse = new Warehouse((int) $product['id_warehouse']);
$product['warehouse_name'] = $warehouse->name;
$warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']);
if (!empty($warehouse_location)) {
$product['warehouse_location'] = $warehouse_location;
} else {
$product['warehouse_location'] = false;
}
} else {
//.........这里部分代码省略.........