[+] BO : add new feature, Order edition
This commit is contained in:
+22
-4
@@ -66,13 +66,31 @@ function generateSupplyOrderFormPDF()
|
|||||||
|
|
||||||
function generateInvoicePDF()
|
function generateInvoicePDF()
|
||||||
{
|
{
|
||||||
if (!isset($_GET['id_order']))
|
if (Tools::isSubmit('id_order'))
|
||||||
die (Tools::displayError('Missing order ID'));
|
generateInvoicePDFByIdOrder(Tools::getValue('id_order'));
|
||||||
$order = new Order((int)($_GET['id_order']));
|
elseif (Tools::isSubmit('id_order_invoice'))
|
||||||
|
generateInvoicePDFByIdOrderInvoice(Tools::getValue('id_order_invoice'));
|
||||||
|
else
|
||||||
|
die (Tools::displayError('Missing order ID or invoice order ID'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateInvoicePDFByIdOrder($id_order)
|
||||||
|
{
|
||||||
|
$order = new Order($id_order);
|
||||||
if (!Validate::isLoadedObject($order))
|
if (!Validate::isLoadedObject($order))
|
||||||
die(Tools::displayError('Cannot find order in database'));
|
die(Tools::displayError('Cannot find order in database'));
|
||||||
|
|
||||||
generatePDF($order, PDF::TEMPLATE_INVOICE);
|
generatePDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateInvoicePDFByIdOrderInvoice($id_order_invoice)
|
||||||
|
{
|
||||||
|
$order_invoice = new OrderInvoice($id_order_invoice);
|
||||||
|
if (!Validate::isLoadedObject($order_invoice))
|
||||||
|
die(Tools::displayError('Cannot find order invoice in database'));
|
||||||
|
|
||||||
|
generatePDF($order_invoice, PDF::TEMPLATE_INVOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateOrderSlipPDF()
|
function generateOrderSlipPDF()
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td align="center" class="cancelCheck">--</td>
|
<td align="center" class="cancelCheck">--</td>
|
||||||
|
<td align="center" class="cancelQuantity">--</td>
|
||||||
</tr>
|
</tr>
|
||||||
{foreach from=$product.customizedDatas key=customizationId item=customization}
|
{foreach from=$product.customizedDatas key=customizationId item=customization}
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<tr id="new_product" height="52" style="display:none;background-color:#E8EDC2">
|
||||||
|
<td style="display:none;" colspan="2">
|
||||||
|
<input type="hidden" id="add_product_product_id" name="add_product[product_id]" value="0" />
|
||||||
|
{l s='Product:'} <input type="text" id="add_product_product_name" value="" size="42" />
|
||||||
|
<div id="add_product_product_attribute_area" style="margin-top: 5px;display: none;">
|
||||||
|
{l s='Combinations:'} <select name="add_product[product_attribute_id]" id="add_product_product_attribute_id"></select>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td style="display:none;">
|
||||||
|
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="add_product[product_price_tax_excl]" id="add_product_product_price_tax_excl" value="" size="4" disabled="disabled" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax excl.'}<br />
|
||||||
|
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="add_product[product_price_tax_incl]" id="add_product_product_price_tax_incl" value="" size="4" disabled="disabled" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax incl.'}<br />
|
||||||
|
</td>
|
||||||
|
<td style="display:none;" align="center" class="productQuantity"><input type="text" name="add_product[product_quantity]" id="add_product_product_quantity" value="1" size="3" disabled="disabled" /></td>
|
||||||
|
{if ($order->hasBeenPaid())}<td style="display:none;" align="center" class="productQuantity"> </td>{/if}
|
||||||
|
{if ($order->hasBeenDelivered())}<td style="display:none;" align="center" class="productQuantity"> </td>{/if}
|
||||||
|
<td style="display:none;" align="center" class="productQuantity" id="add_product_product_stock">0</td>
|
||||||
|
<td style="display:none;" align="center" id="add_product_product_total">{displayPrice price=0 currency=$currency->id}</td>
|
||||||
|
<td style="display:none;" align="center" colspan="2">
|
||||||
|
{if $order->valid}
|
||||||
|
<select name="add_product[invoice]" id="add_product_product_invoice" disabled="disabled">
|
||||||
|
<optgroup label="{l s='Existing'}">
|
||||||
|
{foreach from=$invoices_collection item=invoice}
|
||||||
|
<option value="{$invoice->id}">#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$invoice->number}</option>
|
||||||
|
{/foreach}
|
||||||
|
</optgroup>
|
||||||
|
<optgroup label="{l s='New'}">
|
||||||
|
<option value="0">{l s='Create a new invoice'}</option>
|
||||||
|
</optgroup>
|
||||||
|
</select>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td style="display:none;">
|
||||||
|
<input type="button" class="button" id="submitAddProduct" value="{l s='Add product'}" disabled="disabled" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr id="new_invoice" style="display:none;background-color:#E8EDC2">
|
||||||
|
<td colspan="10">
|
||||||
|
<h3>{l s='New invoice informations'}</h3>
|
||||||
|
<label>{l s='Carrier:'}</label>
|
||||||
|
<div class="margin-form">
|
||||||
|
{$carrier->name}
|
||||||
|
</div>
|
||||||
|
<div class="margin-form">
|
||||||
|
<input type="checkbox" name="add_invoice[free_shipping]" value="1" />
|
||||||
|
<label class="t">{l s='Free shipping'}</label>
|
||||||
|
<p>{l s='If you don\'t select the "Free shipping", the normal shipping cost will be applied'}</p>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
{*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/afl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 10336 $
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*}
|
||||||
|
|
||||||
|
{* Generate HTML code for printing Invoice Icon with link *}
|
||||||
|
<span style="width:20px; margin-right:5px;">
|
||||||
|
{if (($order_state->invoice && $order->invoice_number) && $tr['product_number'])}
|
||||||
|
<a href="pdf.php?id_order={$order->id}&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>
|
||||||
|
{else}
|
||||||
|
-
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{* Generate HTML code for printing Delivery Icon with link *}
|
||||||
|
<span style="width:20px;">
|
||||||
|
{if ($order_state->delivery && $order->delivery_number)}
|
||||||
|
<a href="pdf.php?id_delivery={$order->delivery_number}"><img src="../img/admin/delivery.gif" alt="delivery" /></a>
|
||||||
|
{else}
|
||||||
|
-
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
|
|
||||||
{* Assign product price *}
|
{* Assign product price *}
|
||||||
{if ($order->getTaxCalculationMethod() == $smarty.const.PS_TAX_EXC)}
|
{if ($order->getTaxCalculationMethod() == $smarty.const.PS_TAX_EXC)}
|
||||||
{assign var=product_price value=($product['product_price'] + $product['ecotax'])}
|
{assign var=product_price value=($product['unit_price_tax_excl'] + $product['ecotax'])}
|
||||||
{else}
|
{else}
|
||||||
{assign var=product_price value=$product['product_price_wt']}
|
{assign var=product_price value=$product['unit_price_tax_incl']}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if ($product['product_quantity'] > $product['customizationQuantityTotal'])}
|
{if ($product['product_quantity'] > $product['customizationQuantityTotal'])}
|
||||||
@@ -39,13 +39,31 @@
|
|||||||
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
|
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
|
||||||
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
|
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
|
||||||
</a></td>
|
</a></td>
|
||||||
<td align="center">{displayPrice price=$product_price currency=$currency->id}</td>
|
<td align="center">
|
||||||
<td align="center" class="productQuantity" {if ($product['product_quantity'] > 1)}style="font-weight:700;font-size:1.1em;color:red"{/if}>{$product['product_quantity']}</td>
|
<span class="product_price_show">{displayPrice price=$product_price currency=$currency->id}</span>
|
||||||
|
{if $can_edit}
|
||||||
|
<span class="product_price_edit" style="display:none;">
|
||||||
|
<input type="hidden" name="product_id_order_detail" class="edit_product_id_order_detail" value="{$product['id_order_detail']}" />
|
||||||
|
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="product_price_tax_excl" class="edit_product_price_tax_excl edit_product_price" value="{Tools::ps_round($product['unit_price_tax_excl'], 2)}" size="5" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax excl.'}<br />
|
||||||
|
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="product_price_tax_incl" class="edit_product_price_tax_incl edit_product_price" value="{Tools::ps_round($product['unit_price_tax_incl'], 2)}" size="5" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax incl.'}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td align="center" class="productQuantity">
|
||||||
|
<span class="product_quantity_show">{$product['product_quantity']}</span>
|
||||||
|
{if $can_edit}
|
||||||
|
<span class="product_quantity_edit" style="display:none;">
|
||||||
|
<input type="text" name="product_quantity" class="edit_product_quantity" value="{$product['product_quantity']}" size="2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
{if ($order->hasBeenPaid())}<td align="center" class="productQuantity">{$product['product_quantity_refunded']}</td>{/if}
|
{if ($order->hasBeenPaid())}<td align="center" class="productQuantity">{$product['product_quantity_refunded']}</td>{/if}
|
||||||
{if ($order->hasBeenDelivered())}<td align="center" class="productQuantity">{$product['product_quantity_return']}</td>{/if}
|
{if ($order->hasBeenDelivered())}<td align="center" class="productQuantity">{$product['product_quantity_return']}</td>{/if}
|
||||||
<td align="center" class="productQuantity">{StockManagerFactory::getManager()->getProductRealQuantities($product['product_id'], $product['product_attribute_id'], null, true)}</td>
|
<td align="center" class="productQuantity product_stock">{StockManagerFactory::getManager()->getProductRealQuantities($product['product_id'], $product['product_attribute_id'], null, true)}</td>
|
||||||
<td align="center">{displayPrice price=(Tools::ps_round($product_price, 2) * ($product['product_quantity'] - $product['customizationQuantityTotal'])) currency=$currency->id}</td>
|
<td align="center" class="total_product">
|
||||||
<td align="center" class="cancelCheck">
|
{displayPrice price=(Tools::ps_round($product_price, 2) * ($product['product_quantity'] - $product['customizationQuantityTotal'])) currency=$currency->id}
|
||||||
|
</td>
|
||||||
|
<td align="center" class="cancelCheck standard_refund_fields" style="background-color:rgb(232, 237, 194);display:none">
|
||||||
<input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="{$product['product_quantity_return']}" />
|
<input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="{$product['product_quantity_return']}" />
|
||||||
<input type="hidden" name="totalQty" id="totalQty" value="{$product['product_quantity']}" />
|
<input type="hidden" name="totalQty" id="totalQty" value="{$product['product_quantity']}" />
|
||||||
<input type="hidden" name="productName" id="productName" value="{$product['product_name']}" />
|
<input type="hidden" name="productName" id="productName" value="{$product['product_name']}" />
|
||||||
@@ -55,7 +73,7 @@
|
|||||||
--
|
--
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td class="cancelQuantity">
|
<td class="cancelQuantity standard_refund_fields" style="background-color:rgb(232, 237, 194);display:none">
|
||||||
{if ($product['product_quantity_return'] + $product['product_quantity_refunded'] >= $product['product_quantity'])}
|
{if ($product['product_quantity_return'] + $product['product_quantity_refunded'] >= $product['product_quantity'])}
|
||||||
<input type="hidden" name="cancelQuantity[{$k}]" value="0" />
|
<input type="hidden" name="cancelQuantity[{$k}]" value="0" />
|
||||||
{elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN'))}
|
{elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN'))}
|
||||||
@@ -76,5 +94,25 @@
|
|||||||
0/{$productQuantity}
|
0/{$productQuantity}
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="partial_refund_fields" style="text-align:right;background-color:rgb(232, 237, 194);display:none"><input type="text" size="3" name="partialRefund[{$k}]" /> €</td>
|
||||||
|
{if $can_edit}
|
||||||
|
<td class="product_invoice" colspan="2" style="display: none;text-align:center;">
|
||||||
|
{if $order->hasBeenPaid()}
|
||||||
|
<select name="product_invoice" class="edit_product_invoice">
|
||||||
|
{foreach from=$invoices_collection item=invoice}
|
||||||
|
<option value="{$invoice->id}" {if $invoice->id == $product['id_order_invoice']}selected="selected"{/if}>#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$invoice->number}</option>
|
||||||
|
{/foreach}
|
||||||
|
</select>
|
||||||
|
{else}
|
||||||
|
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td class="product_action" style="text-align:right">
|
||||||
|
<a href="#" class="edit_product_change_link"><img src="../img/admin/edit.gif" alt="{l s='Edit'}" /></a>
|
||||||
|
<input type="submit" class="button" name="submitProductChange" value="{l s='Update'}" style="display: none;" />
|
||||||
|
<a href="#" class="cancel_product_change_link" style="display: none;"><img src="../img/admin/disabled.gif" alt="{l s='Cancel'}" /></a>
|
||||||
|
<a href="#" class="delete_product_line"><img src="../img/admin/delete.gif" alt="{l s='Delete'}" /></a>
|
||||||
|
</td>
|
||||||
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -467,10 +467,10 @@
|
|||||||
products_found += '<label>{l s='Product:'}</label><select id="id_product" onclick="displayProductAttributes();">';
|
products_found += '<label>{l s='Product:'}</label><select id="id_product" onclick="displayProductAttributes();">';
|
||||||
attributes_html += '<label>{l s='Combination:'}</label>';
|
attributes_html += '<label>{l s='Combination:'}</label>';
|
||||||
$.each(res.products, function() {
|
$.each(res.products, function() {
|
||||||
products_found += '<option '+(this.combinations.length > 0 ? 'rel="'+this.qty_in_stock+'"' : '')+' value="'+this.id_product+'">'+this.name+(this.combinations.length == 0 ? ' - '+this.price : '')+'</option>';
|
products_found += '<option '+(this.combinations.length > 0 ? 'rel="'+this.qty_in_stock+'"' : '')+' value="'+this.id_product+'">'+this.name+(this.combinations.length == 0 ? ' - '+this.formatted_price : '')+'</option>';
|
||||||
attributes_html += '<select class="id_product_attribute" id="ipa_'+this.id_product+'" style="display:none;">';
|
attributes_html += '<select class="id_product_attribute" id="ipa_'+this.id_product+'" style="display:none;">';
|
||||||
$.each(this.combinations, function() {
|
$.each(this.combinations, function() {
|
||||||
attributes_html += '<option rel="'+this.qty_in_stock+'" '+(this.default_on == 1 ? 'selected="selected"' : '')+' value="'+this.id_product_attribute+'">'+this.attributes+' - '+this.price+'</option>';
|
attributes_html += '<option rel="'+this.qty_in_stock+'" '+(this.default_on == 1 ? 'selected="selected"' : '')+' value="'+this.id_product_attribute+'">'+this.attributes+' - '+this.formatted_price+'</option>';
|
||||||
});
|
});
|
||||||
attributes_html += '</select>';
|
attributes_html += '</select>';
|
||||||
});
|
});
|
||||||
@@ -508,7 +508,7 @@
|
|||||||
var cart_content = '';
|
var cart_content = '';
|
||||||
$.each(products, function() {
|
$.each(products, function() {
|
||||||
cart_quantity[this.id_product+'_'+this.id_product_attribute] = this.cart_quantity;
|
cart_quantity[this.id_product+'_'+this.id_product_attribute] = this.cart_quantity;
|
||||||
cart_content += '<tr><td><img src="'+this.image_link+'" title="'+this.name+'" /></td><td>'+this.name+'<br />'+this.attributes_small+'</td><td>'+this.reference+'</td><td><input type="text" size="7" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="product_unit_price" value="'+this.price+'" /> <span class="currency_sign"></span></td><td>';
|
cart_content += '<tr><td><img src="'+this.image_link+'" title="'+this.name+'" /></td><td>'+this.name+'<br />'+this.attributes_small+'</td><td>'+this.reference+'</td><td><input type="text" size="7" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="product_unit_price" value="'+this.formatted_price+'" /> <span class="currency_sign"></span></td><td>';
|
||||||
cart_content += '<p><a href="#" class="delete_product" rel="delete_'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/delete.gif" /></a>';
|
cart_content += '<p><a href="#" class="delete_product" rel="delete_'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/delete.gif" /></a>';
|
||||||
cart_content += '<a href="#" class="increaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/up.gif" /></a><input type="text" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="cart_quantity" size="2" value="'+this.cart_quantity+'" /></p>';
|
cart_content += '<a href="#" class="increaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/up.gif" /></a><input type="text" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="cart_quantity" size="2" value="'+this.cart_quantity+'" /></p>';
|
||||||
cart_content += '<p style="float:right"><center><a href="#" class="decreaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'"><img src="../img/admin/down.gif" /></center></a>';
|
cart_content += '<p style="float:right"><center><a href="#" class="decreaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'"><img src="../img/admin/down.gif" /></center></a>';
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -918,6 +918,8 @@ class AdminControllerCore extends Controller
|
|||||||
'desc' => $this->l('Save')
|
'desc' => $this->l('Save')
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'view':
|
||||||
|
break;
|
||||||
default: // list
|
default: // list
|
||||||
$this->toolbar_btn['new'] = array(
|
$this->toolbar_btn['new'] = array(
|
||||||
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
|
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
|
||||||
@@ -1849,7 +1851,6 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
if (empty($order_by))
|
if (empty($order_by))
|
||||||
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
|
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
|
||||||
|
|
||||||
if (empty($order_way))
|
if (empty($order_way))
|
||||||
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
|
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
|
||||||
|
|
||||||
|
|||||||
+80
-79
@@ -75,9 +75,9 @@ class CartCore extends ObjectModel
|
|||||||
public $checkedTos = false;
|
public $checkedTos = false;
|
||||||
public $pictures;
|
public $pictures;
|
||||||
public $textFields;
|
public $textFields;
|
||||||
|
|
||||||
public $delivery_option;
|
public $delivery_option;
|
||||||
|
|
||||||
/** @var boolean Allow to seperate order in multiple package in order to recieve as soon as possible the available products */
|
/** @var boolean Allow to seperate order in multiple package in order to recieve as soon as possible the available products */
|
||||||
public $allow_seperated_package = false;
|
public $allow_seperated_package = false;
|
||||||
|
|
||||||
@@ -257,6 +257,7 @@ class CartCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated 1.5.0.1
|
* @deprecated 1.5.0.1
|
||||||
|
* @see Cart::getCartRules()
|
||||||
*/
|
*/
|
||||||
public function getDiscounts($lite = false, $refresh = false)
|
public function getDiscounts($lite = false, $refresh = false)
|
||||||
{
|
{
|
||||||
@@ -691,7 +692,7 @@ class CartCore extends ObjectModel
|
|||||||
$context = Context::getContext()->cloneContext();
|
$context = Context::getContext()->cloneContext();
|
||||||
$context->cart = $this;
|
$context->cart = $this;
|
||||||
CartRule::autoAddToCart($context);
|
CartRule::autoAddToCart($context);
|
||||||
|
|
||||||
if ($product->customizable)
|
if ($product->customizable)
|
||||||
return $this->_updateCustomizationQuantity((int)$quantity, (int)$id_customization, (int)$id_product, (int)$id_product_attribute, $operator);
|
return $this->_updateCustomizationQuantity((int)$quantity, (int)$id_customization, (int)$id_product, (int)$id_product_attribute, $operator);
|
||||||
else
|
else
|
||||||
@@ -983,7 +984,7 @@ class CartCore extends ObjectModel
|
|||||||
return 0;
|
return 0;
|
||||||
if ($virtual AND $type == Cart::BOTH)
|
if ($virtual AND $type == Cart::BOTH)
|
||||||
$type = Cart::BOTH_WITHOUT_SHIPPING;
|
$type = Cart::BOTH_WITHOUT_SHIPPING;
|
||||||
|
|
||||||
if ($type != Cart::BOTH_WITHOUT_SHIPPING AND $type != Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
|
if ($type != Cart::BOTH_WITHOUT_SHIPPING AND $type != Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
|
||||||
{
|
{
|
||||||
if (is_null($products) && is_null($id_carrier))
|
if (is_null($products) && is_null($id_carrier))
|
||||||
@@ -993,13 +994,13 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$shipping_fees = 0;
|
$shipping_fees = 0;
|
||||||
|
|
||||||
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
|
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
|
||||||
$type = Cart::ONLY_PRODUCTS;
|
$type = Cart::ONLY_PRODUCTS;
|
||||||
|
|
||||||
if (is_null($products))
|
if (is_null($products))
|
||||||
$products = $this->getProducts();
|
$products = $this->getProducts();
|
||||||
|
|
||||||
$order_total = 0;
|
$order_total = 0;
|
||||||
if (Tax::excludeTaxeOption())
|
if (Tax::excludeTaxeOption())
|
||||||
$withTaxes = false;
|
$withTaxes = false;
|
||||||
@@ -1068,10 +1069,10 @@ class CartCore extends ObjectModel
|
|||||||
return $order_total_discount;
|
return $order_total_discount;
|
||||||
return Tools::ps_round((float)$order_total, 2);
|
return Tools::ps_round((float)$order_total, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
|
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
|
||||||
*
|
*
|
||||||
* @return array array(
|
* @return array array(
|
||||||
* 0 => array( // First address
|
* 0 => array( // First address
|
||||||
* 0 => array( // First package
|
* 0 => array( // First package
|
||||||
@@ -1095,15 +1096,15 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (!isset($warehouse_count_by_address[$product['id_address_delivery']]))
|
if (!isset($warehouse_count_by_address[$product['id_address_delivery']]))
|
||||||
$warehouse_count_by_address[$product['id_address_delivery']] = array();
|
$warehouse_count_by_address[$product['id_address_delivery']] = array();
|
||||||
|
|
||||||
$product['warehouse_list'] = array();
|
$product['warehouse_list'] = array();
|
||||||
|
|
||||||
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
|
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
|
||||||
// Does the product is in stock ?
|
// Does the product is in stock ?
|
||||||
// If yes, get only warehouse where the product is in stock
|
// If yes, get only warehouse where the product is in stock
|
||||||
$warehouse_in_stock = array();
|
$warehouse_in_stock = array();
|
||||||
$manager = StockManagerFactory::getManager();
|
$manager = StockManagerFactory::getManager();
|
||||||
|
|
||||||
foreach ($warehouse_list as $key => $warehouse)
|
foreach ($warehouse_list as $key => $warehouse)
|
||||||
{
|
{
|
||||||
if ($manager->getProductRealQuantities(
|
if ($manager->getProductRealQuantities(
|
||||||
@@ -1121,7 +1122,7 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$product['in_stock'] = false;
|
$product['in_stock'] = false;
|
||||||
|
|
||||||
foreach ($warehouse_list as $warehouse)
|
foreach ($warehouse_list as $warehouse)
|
||||||
{
|
{
|
||||||
if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']]))
|
if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']]))
|
||||||
@@ -1129,21 +1130,21 @@ class CartCore extends ObjectModel
|
|||||||
$warehouse_object = new Warehouse($warehouse['id_warehouse']);
|
$warehouse_object = new Warehouse($warehouse['id_warehouse']);
|
||||||
$warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
|
$warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
|
||||||
}
|
}
|
||||||
|
|
||||||
$product['warehouse_list'][] = $warehouse['id_warehouse'];
|
$product['warehouse_list'][] = $warehouse['id_warehouse'];
|
||||||
if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]))
|
if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]))
|
||||||
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
|
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
|
||||||
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
|
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If product from the cart are not in any warehouse, return false
|
// If product from the cart are not in any warehouse, return false
|
||||||
//foreach ($warehouse_count_by_address as $warehouse_count)
|
//foreach ($warehouse_count_by_address as $warehouse_count)
|
||||||
// if (empty($warehouse_count))
|
// if (empty($warehouse_count))
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
arsort($warehouse_count_by_address);
|
arsort($warehouse_count_by_address);
|
||||||
|
|
||||||
// Step 2 : Group product by warehouse
|
// Step 2 : Group product by warehouse
|
||||||
$grouped_by_warehouse = array();
|
$grouped_by_warehouse = array();
|
||||||
foreach ($product_list as &$product)
|
foreach ($product_list as &$product)
|
||||||
@@ -1153,32 +1154,32 @@ class CartCore extends ObjectModel
|
|||||||
'in_stock' => array(),
|
'in_stock' => array(),
|
||||||
'out_of_stock' => array(),
|
'out_of_stock' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Determine the warehouse to use for this product in order to reduce the number of package
|
// Determine the warehouse to use for this product in order to reduce the number of package
|
||||||
$id_warehouse = 0;
|
$id_warehouse = 0;
|
||||||
foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_warehouse)
|
foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_warehouse)
|
||||||
if (in_array($id_warehouse, $product['warehouse_list']))
|
if (in_array($id_warehouse, $product['warehouse_list']))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse]))
|
if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse]))
|
||||||
{
|
{
|
||||||
$grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
|
$grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
|
||||||
$grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
|
$grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->allow_seperated_package)
|
if (!$this->allow_seperated_package)
|
||||||
$key = 'in_stock';
|
$key = 'in_stock';
|
||||||
else
|
else
|
||||||
$key = ($product['in_stock']) ? 'in_stock' : 'out_of_stock';
|
$key = ($product['in_stock']) ? 'in_stock' : 'out_of_stock';
|
||||||
|
|
||||||
$product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse);
|
$product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse);
|
||||||
|
|
||||||
if (empty($product['carrier_list']))
|
if (empty($product['carrier_list']))
|
||||||
$product['carrier_list'] = array(0);
|
$product['carrier_list'] = array(0);
|
||||||
|
|
||||||
$grouped_by_warehouse[$product['id_address_delivery']][$key][$id_warehouse][] = $product;
|
$grouped_by_warehouse[$product['id_address_delivery']][$key][$id_warehouse][] = $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3 : grouped product from grouped_by_warehouse by available carriers
|
// Step 3 : grouped product from grouped_by_warehouse by available carriers
|
||||||
$grouped_by_carriers = array();
|
$grouped_by_carriers = array();
|
||||||
foreach ($grouped_by_warehouse as $id_address_delivery => $products_in_stock_list)
|
foreach ($grouped_by_warehouse as $id_address_delivery => $products_in_stock_list)
|
||||||
@@ -1188,7 +1189,7 @@ class CartCore extends ObjectModel
|
|||||||
'in_stock' => array(),
|
'in_stock' => array(),
|
||||||
'out_of_stock' => array(),
|
'out_of_stock' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($products_in_stock_list as $key => $warehouse_list)
|
foreach ($products_in_stock_list as $key => $warehouse_list)
|
||||||
{
|
{
|
||||||
if (!isset($grouped_by_carriers[$id_address_delivery][$key]))
|
if (!isset($grouped_by_carriers[$id_address_delivery][$key]))
|
||||||
@@ -1197,23 +1198,23 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse]))
|
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse]))
|
||||||
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse] = array();
|
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse] = array();
|
||||||
|
|
||||||
foreach ($product_list as $product)
|
foreach ($product_list as $product)
|
||||||
{
|
{
|
||||||
$package_carriers_key = implode(',', $product['carrier_list']);
|
$package_carriers_key = implode(',', $product['carrier_list']);
|
||||||
|
|
||||||
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]))
|
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]))
|
||||||
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key] = array(
|
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key] = array(
|
||||||
'product_list' => array(),
|
'product_list' => array(),
|
||||||
'carrier_list' => $product['carrier_list']
|
'carrier_list' => $product['carrier_list']
|
||||||
);
|
);
|
||||||
|
|
||||||
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]['product_list'][] = $product;
|
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]['product_list'][] = $product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$package_list = array();
|
$package_list = array();
|
||||||
// Step 4 : merge product from grouped_by_carriers into $package to minimize the number of package
|
// Step 4 : merge product from grouped_by_carriers into $package to minimize the number of package
|
||||||
foreach ($grouped_by_carriers as $id_address_delivery => $products_in_stock_list)
|
foreach ($grouped_by_carriers as $id_address_delivery => $products_in_stock_list)
|
||||||
@@ -1223,8 +1224,8 @@ class CartCore extends ObjectModel
|
|||||||
'in_stock' => array(),
|
'in_stock' => array(),
|
||||||
'out_of_stock' => array(),
|
'out_of_stock' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
foreach ($products_in_stock_list as $key => $warehouse_list)
|
foreach ($products_in_stock_list as $key => $warehouse_list)
|
||||||
{
|
{
|
||||||
if (!isset($package_list[$id_address_delivery][$key]))
|
if (!isset($package_list[$id_address_delivery][$key]))
|
||||||
@@ -1242,7 +1243,7 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
arsort($carrier_count);
|
arsort($carrier_count);
|
||||||
|
|
||||||
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
|
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
|
||||||
{
|
{
|
||||||
if (!isset($package_list[$id_address_delivery][$key][$id_warehouse]))
|
if (!isset($package_list[$id_address_delivery][$key][$id_warehouse]))
|
||||||
@@ -1269,14 +1270,14 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5 : Reduce deep of $package_list
|
// Step 5 : Reduce deep of $package_list
|
||||||
$final_package_list = array();
|
$final_package_list = array();
|
||||||
foreach ($package_list as $id_address_delivery => $products_in_stock_list)
|
foreach ($package_list as $id_address_delivery => $products_in_stock_list)
|
||||||
{
|
{
|
||||||
if (!isset($final_package_list[$id_address_delivery]))
|
if (!isset($final_package_list[$id_address_delivery]))
|
||||||
$final_package_list[$id_address_delivery] = array();
|
$final_package_list[$id_address_delivery] = array();
|
||||||
|
|
||||||
foreach ($products_in_stock_list as $key => $warehouse_list)
|
foreach ($products_in_stock_list as $key => $warehouse_list)
|
||||||
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
|
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
|
||||||
foreach ($products_grouped_by_carriers as $data)
|
foreach ($products_grouped_by_carriers as $data)
|
||||||
@@ -1288,11 +1289,11 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $final_package_list;
|
return $final_package_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all deliveries options available for the current cart
|
* Get all deliveries options available for the current cart
|
||||||
* @param Country $default_country
|
* @param Country $default_country
|
||||||
*
|
*
|
||||||
* @return array array(
|
* @return array array(
|
||||||
* 0 => array( // First address
|
* 0 => array( // First address
|
||||||
* 0 => array( // First delivery option available for this address
|
* 0 => array( // First delivery option available for this address
|
||||||
@@ -1326,7 +1327,7 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$delivery_option_list[$id_address] = array();
|
$delivery_option_list[$id_address] = array();
|
||||||
$carriers_price[$id_address] = array();
|
$carriers_price[$id_address] = array();
|
||||||
|
|
||||||
$common_carriers = array();
|
$common_carriers = array();
|
||||||
$best_price_carriers = array();
|
$best_price_carriers = array();
|
||||||
$best_grade_carriers = array();
|
$best_grade_carriers = array();
|
||||||
@@ -1335,10 +1336,10 @@ class CartCore extends ObjectModel
|
|||||||
// No carriers available
|
// No carriers available
|
||||||
if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0)
|
if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0)
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
$carriers_price[$id_address][$id_package] = array();
|
$carriers_price[$id_address][$id_package] = array();
|
||||||
$carriers_instance = array();
|
$carriers_instance = array();
|
||||||
|
|
||||||
if (empty($common_carriers))
|
if (empty($common_carriers))
|
||||||
$common_carriers = $package['carrier_list'];
|
$common_carriers = $package['carrier_list'];
|
||||||
else
|
else
|
||||||
@@ -1361,19 +1362,19 @@ class CartCore extends ObjectModel
|
|||||||
$carriers_price[$id_address][$id_package][$id_carrier] = array(
|
$carriers_price[$id_address][$id_package][$id_carrier] = array(
|
||||||
'without_tax' => $price_without_tax,
|
'without_tax' => $price_without_tax,
|
||||||
'with_tax' => $price_with_tax);
|
'with_tax' => $price_with_tax);
|
||||||
|
|
||||||
$grade = $carriers_instance[$id_carrier]->grade;
|
$grade = $carriers_instance[$id_carrier]->grade;
|
||||||
if (is_null($best_grade) || $grade > $best_grade)
|
if (is_null($best_grade) || $grade > $best_grade)
|
||||||
{
|
{
|
||||||
$best_grade = $grade;
|
$best_grade = $grade;
|
||||||
$best_grade_carrier = $id_carrier;
|
$best_grade_carrier = $id_carrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$best_price_carriers[$id_package] = $best_price_carrier;
|
$best_price_carriers[$id_package] = $best_price_carrier;
|
||||||
$best_grade_carriers[$id_package] = $best_grade_carrier;
|
$best_grade_carriers[$id_package] = $best_grade_carrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
$best_price_carrier = array();
|
$best_price_carrier = array();
|
||||||
$key = '';
|
$key = '';
|
||||||
foreach ($best_price_carriers as $id_package => $id_carrier)
|
foreach ($best_price_carriers as $id_package => $id_carrier)
|
||||||
@@ -1396,7 +1397,7 @@ class CartCore extends ObjectModel
|
|||||||
'is_best_grade' => false,
|
'is_best_grade' => false,
|
||||||
'unique_carrier' => false
|
'unique_carrier' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
$best_grade_carrier = array();
|
$best_grade_carrier = array();
|
||||||
$key = '';
|
$key = '';
|
||||||
foreach ($best_grade_carriers as $id_package => $id_carrier)
|
foreach ($best_grade_carriers as $id_package => $id_carrier)
|
||||||
@@ -1420,7 +1421,7 @@ class CartCore extends ObjectModel
|
|||||||
'unique_carrier' => false
|
'unique_carrier' => false
|
||||||
);
|
);
|
||||||
$delivery_option_list[$id_address][$key]['is_best_grade'] = true;
|
$delivery_option_list[$id_address][$key]['is_best_grade'] = true;
|
||||||
|
|
||||||
foreach ($common_carriers as $id_carrier)
|
foreach ($common_carriers as $id_carrier)
|
||||||
{
|
{
|
||||||
$price = 0;
|
$price = 0;
|
||||||
@@ -1463,11 +1464,11 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$total_price_with_tax += $data['price_with_tax'];
|
$total_price_with_tax += $data['price_with_tax'];
|
||||||
$total_price_without_tax += $data['price_without_tax'];
|
$total_price_without_tax += $data['price_without_tax'];
|
||||||
|
|
||||||
if (!isset($carrier_collection[$id_carrier]))
|
if (!isset($carrier_collection[$id_carrier]))
|
||||||
$carrier_collection[$id_carrier] = new Carrier($id_carrier);
|
$carrier_collection[$id_carrier] = new Carrier($id_carrier);
|
||||||
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance'] = $carrier_collection[$id_carrier];
|
$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'))
|
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';
|
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = _THEME_SHIP_DIR_.$id_carrier.'.jpg';
|
||||||
else
|
else
|
||||||
@@ -1479,7 +1480,7 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $delivery_option_list;
|
return $delivery_option_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the cart use multiple
|
* Does the cart use multiple
|
||||||
*/
|
*/
|
||||||
@@ -1507,7 +1508,7 @@ class CartCore extends ObjectModel
|
|||||||
$collection[$row['id_address_delivery']] = new Address($row['id_address_delivery']);
|
$collection[$row['id_address_delivery']] = new Address($row['id_address_delivery']);
|
||||||
return $collection;
|
return $collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the delivery option and id_carrier, if there is only one carrier
|
* Set the delivery option and id_carrier, if there is only one carrier
|
||||||
*/
|
*/
|
||||||
@@ -1569,7 +1570,7 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (is_null($delivery_option))
|
if (is_null($delivery_option))
|
||||||
$delivery_option = $this->getDeliveryOption($default_country);
|
$delivery_option = $this->getDeliveryOption($default_country);
|
||||||
|
|
||||||
$total_shipping = 0;
|
$total_shipping = 0;
|
||||||
$delivery_option_list = $this->getDeliveryOptionList();
|
$delivery_option_list = $this->getDeliveryOptionList();
|
||||||
foreach ($delivery_option as $id_address => $key)
|
foreach ($delivery_option as $id_address => $key)
|
||||||
@@ -1595,14 +1596,14 @@ class CartCore extends ObjectModel
|
|||||||
* @param Array $product_list
|
* @param Array $product_list
|
||||||
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
|
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
|
||||||
* @deprecated since 1.5.0
|
* @deprecated since 1.5.0
|
||||||
*
|
*
|
||||||
* @return float Shipping total
|
* @return float Shipping total
|
||||||
*/
|
*/
|
||||||
public function getOrderShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
|
public function getOrderShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
|
||||||
{
|
{
|
||||||
return $this->getPackageShippingCost($id_carrier, $useTax, $default_country, $product_list);
|
return $this->getPackageShippingCost($id_carrier, $useTax, $default_country, $product_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return package shipping cost
|
* Return package shipping cost
|
||||||
*
|
*
|
||||||
@@ -1611,7 +1612,7 @@ class CartCore extends ObjectModel
|
|||||||
* @param Country $default_country
|
* @param Country $default_country
|
||||||
* @param Array $product_list
|
* @param Array $product_list
|
||||||
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
|
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
|
||||||
*
|
*
|
||||||
* @return float Shipping total
|
* @return float Shipping total
|
||||||
*/
|
*/
|
||||||
public function getPackageShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
|
public function getPackageShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
|
||||||
@@ -1627,7 +1628,7 @@ class CartCore extends ObjectModel
|
|||||||
$products = $complete_product_list;
|
$products = $complete_product_list;
|
||||||
else
|
else
|
||||||
$products = $product_list;
|
$products = $product_list;
|
||||||
|
|
||||||
// Checking discounts in cart
|
// Checking discounts in cart
|
||||||
// if (Discount::isFeatureActive())
|
// if (Discount::isFeatureActive())
|
||||||
// $discounts = $this->getDiscounts(true);
|
// $discounts = $this->getDiscounts(true);
|
||||||
@@ -1864,7 +1865,7 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $total_weight;
|
return $total_weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(self::$_totalWeight[$this->id]))
|
if (!isset(self::$_totalWeight[$this->id]))
|
||||||
{
|
{
|
||||||
if (Combination::isFeatureActive())
|
if (Combination::isFeatureActive())
|
||||||
@@ -2192,16 +2193,16 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setProductAddressDelivery($id_product, $id_product_attribute, $old_id_address_delivery, $new_id_address_delivery)
|
public function setProductAddressDelivery($id_product, $id_product_attribute, $old_id_address_delivery, $new_id_address_delivery)
|
||||||
{
|
{
|
||||||
// Check address is linked with the customer
|
// Check address is linked with the customer
|
||||||
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
|
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ($new_id_address_delivery == $old_id_address_delivery)
|
if ($new_id_address_delivery == $old_id_address_delivery)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Checking if the product with the old address delivery exists
|
// Checking if the product with the old address delivery exists
|
||||||
$sql = new DbQuery();
|
$sql = new DbQuery();
|
||||||
$sql->select('count(*)');
|
$sql->select('count(*)');
|
||||||
@@ -2213,7 +2214,7 @@ class CartCore extends ObjectModel
|
|||||||
$result = Db::getInstance()->getValue($sql);
|
$result = Db::getInstance()->getValue($sql);
|
||||||
if ($result == 0)
|
if ($result == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Checking if there is no others similar products with this new address delivery
|
// Checking if there is no others similar products with this new address delivery
|
||||||
$sql = new DbQuery();
|
$sql = new DbQuery();
|
||||||
$sql->select('sum(quantity) as qty');
|
$sql->select('sum(quantity) as qty');
|
||||||
@@ -2223,7 +2224,7 @@ class CartCore extends ObjectModel
|
|||||||
$sql->where('id_address_delivery = '.(int)$new_id_address_delivery);
|
$sql->where('id_address_delivery = '.(int)$new_id_address_delivery);
|
||||||
$sql->where('id_cart = '.(int)$this->id);
|
$sql->where('id_cart = '.(int)$this->id);
|
||||||
$result = Db::getInstance()->getValue($sql);
|
$result = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
// Removing similar products with this new address delivery
|
// Removing similar products with this new address delivery
|
||||||
$sql = 'DELETE FROM '._DB_PREFIX_.'cart_product
|
$sql = 'DELETE FROM '._DB_PREFIX_.'cart_product
|
||||||
WHERE id_product = '.(int)$id_product.'
|
WHERE id_product = '.(int)$id_product.'
|
||||||
@@ -2232,7 +2233,7 @@ class CartCore extends ObjectModel
|
|||||||
AND id_cart = '.(int)$this->id.'
|
AND id_cart = '.(int)$this->id.'
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
// Changing the address
|
// Changing the address
|
||||||
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
|
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
|
||||||
SET `id_address_delivery` = '.(int)$new_id_address_delivery.',
|
SET `id_address_delivery` = '.(int)$new_id_address_delivery.',
|
||||||
@@ -2243,7 +2244,7 @@ class CartCore extends ObjectModel
|
|||||||
AND id_cart = '.(int)$this->id.'
|
AND id_cart = '.(int)$this->id.'
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
// Changing the address of the customizations
|
// Changing the address of the customizations
|
||||||
$sql = 'UPDATE '._DB_PREFIX_.'customization
|
$sql = 'UPDATE '._DB_PREFIX_.'customization
|
||||||
SET `id_address_delivery` = '.(int)$new_id_address_delivery.'
|
SET `id_address_delivery` = '.(int)$new_id_address_delivery.'
|
||||||
@@ -2252,16 +2253,16 @@ class CartCore extends ObjectModel
|
|||||||
AND id_address_delivery = '.(int)$old_id_address_delivery.'
|
AND id_address_delivery = '.(int)$old_id_address_delivery.'
|
||||||
AND id_cart = '.(int)$this->id;
|
AND id_cart = '.(int)$this->id;
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function duplicateProduct($id_product, $id_product_attribute, $id_address_delivery, $new_id_address_delivery, $quantity = 1, $keep_quantity = false)
|
public function duplicateProduct($id_product, $id_product_attribute, $id_address_delivery, $new_id_address_delivery, $quantity = 1, $keep_quantity = false)
|
||||||
{
|
{
|
||||||
// Check address is linked with the customer
|
// Check address is linked with the customer
|
||||||
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
|
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Checking the product do not exist with the new address
|
// Checking the product do not exist with the new address
|
||||||
$sql = new DbQuery();
|
$sql = new DbQuery();
|
||||||
$sql->select('count(*)');
|
$sql->select('count(*)');
|
||||||
@@ -2273,7 +2274,7 @@ class CartCore extends ObjectModel
|
|||||||
$result = Db::getInstance()->getValue($sql);
|
$result = Db::getInstance()->getValue($sql);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Duplicating cart_product line
|
// Duplicating cart_product line
|
||||||
$sql = 'INSERT INTO '._DB_PREFIX_.'cart_product
|
$sql = 'INSERT INTO '._DB_PREFIX_.'cart_product
|
||||||
(`id_cart`, `id_product`, `id_shop`, `id_product_attribute`, `quantity`, `date_add`, `id_address_delivery`)
|
(`id_cart`, `id_product`, `id_shop`, `id_product_attribute`, `quantity`, `date_add`, `id_address_delivery`)
|
||||||
@@ -2286,7 +2287,7 @@ class CartCore extends ObjectModel
|
|||||||
NOW(),
|
NOW(),
|
||||||
'.(int)$new_id_address_delivery.')';
|
'.(int)$new_id_address_delivery.')';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
if (!$keep_quantity)
|
if (!$keep_quantity)
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
|
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
|
||||||
@@ -2298,7 +2299,7 @@ class CartCore extends ObjectModel
|
|||||||
AND id_address_delivery = '.(int)$id_address_delivery;
|
AND id_address_delivery = '.(int)$id_address_delivery;
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking if there is customizations
|
// Checking if there is customizations
|
||||||
$sql = new DbQuery();
|
$sql = new DbQuery();
|
||||||
$sql->select('*');
|
$sql->select('*');
|
||||||
@@ -2311,7 +2312,7 @@ class CartCore extends ObjectModel
|
|||||||
|
|
||||||
foreach ($results as $customization)
|
foreach ($results as $customization)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Duplicate customization
|
// Duplicate customization
|
||||||
$sql = 'INSERT INTO '._DB_PREFIX_.'customization(`id_product_attribute`, `id_address_delivery`, `id_cart`, `id_product`, `quantity`, `in_cart`)
|
$sql = 'INSERT INTO '._DB_PREFIX_.'customization(`id_product_attribute`, `id_address_delivery`, `id_cart`, `id_product`, `quantity`, `in_cart`)
|
||||||
VALUES (
|
VALUES (
|
||||||
@@ -2322,12 +2323,12 @@ class CartCore extends ObjectModel
|
|||||||
'.$quantity.',
|
'.$quantity.',
|
||||||
'.$customization['in_cart'].')';
|
'.$customization['in_cart'].')';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
$sql = 'INSERT INTO '._DB_PREFIX_.'customized_data(`id_customization`, `type`, `index`, `value`)
|
$sql = 'INSERT INTO '._DB_PREFIX_.'customized_data(`id_customization`, `type`, `index`, `value`)
|
||||||
(SELECT '.(int)Db::getInstance()->Insert_ID().' `id_customization`, `type`, `index`, `value` FROM customized_data WHERE id_customization = '.$customization['id_customization'].')';
|
(SELECT '.(int)Db::getInstance()->Insert_ID().' `id_customization`, `type`, `index`, `value` FROM customized_data WHERE id_customization = '.$customization['id_customization'].')';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$customization_count = count($results);
|
$customization_count = count($results);
|
||||||
if ($customization_count > 0)
|
if ($customization_count > 0)
|
||||||
{
|
{
|
||||||
@@ -2342,7 +2343,7 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update products cart address delivery with the address delivery of the cart
|
* Update products cart address delivery with the address delivery of the cart
|
||||||
*/
|
*/
|
||||||
@@ -2365,7 +2366,7 @@ class CartCore extends ObjectModel
|
|||||||
AND id_product_attribute = '.$product['id_product_attribute'];
|
AND id_product_attribute = '.$product['id_product_attribute'];
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merging multiple lines
|
// Merging multiple lines
|
||||||
$sql = 'DELETE cp1
|
$sql = 'DELETE cp1
|
||||||
FROM `'._DB_PREFIX_.'cart_product` cp1
|
FROM `'._DB_PREFIX_.'cart_product` cp1
|
||||||
@@ -2378,8 +2379,8 @@ class CartCore extends ObjectModel
|
|||||||
AND (cp1.date_add > cp2.date_add)
|
AND (cp1.date_add > cp2.date_add)
|
||||||
)';
|
)';
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
|
|
||||||
|
|
||||||
// upgradng address delivery
|
// upgradng address delivery
|
||||||
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
||||||
SET `id_address_delivery` =
|
SET `id_address_delivery` =
|
||||||
@@ -2402,7 +2403,7 @@ class CartCore extends ObjectModel
|
|||||||
WHERE `id_cart` = '.(int)$this->id;
|
WHERE `id_cart` = '.(int)$this->id;
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an address to all products on the cart without address delivery
|
* Set an address to all products on the cart without address delivery
|
||||||
*/
|
*/
|
||||||
@@ -2415,17 +2416,17 @@ class CartCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if ((int)$cart->id_customer == 0)
|
if ((int)$cart->id_customer == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$customer = new Customer((int)$cart->id_customer);
|
$customer = new Customer((int)$cart->id_customer);
|
||||||
$addresses = $customer->getAddresses(Context::getContext()->language->id);
|
$addresses = $customer->getAddresses(Context::getContext()->language->id);
|
||||||
|
|
||||||
if (count($addresses) == 0)
|
if (count($addresses) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$id_address_delivery = $addresses[0]['id_address'];
|
$id_address_delivery = $addresses[0]['id_address'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
||||||
SET `id_address_delivery` =
|
SET `id_address_delivery` =
|
||||||
(
|
(
|
||||||
|
|||||||
+44
-43
@@ -59,7 +59,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
|
|
||||||
protected $table = 'cart_rule';
|
protected $table = 'cart_rule';
|
||||||
protected $identifier = 'id_cart_rule';
|
protected $identifier = 'id_cart_rule';
|
||||||
|
|
||||||
protected $fieldsRequired = array('date_from', 'date_to');
|
protected $fieldsRequired = array('date_from', 'date_to');
|
||||||
protected $fieldsSize = array('code' => 254, 'description' => 65534);
|
protected $fieldsSize = array('code' => 254, 'description' => 65534);
|
||||||
protected $fieldsValidate = array(
|
protected $fieldsValidate = array(
|
||||||
@@ -134,16 +134,16 @@ class CartRuleCore extends ObjectModel
|
|||||||
return false;
|
return false;
|
||||||
return $this->getTranslationsFields(array('name'));
|
return $this->getTranslationsFields(array('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $nullValues = false)
|
||||||
{
|
{
|
||||||
if (!parent::add($autodate, $nullValues))
|
if (!parent::add($autodate, $nullValues))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', '1');
|
Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', '1');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (!parent::delete())
|
if (!parent::delete())
|
||||||
@@ -158,7 +158,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule` WHERE `id_cart_rule` = '.(int)$this->id);
|
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
|
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination)
|
public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination)
|
||||||
{
|
{
|
||||||
Db::getInstance()->Execute('
|
Db::getInstance()->Execute('
|
||||||
@@ -186,7 +186,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
return false;
|
return false;
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_cart_rule` FROM `'._DB_PREFIX_.'cart_rule` WHERE `code` = \''.pSQL($code).'\'');
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_cart_rule` FROM `'._DB_PREFIX_.'cart_rule` WHERE `code` = \''.pSQL($code).'\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null)
|
public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null)
|
||||||
{
|
{
|
||||||
if (!CartRule::isFeatureActive())
|
if (!CartRule::isFeatureActive())
|
||||||
@@ -219,7 +219,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function usedByCustomer($id_customer)
|
public function usedByCustomer($id_customer)
|
||||||
{
|
{
|
||||||
return (bool)Db::getInstance()->getValue('
|
return (bool)Db::getInstance()->getValue('
|
||||||
@@ -229,7 +229,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
WHERE ocr.`id_cart_rule` = '.(int)$this->id.'
|
WHERE ocr.`id_cart_rule` = '.(int)$this->id.'
|
||||||
AND o.`id_customer` = '.(int)$id_customer);
|
AND o.`id_customer` = '.(int)$id_customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cartRuleExists($name)
|
public static function cartRuleExists($name)
|
||||||
{
|
{
|
||||||
if (!CartRule::isFeatureActive())
|
if (!CartRule::isFeatureActive())
|
||||||
@@ -240,7 +240,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
FROM `'._DB_PREFIX_.'cart_rule`
|
FROM `'._DB_PREFIX_.'cart_rule`
|
||||||
WHERE `code` = \''.pSQL($name).'\'');
|
WHERE `code` = \''.pSQL($name).'\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteByIdCustomer($id_customer)
|
public static function deleteByIdCustomer($id_customer)
|
||||||
{
|
{
|
||||||
$return = true;
|
$return = true;
|
||||||
@@ -255,7 +255,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (!Validate::isLoadedObject($this) OR $this->product_restriction == 0)
|
if (!Validate::isLoadedObject($this) OR $this->product_restriction == 0)
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
$productRules = array();
|
$productRules = array();
|
||||||
$result = Db::getInstance()->ExecuteS('
|
$result = Db::getInstance()->ExecuteS('
|
||||||
SELECT *
|
SELECT *
|
||||||
@@ -270,13 +270,13 @@ class CartRuleCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $productRules;
|
return $productRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo : Add shop management
|
// Todo : Add shop management
|
||||||
public function checkValidity(Context $context, $alreadyInCart = false)
|
public function checkValidity(Context $context, $alreadyInCart = false)
|
||||||
{
|
{
|
||||||
if (!CartRule::isFeatureActive())
|
if (!CartRule::isFeatureActive())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!$this->active)
|
if (!$this->active)
|
||||||
return Tools::displayError('This voucher is disabled');
|
return Tools::displayError('This voucher is disabled');
|
||||||
if (!$this->quantity)
|
if (!$this->quantity)
|
||||||
@@ -285,7 +285,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
return Tools::displayError('This voucher is not valid yet');
|
return Tools::displayError('This voucher is not valid yet');
|
||||||
if (strtotime($this->date_to) < time())
|
if (strtotime($this->date_to) < time())
|
||||||
return Tools::displayError('This voucher has expired');
|
return Tools::displayError('This voucher has expired');
|
||||||
|
|
||||||
if ($context->cart->id_customer)
|
if ($context->cart->id_customer)
|
||||||
{
|
{
|
||||||
$quantityUsed = Db::getInstance()->getValue('
|
$quantityUsed = Db::getInstance()->getValue('
|
||||||
@@ -304,7 +304,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
if ($quantityUsed + 1 > $this->quantity_per_user)
|
if ($quantityUsed + 1 > $this->quantity_per_user)
|
||||||
return Tools::displayError('You cannot use this voucher anymore (usage limit reached)');
|
return Tools::displayError('You cannot use this voucher anymore (usage limit reached)');
|
||||||
}
|
}
|
||||||
|
|
||||||
$otherCartRules = $context->cart->getCartRules();
|
$otherCartRules = $context->cart->getCartRules();
|
||||||
if (count($otherCartRules))
|
if (count($otherCartRules))
|
||||||
foreach ($otherCartRules as $otherCartRule)
|
foreach ($otherCartRules as $otherCartRule)
|
||||||
@@ -325,7 +325,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get an intersection of the customer groups and the cart rule groups (if the customer is not logged in, the default group is 1)
|
// Get an intersection of the customer groups and the cart rule groups (if the customer is not logged in, the default group is 1)
|
||||||
if ($this->group_restriction)
|
if ($this->group_restriction)
|
||||||
{
|
{
|
||||||
@@ -337,7 +337,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
if (!$id_cart_rule)
|
if (!$id_cart_rule)
|
||||||
return Tools::displayError('You cannot use this voucher');
|
return Tools::displayError('You cannot use this voucher');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the customer delivery address is usable with the cart rule
|
// Check if the customer delivery address is usable with the cart rule
|
||||||
if ($this->country_restriction AND $context->cart->id_address_delivery)
|
if ($this->country_restriction AND $context->cart->id_address_delivery)
|
||||||
{
|
{
|
||||||
@@ -349,7 +349,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
if (!$id_cart_rule)
|
if (!$id_cart_rule)
|
||||||
return Tools::displayError('You cannot use this voucher in your country of delivery');
|
return Tools::displayError('You cannot use this voucher in your country of delivery');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the carrier chosen by the customer is usable with the cart rule
|
// Check if the carrier chosen by the customer is usable with the cart rule
|
||||||
if ($this->carrier_restriction AND $context->cart->id_carrier)
|
if ($this->carrier_restriction AND $context->cart->id_carrier)
|
||||||
{
|
{
|
||||||
@@ -361,7 +361,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
if (!$id_cart_rule)
|
if (!$id_cart_rule)
|
||||||
return Tools::displayError('You cannot use this voucher with this carrier');
|
return Tools::displayError('You cannot use this voucher with this carrier');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the products chosen by the customer are usable with the cart rule
|
// Check if the products chosen by the customer are usable with the cart rule
|
||||||
if ($this->product_restriction)
|
if ($this->product_restriction)
|
||||||
{
|
{
|
||||||
@@ -420,13 +420,14 @@ class CartRuleCore extends ObjectModel
|
|||||||
return Tools::displayError('You cannot use this voucher').' - '.Tools::displayError('Please log in');
|
return Tools::displayError('You cannot use this voucher').' - '.Tools::displayError('Please log in');
|
||||||
return Tools::displayError('You cannot use this voucher');
|
return Tools::displayError('You cannot use this voucher');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->minimum_amount)
|
if ($this->minimum_amount)
|
||||||
{
|
{
|
||||||
$minimum_amount = $this->minimum_amount;
|
$minimum_amount = $this->minimum_amount;
|
||||||
if ($this->minimum_amount_currency != Configuration::get('PS_CURRENCY_DEFAULT'))
|
if ($this->minimum_amount_currency != Configuration::get('PS_CURRENCY_DEFAULT'))
|
||||||
{
|
{
|
||||||
$minimumAmountCurrency = new Currency($this->minimum_amount);
|
$minimumAmountCurrency = new Currency($this->minimum_amount_currency);
|
||||||
|
//p($this->minimum_amount_currency);
|
||||||
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate;
|
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate;
|
||||||
}
|
}
|
||||||
$cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS);
|
$cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS);
|
||||||
@@ -436,7 +437,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
return Tools::displayError('You do not reach the minimum amount required to use this voucher');
|
return Tools::displayError('You do not reach the minimum amount required to use this voucher');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The reduction value is POSITIVE
|
// The reduction value is POSITIVE
|
||||||
public function getContextualValue($useTax, Context $context = NULL)
|
public function getContextualValue($useTax, Context $context = NULL)
|
||||||
{
|
{
|
||||||
@@ -444,9 +445,9 @@ class CartRuleCore extends ObjectModel
|
|||||||
return 0;
|
return 0;
|
||||||
if (!$context)
|
if (!$context)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
|
|
||||||
$reductionValue = 0;
|
$reductionValue = 0;
|
||||||
|
|
||||||
// Free shipping on selected carriers
|
// Free shipping on selected carriers
|
||||||
if ($this->free_shipping)
|
if ($this->free_shipping)
|
||||||
{
|
{
|
||||||
@@ -463,13 +464,13 @@ class CartRuleCore extends ObjectModel
|
|||||||
$reductionValue += $context->cart->getOrderShippingCost($context->cart->id_carrier, $useTax, $context->country);
|
$reductionValue += $context->cart->getOrderShippingCost($context->cart->id_carrier, $useTax, $context->country);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discount (%) on the whole order
|
// Discount (%) on the whole order
|
||||||
if ($this->reduction_percent AND $this->reduction_product == 0)
|
if ($this->reduction_percent AND $this->reduction_product == 0)
|
||||||
{
|
{
|
||||||
$reductionValue += $context->cart->getOrderTotal($useTax, Cart::ONLY_PRODUCTS) * $this->reduction_percent / 100;
|
$reductionValue += $context->cart->getOrderTotal($useTax, Cart::ONLY_PRODUCTS) * $this->reduction_percent / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discount (%) on a specific product
|
// Discount (%) on a specific product
|
||||||
if ($this->reduction_percent AND $this->reduction_product > 0)
|
if ($this->reduction_percent AND $this->reduction_product > 0)
|
||||||
{
|
{
|
||||||
@@ -477,7 +478,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
if ($product['id_product'] == $this->reduction_product)
|
if ($product['id_product'] == $this->reduction_product)
|
||||||
$reductionValue += ($useTax ? $product['total_wt'] : $product['total']) * $this->reduction_percent / 100;
|
$reductionValue += ($useTax ? $product['total_wt'] : $product['total']) * $this->reduction_percent / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discount (%) on the cheapest product
|
// Discount (%) on the cheapest product
|
||||||
if ($this->reduction_percent AND $this->reduction_product == -1)
|
if ($this->reduction_percent AND $this->reduction_product == -1)
|
||||||
{
|
{
|
||||||
@@ -490,7 +491,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
$reductionValue += $minPrice * $this->reduction_percent / 100;
|
$reductionValue += $minPrice * $this->reduction_percent / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discount (¤)
|
// Discount (¤)
|
||||||
if ($this->reduction_amount)
|
if ($this->reduction_amount)
|
||||||
{
|
{
|
||||||
@@ -503,10 +504,10 @@ class CartRuleCore extends ObjectModel
|
|||||||
$reduction_amount /= $voucherCurrency->conversion_rate;
|
$reduction_amount /= $voucherCurrency->conversion_rate;
|
||||||
// Then we convert the voucher value in the default currency into the cart currency
|
// Then we convert the voucher value in the default currency into the cart currency
|
||||||
$reduction_amount *= $context->currency->conversion_rate;
|
$reduction_amount *= $context->currency->conversion_rate;
|
||||||
|
|
||||||
$reduction_amount = Tools::ps_round($reduction_amount);
|
$reduction_amount = Tools::ps_round($reduction_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it has the same tax application that you need, then it's the right value, whatever the product!
|
// If it has the same tax application that you need, then it's the right value, whatever the product!
|
||||||
if ($this->reduction_tax == $useTax)
|
if ($this->reduction_tax == $useTax)
|
||||||
$reductionValue += $reduction_amount;
|
$reductionValue += $reduction_amount;
|
||||||
@@ -543,7 +544,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
// Todo: discount on the cheapest (but this is not meaningful)
|
// Todo: discount on the cheapest (but this is not meaningful)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free gift
|
// Free gift
|
||||||
if ($this->gift_product)
|
if ($this->gift_product)
|
||||||
{
|
{
|
||||||
@@ -551,10 +552,10 @@ class CartRuleCore extends ObjectModel
|
|||||||
if ($product['id_product'] == $this->gift_product)
|
if ($product['id_product'] == $this->gift_product)
|
||||||
$reductionValue += ($useTax ? $product['price_wt'] : $product['price']);
|
$reductionValue += ($useTax ? $product['price_wt'] : $product['price']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $reductionValue;
|
return $reductionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCartRuleCombinations()
|
protected function getCartRuleCombinations()
|
||||||
{
|
{
|
||||||
$array = array();
|
$array = array();
|
||||||
@@ -586,14 +587,14 @@ class CartRuleCore extends ObjectModel
|
|||||||
)');
|
)');
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAssociatedRestrictions($type, $active = 1)
|
public function getAssociatedRestrictions($type, $active = 1)
|
||||||
{
|
{
|
||||||
$array = array('selected' => array(), 'unselected' => array());
|
$array = array('selected' => array(), 'unselected' => array());
|
||||||
|
|
||||||
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule')))
|
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule')))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0)
|
if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0)
|
||||||
{
|
{
|
||||||
$array['selected'] = Db::getInstance()->ExecuteS('
|
$array['selected'] = Db::getInstance()->ExecuteS('
|
||||||
@@ -625,12 +626,12 @@ class CartRuleCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function autoRemoveFromCart($context = NULL)
|
public static function autoRemoveFromCart($context = NULL)
|
||||||
{
|
{
|
||||||
if (!CartRule::isFeatureActive())
|
if (!CartRule::isFeatureActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
if (!$context)
|
if (!$context)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
@@ -647,14 +648,14 @@ class CartRuleCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function autoAddToCart($context = NULL)
|
public static function autoAddToCart($context = NULL)
|
||||||
{
|
{
|
||||||
if ($context === NULL)
|
if ($context === NULL)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
if (!CartRule::isFeatureActive() || !Validate::isLoadedObject($context->cart))
|
if (!CartRule::isFeatureActive() || !Validate::isLoadedObject($context->cart))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$result = Db::getInstance()->ExecuteS('
|
$result = Db::getInstance()->ExecuteS('
|
||||||
SELECT cr.*
|
SELECT cr.*
|
||||||
FROM '._DB_PREFIX_.'cart_rule cr
|
FROM '._DB_PREFIX_.'cart_rule cr
|
||||||
@@ -667,7 +668,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
AND cr.date_to > "'.date('Y-m-d H:i:s').'"
|
AND cr.date_to > "'.date('Y-m-d H:i:s').'"
|
||||||
AND cr.id_cart_rule NOT IN (SELECT id_cart_rule FROM '._DB_PREFIX_.'cart_cart_rule WHERE id_cart = '.(int)$context->cart->id.')
|
AND cr.id_cart_rule NOT IN (SELECT id_cart_rule FROM '._DB_PREFIX_.'cart_cart_rule WHERE id_cart = '.(int)$context->cart->id.')
|
||||||
AND (
|
AND (
|
||||||
cr.id_customer = 0
|
cr.id_customer = 0
|
||||||
'.($context->customer->id ? 'OR cr.id_customer = '.(int)$context->cart->id_customer : '').'
|
'.($context->customer->id ? 'OR cr.id_customer = '.(int)$context->cart->id_customer : '').'
|
||||||
)
|
)
|
||||||
AND (
|
AND (
|
||||||
@@ -693,15 +694,15 @@ class CartRuleCore extends ObjectModel
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
ORDER BY priority');
|
ORDER BY priority');
|
||||||
|
|
||||||
$cartRules = ObjectModel::hydrateCollection('CartRule', $result);
|
$cartRules = ObjectModel::hydrateCollection('CartRule', $result);
|
||||||
|
|
||||||
// Todo: consider optimization (we can avoid many queries in checkValidity)
|
// Todo: consider optimization (we can avoid many queries in checkValidity)
|
||||||
foreach ($cartRules as $cartRule)
|
foreach ($cartRules as $cartRule)
|
||||||
if (!$cartRule->checkValidity($context))
|
if (!$cartRule->checkValidity($context))
|
||||||
$context->cart->addCartRule($cartRule->id);
|
$context->cart->addCartRule($cartRule->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isFeatureActive()
|
public static function isFeatureActive()
|
||||||
{
|
{
|
||||||
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
|
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
|
||||||
|
|||||||
@@ -73,15 +73,15 @@ class CurrencyCore extends ObjectModel
|
|||||||
protected $webserviceParameters = array(
|
protected $webserviceParameters = array(
|
||||||
'objectsNodeName' => 'currencies',
|
'objectsNodeName' => 'currencies',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* contains the sign to display before price, according to its format
|
* contains the sign to display before price, according to its format
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $prefix = null;
|
public $prefix = null;
|
||||||
/**
|
/**
|
||||||
* contains the sign to display after price, according to its format
|
* contains the sign to display after price, according to its format
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $suffix = null;
|
public $suffix = null;
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
*
|
*
|
||||||
* @return array Currencies
|
* @return array Currencies
|
||||||
*/
|
*/
|
||||||
static public function getCurrencies($object = false, $active = 1, Shop $shop = null)
|
public static function getCurrencies($object = false, $active = 1, Shop $shop = null)
|
||||||
{
|
{
|
||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = new Shop(Context::getContext()->shop->getID(true));
|
$shop = new Shop(Context::getContext()->shop->getID(true));
|
||||||
@@ -216,7 +216,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
return $tab;
|
return $tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
|
public static function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
|
||||||
{
|
{
|
||||||
if (is_null($id_shop))
|
if (is_null($id_shop))
|
||||||
$id_shop = Context::getContext()->shop->getID();
|
$id_shop = Context::getContext()->shop->getID();
|
||||||
@@ -228,7 +228,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
return Db::getInstance()->getRow($sql);
|
return Db::getInstance()->getRow($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getPaymentCurrencies($id_module, $id_shop = null)
|
public static function getPaymentCurrencies($id_module, $id_shop = null)
|
||||||
{
|
{
|
||||||
if (is_null($id_shop))
|
if (is_null($id_shop))
|
||||||
$id_shop = Context::getContext()->shop->getID();
|
$id_shop = Context::getContext()->shop->getID();
|
||||||
@@ -244,7 +244,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
return Db::getInstance()->executeS($sql);
|
return Db::getInstance()->executeS($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function checkPaymentCurrencies($id_module, $id_shop = null)
|
public static function checkPaymentCurrencies($id_module, $id_shop = null)
|
||||||
{
|
{
|
||||||
if (is_null($id_shop))
|
if (is_null($id_shop))
|
||||||
$id_shop = Context::getContext()->shop->getID(true);
|
$id_shop = Context::getContext()->shop->getID(true);
|
||||||
@@ -275,7 +275,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
return $result['id_currency'];
|
return $result['id_currency'];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getIdByIsoCodeNum($iso_code)
|
public static function getIdByIsoCodeNum($iso_code)
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT `id_currency`
|
SELECT `id_currency`
|
||||||
@@ -357,7 +357,7 @@ class CurrencyCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current currency
|
* Get current currency
|
||||||
*
|
*
|
||||||
* @deprecated as of 1.5 use $context->currency instead
|
* @deprecated as of 1.5 use $context->currency instead
|
||||||
* @return Currency
|
* @return Currency
|
||||||
*/
|
*/
|
||||||
|
|||||||
+13
-9
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* 2007-2011 PrestaShop
|
* 2007-2011 PrestaShop
|
||||||
*
|
*
|
||||||
* NOTICE OF LICENSE
|
* NOTICE OF LICENSE
|
||||||
*
|
*
|
||||||
@@ -25,6 +25,12 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @deprecated 1.5.0.1
|
||||||
|
* @see OrderPaymentCore
|
||||||
|
*
|
||||||
|
*/
|
||||||
class PaymentCCCore extends ObjectModel
|
class PaymentCCCore extends ObjectModel
|
||||||
{
|
{
|
||||||
public $id_order;
|
public $id_order;
|
||||||
@@ -60,7 +66,7 @@ class PaymentCCCore extends ObjectModel
|
|||||||
$fields['date_add'] = pSQL($this->date_add);
|
$fields['date_add'] = pSQL($this->date_add);
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $nullValues = false)
|
||||||
{
|
{
|
||||||
if (parent::add($autodate, $nullValues))
|
if (parent::add($autodate, $nullValues))
|
||||||
@@ -70,20 +76,18 @@ class PaymentCCCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the detailed payment of an order
|
* Get the detailed payment of an order
|
||||||
* @param int $id_order
|
* @param int $id_order
|
||||||
* @return array
|
* @return array
|
||||||
|
* @deprecated 1.5.0.1
|
||||||
|
* @see OrderPaymentCore
|
||||||
*/
|
*/
|
||||||
public static function getByOrderId($id_order)
|
public static function getByOrderId($id_order)
|
||||||
{
|
{
|
||||||
$query = '
|
Tools::displayAsDeprecated();
|
||||||
SELECT *
|
return null;
|
||||||
FROM `'._DB_PREFIX_.'payment_cc`
|
|
||||||
WHERE `id_order` = '.$id_order;
|
|
||||||
|
|
||||||
return Db::getInstance()->getRow($query);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+50
-71
@@ -32,9 +32,6 @@ abstract class PaymentModuleCore extends Module
|
|||||||
public $currencies = true;
|
public $currencies = true;
|
||||||
public $currencies_mode = 'checkbox';
|
public $currencies_mode = 'checkbox';
|
||||||
|
|
||||||
/* @var object PaymentCC */
|
|
||||||
public $pcc = null;
|
|
||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
if (!parent::install())
|
if (!parent::install())
|
||||||
@@ -78,18 +75,6 @@ abstract class PaymentModuleCore extends Module
|
|||||||
return false;
|
return false;
|
||||||
return parent::uninstall();
|
return parent::uninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pcc = new PaymentCC();
|
|
||||||
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
unset($this->pcc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate an order in database
|
* Validate an order in database
|
||||||
@@ -101,12 +86,12 @@ abstract class PaymentModuleCore extends Module
|
|||||||
* @param string $paymentMethod Payment method (eg. 'Credit card')
|
* @param string $paymentMethod Payment method (eg. 'Credit card')
|
||||||
* @param string $message Message to attach to order
|
* @param string $message Message to attach to order
|
||||||
*/
|
*/
|
||||||
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
|
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
|
||||||
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
|
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
|
||||||
$secure_key = false, Shop $shop = null)
|
$secure_key = false, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cart = new Cart((int)($id_cart));
|
$cart = new Cart((int)($id_cart));
|
||||||
|
|
||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
// Does order already exists ?
|
// Does order already exists ?
|
||||||
@@ -114,7 +99,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
{
|
{
|
||||||
if ($secure_key !== false AND $secure_key != $cart->secure_key)
|
if ($secure_key !== false AND $secure_key != $cart->secure_key)
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
|
|
||||||
// For each package, generate an order
|
// For each package, generate an order
|
||||||
$delivery_option_list = $cart->getDeliveryOptionList();
|
$delivery_option_list = $cart->getDeliveryOptionList();
|
||||||
$package_list = $cart->getPackageList();
|
$package_list = $cart->getPackageList();
|
||||||
@@ -128,27 +113,27 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$cart_delivery_option[$id_address] = $key;
|
$cart_delivery_option[$id_address] = $key;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$order_list = array();
|
$order_list = array();
|
||||||
$order_detail_list = array();
|
$order_detail_list = array();
|
||||||
$reference = Order::generateReference();
|
$reference = Order::generateReference();
|
||||||
$this->currentOrderReference = $reference;
|
$this->currentOrderReference = $reference;
|
||||||
|
|
||||||
$id_currency = $currency_special ? (int)($currency_special) : (int)($cart->id_currency);
|
$id_currency = $currency_special ? (int)($currency_special) : (int)($cart->id_currency);
|
||||||
$currency = new Currency($id_currency);
|
$currency = new Currency($id_currency);
|
||||||
|
|
||||||
$this->context->cart->order_reference = $reference;
|
$this->context->cart->order_reference = $reference;
|
||||||
|
|
||||||
$orderCreationFailed = false;
|
$orderCreationFailed = false;
|
||||||
$cart_total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
|
$cart_total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
|
||||||
|
|
||||||
if ($cart->orderExists())
|
if ($cart->orderExists())
|
||||||
{
|
{
|
||||||
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
|
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
|
||||||
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
|
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
|
||||||
die($errorMessage);
|
die($errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($cart_delivery_option as $id_address => $key_carriers)
|
foreach ($cart_delivery_option as $id_address => $key_carriers)
|
||||||
foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data)
|
foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data)
|
||||||
foreach ($data['package_list'] as $id_package)
|
foreach ($data['package_list'] as $id_package)
|
||||||
@@ -162,14 +147,13 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$order->id_address_delivery = (int)$id_address;
|
$order->id_address_delivery = (int)$id_address;
|
||||||
$order->id_currency = $id_currency;
|
$order->id_currency = $id_currency;
|
||||||
$order->id_lang = (int)($cart->id_lang);
|
$order->id_lang = (int)($cart->id_lang);
|
||||||
|
|
||||||
$order->id_warehouse = $package_list[$id_address][$id_package]['id_warehouse'];
|
$order->id_warehouse = $package_list[$id_address][$id_package]['id_warehouse'];
|
||||||
$order->id_cart = (int)($cart->id);
|
$order->id_cart = (int)($cart->id);
|
||||||
$order->reference = $reference;
|
$order->reference = $reference;
|
||||||
|
|
||||||
$order->id_shop = (int)($shop->getID() ? $shop->getID() : $cart->id_shop);
|
$order->id_shop = (int)($shop->getID() ? $shop->getID() : $cart->id_shop);
|
||||||
$order->id_group_shop = (int)($shop->getID() ? $shop->getGroupID() : $cart->id_group_shop);
|
$order->id_group_shop = (int)($shop->getID() ? $shop->getGroupID() : $cart->id_group_shop);
|
||||||
|
|
||||||
$customer = new Customer((int)($order->id_customer));
|
$customer = new Customer((int)($order->id_customer));
|
||||||
$order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key));
|
$order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key));
|
||||||
$order->payment = $paymentMethod;
|
$order->payment = $paymentMethod;
|
||||||
@@ -191,18 +175,18 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$order->total_shipping = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
|
$order->total_shipping = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
|
||||||
$order->total_shipping_tax_excl = (float)$cart->getPackageShippingCost((int)$id_carrier, false, null, $product_list, $id_carrier);
|
$order->total_shipping_tax_excl = (float)$cart->getPackageShippingCost((int)$id_carrier, false, null, $product_list, $id_carrier);
|
||||||
$order->total_shipping_tax_incl = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
|
$order->total_shipping_tax_incl = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
|
||||||
|
|
||||||
if (Validate::isLoadedObject($carrier))
|
if (Validate::isLoadedObject($carrier))
|
||||||
$order->carrier_tax_rate = $carrier->getTaxesRate(new Address($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$order->carrier_tax_rate = $carrier->getTaxesRate(new Address($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
|
|
||||||
$order->total_wrapping = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
$order->total_wrapping = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
||||||
$order->total_wrapping_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
$order->total_wrapping_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
||||||
$order->total_wrapping_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
$order->total_wrapping_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
||||||
|
|
||||||
$order->total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
$order->total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||||
$order->total_paid_tax_excl = (float)Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH, $product_list, $id_carrier)), 2);
|
$order->total_paid_tax_excl = (float)Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||||
$order->total_paid_tax_incl = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
$order->total_paid_tax_incl = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||||
|
|
||||||
$order->invoice_date = '0000-00-00 00:00:00';
|
$order->invoice_date = '0000-00-00 00:00:00';
|
||||||
$order->delivery_date = '0000-00-00 00:00:00';
|
$order->delivery_date = '0000-00-00 00:00:00';
|
||||||
// Amount paid by customer is not the right one -> Status = payment error
|
// Amount paid by customer is not the right one -> Status = payment error
|
||||||
@@ -211,18 +195,29 @@ abstract class PaymentModuleCore extends Module
|
|||||||
// We use number_format in order to compare two string
|
// We use number_format in order to compare two string
|
||||||
if (number_format($cart_total_paid, 2) != number_format($order->total_paid_real, 2))
|
if (number_format($cart_total_paid, 2) != number_format($order->total_paid_real, 2))
|
||||||
$id_order_state = Configuration::get('PS_OS_ERROR');
|
$id_order_state = Configuration::get('PS_OS_ERROR');
|
||||||
|
|
||||||
// Creating order
|
// Creating order
|
||||||
$result = $order->add();
|
$result = $order->add();
|
||||||
|
|
||||||
$order_list[] = $order;
|
$order_list[] = $order;
|
||||||
|
|
||||||
// Insert new Order detail list using cart for the current order
|
// Insert new Order detail list using cart for the current order
|
||||||
$order_detail = new OrderDetail(null, null, $this->context);
|
$order_detail = new OrderDetail(null, null, $this->context);
|
||||||
$order_detail->createList($order, $cart, $id_order_state, $product_list);
|
$order_detail->createList($order, $cart, $id_order_state, $product_list);
|
||||||
$order_detail_list[] = $order_detail;
|
$order_detail_list[] = $order_detail;
|
||||||
|
|
||||||
|
// Adding an entry in order_carrier table
|
||||||
|
Db::getInstance()->execute('
|
||||||
|
INSERT INTO `'._DB_PREFIX_.'order_carrier` (`id_order`, `id_carrier`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `date_add`) VALUES
|
||||||
|
('.(int)$order->id.', '.(int)$carrier->id.', '.(float)$order->getTotalWeight().', '.(float)$order->total_shipping_tax_excl.', '.(float)$order->total_shipping_tax_incl.', NOW())');
|
||||||
}
|
}
|
||||||
$this->addPCC($reference, $id_currency, $amountPaid);
|
// Register Payment
|
||||||
|
if (!$order->addOrderPayment($amountPaid))
|
||||||
|
{
|
||||||
|
$errorMessage = Tools::displayError('Can\'t save payment');
|
||||||
|
Logger::addLog($errorMessage, 4, '0000003', 'Order', intval($order->id));
|
||||||
|
die($errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
// Next !
|
// Next !
|
||||||
foreach ($order_detail_list as $key => $order_detail)
|
foreach ($order_detail_list as $key => $order_detail)
|
||||||
@@ -249,9 +244,9 @@ abstract class PaymentModuleCore extends Module
|
|||||||
// Insert new Order detail list using cart for the current order
|
// Insert new Order detail list using cart for the current order
|
||||||
//$orderDetail = new OrderDetail(null, null, $this->context);
|
//$orderDetail = new OrderDetail(null, null, $this->context);
|
||||||
//$orderDetail->createList($order, $cart, $id_order_state);
|
//$orderDetail->createList($order, $cart, $id_order_state);
|
||||||
|
|
||||||
//$this->addPCC($order->id, $order->id_currency, $amountPaid);
|
//$this->addPCC($order->id, $order->id_currency, $amountPaid);
|
||||||
|
|
||||||
// Construct order detail table for the email
|
// Construct order detail table for the email
|
||||||
$productsList = '';
|
$productsList = '';
|
||||||
$products = $cart->getProducts();
|
$products = $cart->getProducts();
|
||||||
@@ -259,7 +254,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
{
|
{
|
||||||
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
|
|
||||||
$customizationQuantity = 0;
|
$customizationQuantity = 0;
|
||||||
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']]))
|
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']]))
|
||||||
{
|
{
|
||||||
@@ -269,15 +264,15 @@ abstract class PaymentModuleCore extends Module
|
|||||||
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
|
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
|
||||||
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
|
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
|
||||||
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
|
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
|
||||||
|
|
||||||
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
|
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
|
||||||
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
|
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
|
||||||
|
|
||||||
$customizationText .= '---<br />';
|
$customizationText .= '---<br />';
|
||||||
}
|
}
|
||||||
|
|
||||||
$customizationText = rtrim($customizationText, '---<br />');
|
$customizationText = rtrim($customizationText, '---<br />');
|
||||||
|
|
||||||
$customizationQuantity = (int)($product['customizationQuantityTotal']);
|
$customizationQuantity = (int)($product['customizationQuantityTotal']);
|
||||||
$productsList .=
|
$productsList .=
|
||||||
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
||||||
@@ -288,7 +283,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$customizationQuantity OR (int)$product['cart_quantity'] > $customizationQuantity)
|
if (!$customizationQuantity OR (int)$product['cart_quantity'] > $customizationQuantity)
|
||||||
$productsList .=
|
$productsList .=
|
||||||
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
||||||
@@ -299,7 +294,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
} // end foreach ($products)
|
} // end foreach ($products)
|
||||||
|
|
||||||
$cartRulesList = '';
|
$cartRulesList = '';
|
||||||
$result = $cart->getCartRules();
|
$result = $cart->getCartRules();
|
||||||
$cartRules = ObjectModel::hydrateCollection('CartRule', $result, (int)$order->id_lang);
|
$cartRules = ObjectModel::hydrateCollection('CartRule', $result, (int)$order->id_lang);
|
||||||
@@ -326,19 +321,19 @@ abstract class PaymentModuleCore extends Module
|
|||||||
Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$order->addCartRule($cartRule->id, $cartRule->name, $value);
|
$order->addCartRule($cartRule->id, $cartRule->name, $value);
|
||||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
||||||
$cartRule->quantity = $cartRule->quantity - 1;
|
$cartRule->quantity = $cartRule->quantity - 1;
|
||||||
$cartRule->update();
|
$cartRule->update();
|
||||||
|
|
||||||
$cartRulesList .= '
|
$cartRulesList .= '
|
||||||
<tr style="background-color:#EBECEE;">
|
<tr style="background-color:#EBECEE;">
|
||||||
<td colspan="4" style="padding:0.6em 0.4em;text-align:right">'.$this->l('Voucher name:').' '.$cartRule->name.'</td>
|
<td colspan="4" style="padding:0.6em 0.4em;text-align:right">'.$this->l('Voucher name:').' '.$cartRule->name.'</td>
|
||||||
<td style="padding:0.6em 0.4em;text-align:right">'.($value != 0.00 ? '-' : '').Tools::displayPrice($value, $currency, false).'</td>
|
<td style="padding:0.6em 0.4em;text-align:right">'.($value != 0.00 ? '-' : '').Tools::displayPrice($value, $currency, false).'</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specify order id for message
|
// Specify order id for message
|
||||||
$oldMessage = Message::getMessageByCartId((int)($cart->id));
|
$oldMessage = Message::getMessageByCartId((int)($cart->id));
|
||||||
if ($oldMessage)
|
if ($oldMessage)
|
||||||
@@ -347,7 +342,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$message->id_order = (int)$order->id;
|
$message->id_order = (int)$order->id;
|
||||||
$message->update();
|
$message->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook validate order
|
// Hook validate order
|
||||||
$orderStatus = new OrderState((int)$id_order_state, (int)$order->id_lang);
|
$orderStatus = new OrderState((int)$id_order_state, (int)$order->id_lang);
|
||||||
if (Validate::isLoadedObject($orderStatus))
|
if (Validate::isLoadedObject($orderStatus))
|
||||||
@@ -357,7 +352,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
if ($orderStatus->logable)
|
if ($orderStatus->logable)
|
||||||
ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']);
|
ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Configuration::get('PS_STOCK_MANAGEMENT') && $order_detail->getStockState())
|
if (Configuration::get('PS_STOCK_MANAGEMENT') && $order_detail->getStockState())
|
||||||
{
|
{
|
||||||
$history = new OrderHistory();
|
$history = new OrderHistory();
|
||||||
@@ -373,8 +368,8 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
||||||
$new_history->addWithemail(true, $extraVars);
|
$new_history->addWithemail(true, $extraVars);
|
||||||
|
|
||||||
unset($order_detail, $pcc);
|
unset($order_detail);
|
||||||
|
|
||||||
// Order is reloaded because the status just changed
|
// Order is reloaded because the status just changed
|
||||||
$order = new Order($order->id);
|
$order = new Order($order->id);
|
||||||
|
|
||||||
@@ -385,7 +380,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$delivery = new Address((int)($order->id_address_delivery));
|
$delivery = new Address((int)($order->id_address_delivery));
|
||||||
$delivery_state = $delivery->id_state ? new State((int)($delivery->id_state)) : false;
|
$delivery_state = $delivery->id_state ? new State((int)($delivery->id_state)) : false;
|
||||||
$invoice_state = $invoice->id_state ? new State((int)($invoice->id_state)) : false;
|
$invoice_state = $invoice->id_state ? new State((int)($invoice->id_state)) : false;
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'{firstname}' => $customer->firstname,
|
'{firstname}' => $customer->firstname,
|
||||||
'{lastname}' => $customer->lastname,
|
'{lastname}' => $customer->lastname,
|
||||||
@@ -434,10 +429,10 @@ abstract class PaymentModuleCore extends Module
|
|||||||
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false),
|
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false),
|
||||||
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false),
|
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false),
|
||||||
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false));
|
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false));
|
||||||
|
|
||||||
if (is_array($extraVars))
|
if (is_array($extraVars))
|
||||||
$data = array_merge($data, $extraVars);
|
$data = array_merge($data, $extraVars);
|
||||||
|
|
||||||
// Join PDF invoice
|
// Join PDF invoice
|
||||||
if ((int)(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number)
|
if ((int)(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number)
|
||||||
{
|
{
|
||||||
@@ -447,7 +442,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$fileAttachment = NULL;
|
$fileAttachment = NULL;
|
||||||
|
|
||||||
if (Validate::isEmail($customer->email))
|
if (Validate::isEmail($customer->email))
|
||||||
Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
|
Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
|
||||||
}
|
}
|
||||||
@@ -470,22 +465,6 @@ abstract class PaymentModuleCore extends Module
|
|||||||
die($errorMessage);
|
die($errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new PaymentCC to the order
|
|
||||||
* @var int id_order
|
|
||||||
* @var int id_currency
|
|
||||||
* @var float amount
|
|
||||||
*/
|
|
||||||
private function addPCC($reference, $id_currency, $amount)
|
|
||||||
{
|
|
||||||
// Other information are set by the module
|
|
||||||
|
|
||||||
$this->pcc->order_reference = (int)$reference;
|
|
||||||
$this->pcc->id_currency = (int)$id_currency;
|
|
||||||
$this->pcc->amount = (float)$amount;
|
|
||||||
$this->pcc->add();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Object Address $the_address that needs to be txt formated
|
* @param Object Address $the_address that needs to be txt formated
|
||||||
|
|||||||
+2
-1
@@ -2715,7 +2715,8 @@ class ProductCore extends ObjectModel
|
|||||||
$resultsArray = array();
|
$resultsArray = array();
|
||||||
foreach ($result as $row)
|
foreach ($result as $row)
|
||||||
{
|
{
|
||||||
$row['price'] = Product::getPriceStatic($row['id_product'], true, null, 2);
|
$row['price_tax_incl'] = Product::getPriceStatic($row['id_product'], true, null, 2);
|
||||||
|
$row['price_tax_excl'] = Product::getPriceStatic($row['id_product'], false, null, 2);
|
||||||
$resultsArray[] = $row;
|
$resultsArray[] = $row;
|
||||||
}
|
}
|
||||||
return $resultsArray;
|
return $resultsArray;
|
||||||
|
|||||||
+210
-29
@@ -91,13 +91,13 @@ class OrderCore extends ObjectModel
|
|||||||
/** @var float Total to pay tax excluded */
|
/** @var float Total to pay tax excluded */
|
||||||
public $total_paid_tax_excl;
|
public $total_paid_tax_excl;
|
||||||
|
|
||||||
/** @var float Total really paid */
|
/** @var float Total really paid @deprecated 1.5.0.1 */
|
||||||
public $total_paid_real;
|
public $total_paid_real;
|
||||||
|
|
||||||
/** @var float Products total */
|
/** @var float Products total */
|
||||||
public $total_products;
|
public $total_products;
|
||||||
|
|
||||||
/** @var float Products total tax excluded */
|
/** @var float Products total tax included */
|
||||||
public $total_products_wt;
|
public $total_products_wt;
|
||||||
|
|
||||||
/** @var float Shipping total */
|
/** @var float Shipping total */
|
||||||
@@ -467,8 +467,14 @@ class OrderCore extends ObjectModel
|
|||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @deprecated 1.5.0.1
|
||||||
|
* @see OrderInvoice::setProductPrices
|
||||||
|
*/
|
||||||
public function setProductPrices(&$row)
|
public function setProductPrices(&$row)
|
||||||
{
|
{
|
||||||
|
//Tools::displayAsDeprecated();
|
||||||
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
|
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
|
||||||
$row['tax_calculator'] = $tax_calculator;
|
$row['tax_calculator'] = $tax_calculator;
|
||||||
$row['tax_rate'] = $tax_calculator->getTotalRate();
|
$row['tax_rate'] = $tax_calculator->getTotalRate();
|
||||||
@@ -979,36 +985,50 @@ class OrderCore extends ObjectModel
|
|||||||
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
|
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getLastInvoiceNumber()
|
||||||
public static function getLastInvoiceNumber()
|
{
|
||||||
{
|
return Db::getInstance()->getValue('
|
||||||
return (int)Db::getInstance()->getValue('
|
SELECT MAX(`number`)
|
||||||
SELECT MAX(`invoice_number`) AS `invoice_number`
|
FROM `'._DB_PREFIX_.'order_invoice`
|
||||||
FROM `'._DB_PREFIX_.'orders`');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setInvoice()
|
public function setInvoice()
|
||||||
{
|
{
|
||||||
$number = (int)Configuration::get('PS_INVOICE_START_NUMBER');
|
$order_invoice = new OrderInvoice();
|
||||||
if ($number)
|
$order_invoice->id_order = $this->id;
|
||||||
|
$order_invoice->number = Configuration::get('PS_INVOICE_START_NUMBER');
|
||||||
|
// If invoice start number has been set, you clean the value of this configuration
|
||||||
|
if ($order_invoice->number)
|
||||||
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
|
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
|
||||||
else
|
else
|
||||||
$number = '(SELECT `invoice_number`
|
$order_invoice->number = self::getLastInvoiceNumber() + 1;
|
||||||
FROM (
|
|
||||||
SELECT MAX(`invoice_number`) + 1 AS `invoice_number`
|
$order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl;
|
||||||
FROM `'._DB_PREFIX_.'orders`)
|
$order_invoice->total_discount_tax_incl = $this->total_discount_tax_incl;
|
||||||
tmp )';
|
$order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
|
||||||
// a way to avoid duplicate invoice number
|
$order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl;
|
||||||
|
$order_invoice->total_products = $this->total_products;
|
||||||
|
$order_invoice->total_products_wt = $this->total_products_wt;
|
||||||
|
$order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl;
|
||||||
|
$order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl;
|
||||||
|
$order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;
|
||||||
|
$order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;
|
||||||
|
|
||||||
|
// Save Order invoice
|
||||||
|
$order_invoice->add();
|
||||||
|
|
||||||
|
// Update order_carrier
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
UPDATE `'._DB_PREFIX_.'orders`
|
UPDATE `'._DB_PREFIX_.'order_carrier`
|
||||||
SET `invoice_number` = '.$number.', `invoice_date` = \''.date('Y-m-d H:i:s').'\'
|
SET `id_order_invoice` = '.(int)$order_invoice->id.'
|
||||||
WHERE `id_order` = '.(int)$this->id
|
WHERE `id_order` = '.(int)$order_invoice->id_order);
|
||||||
);
|
|
||||||
$res = Db::getInstance()->getRow('
|
// Update order detail
|
||||||
SELECT `invoice_number`, `invoice_date`
|
Db::getInstance()->execute('
|
||||||
FROM `'._DB_PREFIX_.'orders`
|
UPDATE `'._DB_PREFIX_.'order_detail`
|
||||||
WHERE `id_order` = '.(int)$this->id
|
SET `id_order_invoice` = '.(int)$order_invoice->id.'
|
||||||
);
|
WHERE `id_order` = '.(int)$order_invoice->id_order);
|
||||||
|
|
||||||
$this->invoice_date = $res['invoice_date'];
|
$this->invoice_date = $res['invoice_date'];
|
||||||
$this->invoice_number = $res['invoice_number'];
|
$this->invoice_number = $res['invoice_number'];
|
||||||
@@ -1070,8 +1090,14 @@ class OrderCore extends ObjectModel
|
|||||||
return (float)($result['weight']);
|
return (float)($result['weight']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $id_invoice
|
||||||
|
* @deprecated 1.5.0.1
|
||||||
|
*/
|
||||||
public static function getInvoice($id_invoice)
|
public static function getInvoice($id_invoice)
|
||||||
{
|
{
|
||||||
|
Tools::displayAsDeprecated();
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT `invoice_number`, `id_order`
|
SELECT `invoice_number`, `id_order`
|
||||||
FROM `'._DB_PREFIX_.'orders`
|
FROM `'._DB_PREFIX_.'orders`
|
||||||
@@ -1128,9 +1154,9 @@ class OrderCore extends ObjectModel
|
|||||||
$history->id_employee = (int)$id_employee;
|
$history->id_employee = (int)$id_employee;
|
||||||
$history->changeIdOrderState((int)$id_order_state, (int)$this->id);
|
$history->changeIdOrderState((int)$id_order_state, (int)$this->id);
|
||||||
$res = Db::getInstance()->getRow('
|
$res = Db::getInstance()->getRow('
|
||||||
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
|
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
|
||||||
FROM `'._DB_PREFIX_.'orders`
|
FROM `'._DB_PREFIX_.'orders`
|
||||||
WHERE `id_order` = '.(int)$this->id);
|
WHERE `id_order` = '.(int)$this->id);
|
||||||
$this->invoice_date = $res['invoice_date'];
|
$this->invoice_date = $res['invoice_date'];
|
||||||
$this->invoice_number = $res['invoice_number'];
|
$this->invoice_number = $res['invoice_number'];
|
||||||
$this->delivery_date = $res['delivery_date'];
|
$this->delivery_date = $res['delivery_date'];
|
||||||
@@ -1156,6 +1182,7 @@ class OrderCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method return the ID of the previous order
|
* This method return the ID of the previous order
|
||||||
|
* @since 1.5.0.1
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPreviousOrderId()
|
public function getPreviousOrderId()
|
||||||
@@ -1169,6 +1196,7 @@ class OrderCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method return the ID of the next order
|
* This method return the ID of the next order
|
||||||
|
* @since 1.5.0.1
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getNextOrderId()
|
public function getNextOrderId()
|
||||||
@@ -1243,9 +1271,162 @@ class OrderCore extends ObjectModel
|
|||||||
WHERE od.`id_order` = '.(int)$this->id.'
|
WHERE od.`id_order` = '.(int)$this->id.'
|
||||||
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method allows to get all Order Payment for the current order
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array Collection of Order Payment
|
||||||
|
*/
|
||||||
|
public function getOrderPaymentCollection()
|
||||||
|
{
|
||||||
|
$order_payment = Db::getInstance()->ExecuteS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'order_payment`
|
||||||
|
WHERE `id_order` = '.(int)$this->id);
|
||||||
|
return ObjectModel::hydrateCollection('OrderPayment', $order_payment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This method allows to add a payment to the current order
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @param float $amount_paid
|
||||||
|
* @param string $payment_method
|
||||||
|
* @param string $payment_transaction_id
|
||||||
|
* @param Currency $currency
|
||||||
|
* @param string $date
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null)
|
||||||
|
{
|
||||||
|
$order_payment = new OrderPayment();
|
||||||
|
$order_payment->id_order = $this->id;
|
||||||
|
$order_payment->id_currency = ($currency ? $currency->id : $this->id_currency);
|
||||||
|
// we kept the currency rate for historization reasons
|
||||||
|
$order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1);
|
||||||
|
// if payment_method is define, we used this
|
||||||
|
$order_payment->payment_method = ($payment_method ? $payment_method : $this->payment);
|
||||||
|
$order_payment->transacation_id = $payment_transaction_id;
|
||||||
|
$order_payment->amount = $amount_paid;
|
||||||
|
$order_payment->date_add = ($date ? $date : null);
|
||||||
|
|
||||||
|
// Update total_paid_real value for backward compatibility reasons
|
||||||
|
if ($order_payment->id_currency == $this->id_currency)
|
||||||
|
$this->total_paid_real += $order_payment->amount;
|
||||||
|
else
|
||||||
|
$this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment->amount, $order_payment->id_currency, false), 2);
|
||||||
|
|
||||||
|
return $order_payment->add() && $this->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the correct product taxes breakdown.
|
||||||
|
*
|
||||||
|
* Get all documents linked to the current order
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDocuments()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
$invoices = $this->getInvoicesCollection();
|
||||||
|
|
||||||
|
return $invoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReturn()
|
||||||
|
{
|
||||||
|
return OrderReturn::getOrdersReturn($this->id_customer, $this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShipping()
|
||||||
|
{
|
||||||
|
$shipping = Db::getInstance()->ExecuteS('
|
||||||
|
SELECT DISTINCT oc.`id_order_invoice`, oc.`weight`, oc.`shipping_cost_tax_excl`, oc.`shipping_cost_tax_incl`, c.`url`, oc.`id_carrier`, c.`name` as `state_name`, oc.`date_add`, "Delivery" as `type`, "true" as `can_edit`, oc.`tracking_number`
|
||||||
|
FROM `'._DB_PREFIX_.'orders` o
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_history` oh
|
||||||
|
ON (o.`id_order` = oh.`id_order`)
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc
|
||||||
|
ON (o.`id_order` = oc.`id_order`)
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'carrier` c
|
||||||
|
ON (oc.`id_carrier` = c.`id_carrier`)
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl
|
||||||
|
ON (oh.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)Context::getContext()->language->id.')
|
||||||
|
WHERE o.`id_order` = '.(int)$this->id);
|
||||||
|
return $shipping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get all invoices for the current order
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array Collection of Order invoice
|
||||||
|
*/
|
||||||
|
public function getInvoicesCollection()
|
||||||
|
{
|
||||||
|
$invoices = Db::getInstance()->ExecuteS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'order_invoice`
|
||||||
|
WHERE `id_order` = '.(int)$this->id);
|
||||||
|
return ObjectModel::hydrateCollection('OrderInvoice', $invoices);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get total paid
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @param Currency $currency currency used for the total paid of the current order
|
||||||
|
* @return float amount in the $currency
|
||||||
|
*/
|
||||||
|
public function getTotalPaid($currency = null)
|
||||||
|
{
|
||||||
|
if (!$currency)
|
||||||
|
$currency = new Currency($this->id_currency);
|
||||||
|
|
||||||
|
$total = 0;
|
||||||
|
// Retrieve all payments
|
||||||
|
$payments = $this->getOrderPaymentCollection();
|
||||||
|
foreach($payments as $payment)
|
||||||
|
{
|
||||||
|
if ($payment->id_currency == $currency->id)
|
||||||
|
$total += $payment->amount;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$amount = Tools::convertPrice($payment->amount, $payment->id_currency, false);
|
||||||
|
if ($currency->id == Configuration::get('PS_DEFAULT_CURRENCY'))
|
||||||
|
$total += $amount;
|
||||||
|
else
|
||||||
|
$total += Tool::convertPrice($amount, $currency->id, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tools::ps_round($total, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This method allows to change the shipping cost of the current order
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @param float $amount
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateShippingCost($amount)
|
||||||
|
{
|
||||||
|
$difference = $amount - $this->total_shipping;
|
||||||
|
// if the current amount is same as the new, we return true
|
||||||
|
if ($difference == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// update the total_shipping value
|
||||||
|
$this->total_shipping = $amount;
|
||||||
|
// update the total of this order
|
||||||
|
$this->total_paid += $difference;
|
||||||
|
|
||||||
|
// update database
|
||||||
|
return $this->update();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the correct product taxes breakdown.
|
* Returns the correct product taxes breakdown.
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ class OrderDetailCore extends ObjectModel
|
|||||||
/** @var integer */
|
/** @var integer */
|
||||||
public $id_order;
|
public $id_order;
|
||||||
|
|
||||||
|
/** @var integer */
|
||||||
|
public $id_order_invoice;
|
||||||
|
|
||||||
/** @var integer */
|
/** @var integer */
|
||||||
public $product_id;
|
public $product_id;
|
||||||
|
|
||||||
@@ -133,6 +136,7 @@ class OrderDetailCore extends ObjectModel
|
|||||||
|
|
||||||
protected $fieldsValidate = array(
|
protected $fieldsValidate = array(
|
||||||
'id_order' => 'isUnsignedId',
|
'id_order' => 'isUnsignedId',
|
||||||
|
'id_order_invoice' => 'isUnsignedId',
|
||||||
'product_id' => 'isUnsignedId',
|
'product_id' => 'isUnsignedId',
|
||||||
'product_attribute_id' => 'isUnsignedId',
|
'product_attribute_id' => 'isUnsignedId',
|
||||||
'product_name' => 'isGenericName',
|
'product_name' => 'isGenericName',
|
||||||
@@ -213,6 +217,7 @@ class OrderDetailCore extends ObjectModel
|
|||||||
$this->validateFields();
|
$this->validateFields();
|
||||||
|
|
||||||
$fields['id_order'] = (int)$this->id_order;
|
$fields['id_order'] = (int)$this->id_order;
|
||||||
|
$fields['id_order_invoice'] = (int)$this->id_order_invoice;
|
||||||
$fields['product_id'] = (int)$this->product_id;
|
$fields['product_id'] = (int)$this->product_id;
|
||||||
$fields['product_attribute_id'] = (int)$this->product_attribute_id;
|
$fields['product_attribute_id'] = (int)$this->product_attribute_id;
|
||||||
$fields['product_name'] = pSQL($this->product_name);
|
$fields['product_name'] = pSQL($this->product_name);
|
||||||
@@ -229,7 +234,7 @@ class OrderDetailCore extends ObjectModel
|
|||||||
$fields['product_ean13'] = pSQL($this->product_ean13);
|
$fields['product_ean13'] = pSQL($this->product_ean13);
|
||||||
$fields['product_upc'] = pSQL($this->product_upc);
|
$fields['product_upc'] = pSQL($this->product_upc);
|
||||||
$fields['product_reference'] = pSQL($this->product_reference);
|
$fields['product_reference'] = pSQL($this->product_reference);
|
||||||
$fields['product_supplier_reference'] = pSQL($this->product_reference);
|
$fields['product_supplier_reference'] = pSQL($this->product_supplier_reference);
|
||||||
$fields['product_weight'] = (float)$this->product_weight;
|
$fields['product_weight'] = (float)$this->product_weight;
|
||||||
$fields['tax_name'] = pSQL($this->tax_name);
|
$fields['tax_name'] = pSQL($this->tax_name);
|
||||||
$fields['tax_rate'] = (float)$this->tax_rate;
|
$fields['tax_rate'] = (float)$this->tax_rate;
|
||||||
@@ -405,11 +410,11 @@ class OrderDetailCore extends ObjectModel
|
|||||||
$this->tax_calculator = $tax_manager->getTaxCalculator();
|
$this->tax_calculator = $tax_manager->getTaxCalculator();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ecotax_tax_rate = 0;
|
$this->ecotax_tax_rate = 0;
|
||||||
if (!empty($product['ecotax']))
|
if (!empty($product['ecotax']))
|
||||||
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||||
|
|
||||||
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
|
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,12 +450,14 @@ class OrderDetailCore extends ObjectModel
|
|||||||
$customer = new Customer((int)$order->id_customer);
|
$customer = new Customer((int)$order->id_customer);
|
||||||
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||||
|
|
||||||
$this->specificPrice = SpecificPrice::getSpecificPrice((int)$product['id_product'],
|
$this->specificPrice = SpecificPrice::getSpecificPrice(
|
||||||
(int)$order->id_shop,
|
(int)$product['id_product'],
|
||||||
(int)$order->id_currency,
|
(int)$order->id_shop,
|
||||||
(int)$customer_address->id_country,
|
(int)$order->id_currency,
|
||||||
(int)$customer->id_default_group,
|
(int)$customer_address->id_country,
|
||||||
(int)$product['cart_quantity']);
|
(int)$customer->id_default_group,
|
||||||
|
(int)$product['cart_quantity']
|
||||||
|
);
|
||||||
|
|
||||||
$this->product_price = (float)$product['price'];
|
$this->product_price = (float)$product['price'];
|
||||||
$this->unit_price_tax_incl = (float)$product['price_wt'];
|
$this->unit_price_tax_incl = (float)$product['price_wt'];
|
||||||
@@ -462,7 +469,12 @@ class OrderDetailCore extends ObjectModel
|
|||||||
|
|
||||||
$this->group_reduction = (float)(Group::getReduction((int)($order->id_customer)));
|
$this->group_reduction = (float)(Group::getReduction((int)($order->id_customer)));
|
||||||
|
|
||||||
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(),
|
if (isset($this->context->shop))
|
||||||
|
$shop_id = $this->context->shop->getID();
|
||||||
|
else
|
||||||
|
$shop_id = $cart->id_shop;
|
||||||
|
|
||||||
|
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $shop_id,
|
||||||
(int)$cart->id_currency, (int)$this->vat_address->id_country,
|
(int)$cart->id_currency, (int)$this->vat_address->id_country,
|
||||||
(int)$this->customer->id_default_group, (int)$product['cart_quantity']);
|
(int)$this->customer->id_default_group, (int)$product['cart_quantity']);
|
||||||
|
|
||||||
@@ -484,10 +496,13 @@ class OrderDetailCore extends ObjectModel
|
|||||||
* @param object $cart
|
* @param object $cart
|
||||||
* @param array $product
|
* @param array $product
|
||||||
* @param int $id_order_status
|
* @param int $id_order_status
|
||||||
|
* @param int $id_order_invoice
|
||||||
|
* @param bool $use_taxes set to false if you don't want to use taxes
|
||||||
*/
|
*/
|
||||||
protected function create(Order $order, Cart $cart, $product, $id_order_state)
|
protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true)
|
||||||
{
|
{
|
||||||
$this->tax_calculator = new TaxCalculator();
|
if ($use_taxes)
|
||||||
|
$this->tax_calculator = new TaxCalculator();
|
||||||
|
|
||||||
$this->id = null;
|
$this->id = null;
|
||||||
|
|
||||||
@@ -510,13 +525,19 @@ class OrderDetailCore extends ObjectModel
|
|||||||
|
|
||||||
$this->setVirtualProductInformation($product);
|
$this->setVirtualProductInformation($product);
|
||||||
$this->checkProductStock($product, $id_order_state);
|
$this->checkProductStock($product, $id_order_state);
|
||||||
$this->setProductTax($order, $product);
|
|
||||||
|
if ($use_taxes)
|
||||||
|
$this->setProductTax($order, $product);
|
||||||
$this->setDetailProductPrice($order, $cart, $product);
|
$this->setDetailProductPrice($order, $cart, $product);
|
||||||
|
|
||||||
|
// Set order invoice id
|
||||||
|
$this->id_order_invoice = (int)$id_order_invoice;
|
||||||
|
|
||||||
// Add new entry to the table
|
// Add new entry to the table
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
$this->saveTaxCalculator();
|
if ($use_taxes)
|
||||||
|
$this->saveTaxCalculator();
|
||||||
unset($this->tax_calculator);
|
unset($this->tax_calculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,18 +546,19 @@ class OrderDetailCore extends ObjectModel
|
|||||||
* @param object $order
|
* @param object $order
|
||||||
* @param object $cart
|
* @param object $cart
|
||||||
* @param int $id_order_status
|
* @param int $id_order_status
|
||||||
|
* @param int $id_order_invoice
|
||||||
|
* @param bool $use_taxes set to false if you don't want to use taxes
|
||||||
*/
|
*/
|
||||||
public function createList(Order $order, Cart $cart, $id_order_state, $product_list)
|
public function createList(Order $order, Cart $cart, $id_order_state, $product_list, $id_order_invoice, $use_taxes = true)
|
||||||
{
|
{
|
||||||
$this->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$this->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
$this->customer = new Customer((int)($order->id_customer));
|
$this->customer = new Customer((int)($order->id_customer));
|
||||||
|
|
||||||
$this->id_order = $order->id;
|
$this->id_order = $order->id;
|
||||||
$products = $product_list;
|
|
||||||
$this->outOfStock = false;
|
$this->outOfStock = false;
|
||||||
|
|
||||||
foreach ($products as $product)
|
foreach ($product_list as $product)
|
||||||
$this->create($order, $cart, $product, $id_order_state);
|
$this->create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes);
|
||||||
|
|
||||||
unset($this->vat_address);
|
unset($this->vat_address);
|
||||||
unset($products);
|
unset($products);
|
||||||
|
|||||||
@@ -0,0 +1,387 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/osl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 10418 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class OrderInvoiceCore extends ObjectModel
|
||||||
|
{
|
||||||
|
/** @var integer */
|
||||||
|
public $id_order;
|
||||||
|
|
||||||
|
/** @var integer */
|
||||||
|
public $number;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_discount_tax_excl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_discount_tax_incl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_paid_tax_excl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_paid_tax_incl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_products;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_products_wt;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_shipping_tax_excl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_shipping_tax_incl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_wrapping_tax_excl;
|
||||||
|
|
||||||
|
/** @var float */
|
||||||
|
public $total_wrapping_tax_incl;
|
||||||
|
|
||||||
|
/** @var intger */
|
||||||
|
public $date_add;
|
||||||
|
|
||||||
|
protected $fieldsRequired = array('id_order', 'number');
|
||||||
|
protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'number' => 'isUnsignedId');
|
||||||
|
|
||||||
|
protected $table = 'order_invoice';
|
||||||
|
protected $identifier = 'id_order_invoice';
|
||||||
|
|
||||||
|
public function getFields()
|
||||||
|
{
|
||||||
|
$this->validateFields();
|
||||||
|
|
||||||
|
$fields['id_order'] = (int)$this->id_order;
|
||||||
|
$fields['number'] = (int)$this->number;
|
||||||
|
$fields['total_discount_tax_excl'] = (float)$this->total_discount_tax_excl;
|
||||||
|
$fields['total_discount_tax_incl'] = (float)$this->total_discount_tax_incl;
|
||||||
|
$fields['total_paid_tax_excl'] = (float)$this->total_paid_tax_excl;
|
||||||
|
$fields['total_paid_tax_incl'] = (float)$this->total_paid_tax_incl;
|
||||||
|
$fields['total_products'] = (float)$this->total_products;
|
||||||
|
$fields['total_products_wt'] = (float)$this->total_products_wt;
|
||||||
|
$fields['total_shipping_tax_excl'] = (float)$this->total_shipping_tax_excl;
|
||||||
|
$fields['total_shipping_tax_incl'] = (float)$this->total_shipping_tax_incl;
|
||||||
|
$fields['total_wrapping_tax_excl'] = (float)$this->total_wrapping_tax_excl;
|
||||||
|
$fields['total_wrapping_tax_incl'] = (float)$this->total_wrapping_tax_incl;
|
||||||
|
$fields['date_add'] = pSQL($this->date_add);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProductsDetail()
|
||||||
|
{
|
||||||
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail` od
|
||||||
|
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||||
|
AND od.`id_order_invoice` = '.(int)$this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get order products
|
||||||
|
*
|
||||||
|
* @return array Products with price, quantity (with taxe and without)
|
||||||
|
*/
|
||||||
|
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
|
||||||
|
{
|
||||||
|
if (!$products)
|
||||||
|
$products = $this->getProductsDetail();
|
||||||
|
|
||||||
|
$order = new Order($this->id_order);
|
||||||
|
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
|
||||||
|
|
||||||
|
$resultArray = array();
|
||||||
|
foreach ($products AS $row)
|
||||||
|
{
|
||||||
|
// Change qty if selected
|
||||||
|
if ($selectedQty)
|
||||||
|
{
|
||||||
|
$row['product_quantity'] = 0;
|
||||||
|
foreach ($selectedProducts AS $key => $id_product)
|
||||||
|
if ($row['id_order_detail'] == $id_product)
|
||||||
|
$row['product_quantity'] = (int)($selectedQty[$key]);
|
||||||
|
if (!$row['product_quantity'])
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setProductImageInformations($row);
|
||||||
|
$this->setProductCurrentStock($row);
|
||||||
|
$this->setProductPrices($row, $order);
|
||||||
|
$this->setProductCustomizedDatas($row, $customized_datas);
|
||||||
|
|
||||||
|
// Add information for virtual product
|
||||||
|
if ($row['download_hash'] && !empty($row['download_hash']))
|
||||||
|
{
|
||||||
|
if ($row['product_attribute_id'] && !empty($row['product_attribute_id']))
|
||||||
|
$row['filename'] = ProductDownload::getFilenameFromIdAttribute((int)$row['product_id'], (int)$row['product_attribute_id']);
|
||||||
|
else
|
||||||
|
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
|
||||||
|
// Get the display filename
|
||||||
|
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
|
||||||
|
}
|
||||||
|
/* Stock product */
|
||||||
|
$resultArray[(int)$row['id_order_detail']] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($customized_datas)
|
||||||
|
Product::addCustomizationPrice($resultArray, $customized_datas);
|
||||||
|
|
||||||
|
return $resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setProductCustomizedDatas(&$product, $customized_datas)
|
||||||
|
{
|
||||||
|
$product['customizedDatas'] = null;
|
||||||
|
if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
|
||||||
|
$product['customizedDatas'] = $customized_datas[$product['product_id']][$product['product_attribute_id']];
|
||||||
|
else
|
||||||
|
$product['customizationQuantityTotal'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This method allow to add stock information on a product detail
|
||||||
|
* @param array &$product
|
||||||
|
*/
|
||||||
|
protected function setProductCurrentStock(&$product)
|
||||||
|
{
|
||||||
|
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This method allow to add image information on a product detail
|
||||||
|
* @param array &$product
|
||||||
|
*/
|
||||||
|
protected function setProductImageInformations(&$product)
|
||||||
|
{
|
||||||
|
if (isset($product['product_attribute_id']) && $product['product_attribute_id'])
|
||||||
|
$id_image = Db::getInstance()->getValue('
|
||||||
|
SELECT id_image
|
||||||
|
FROM '._DB_PREFIX_.'product_attribute_image
|
||||||
|
WHERE id_product_attribute = '.(int)$product['product_attribute_id']);
|
||||||
|
|
||||||
|
if (!isset($image['id_image']) || !$image['id_image'])
|
||||||
|
$id_image = Db::getInstance()->getValue('
|
||||||
|
SELECT id_image
|
||||||
|
FROM '._DB_PREFIX_.'image
|
||||||
|
WHERE id_product = '.(int)($product['product_id']).' AND cover = 1
|
||||||
|
');
|
||||||
|
|
||||||
|
$product['image'] = null;
|
||||||
|
$product['image_size'] = null;
|
||||||
|
|
||||||
|
if ($id_image)
|
||||||
|
$product['image'] = new Image($id_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setProductPrices(&$row, $order)
|
||||||
|
{
|
||||||
|
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
|
||||||
|
$row['tax_calculator'] = $tax_calculator;
|
||||||
|
$row['tax_rate'] = $tax_calculator->getTotalRate();
|
||||||
|
|
||||||
|
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||||
|
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
|
||||||
|
else
|
||||||
|
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2);
|
||||||
|
|
||||||
|
$group_reduction = 1;
|
||||||
|
if ($row['group_reduction'] > 0)
|
||||||
|
$group_reduction = 1 - $row['group_reduction'] / 100;
|
||||||
|
|
||||||
|
if ($row['reduction_percent'] != 0)
|
||||||
|
{
|
||||||
|
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||||
|
$row['product_price'] = ($row['product_price'] - $row['product_price'] * ($row['reduction_percent'] * 0.01));
|
||||||
|
else
|
||||||
|
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['product_price_wt'] * ($row['reduction_percent'] * 0.01)), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['reduction_amount'] != 0)
|
||||||
|
{
|
||||||
|
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||||
|
$row['product_price'] = ($row['product_price'] - ($tax_calculator->removeTaxes($row['reduction_amount'])));
|
||||||
|
else
|
||||||
|
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['reduction_amount']), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['group_reduction'] > 0)
|
||||||
|
{
|
||||||
|
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||||
|
$row['product_price'] = $row['product_price'] * $group_reduction;
|
||||||
|
else
|
||||||
|
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] * $group_reduction , 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($row['reduction_percent'] OR $row['reduction_amount'] OR $row['group_reduction']) AND $order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||||
|
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
|
||||||
|
|
||||||
|
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||||
|
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2) + Tools::ps_round($row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$row['product_price_wt_but_ecotax'] = $row['product_price_wt'];
|
||||||
|
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] + $row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$row['total_wt'] = $row['product_quantity'] * $row['product_price_wt'];
|
||||||
|
$row['total_price'] = $row['product_quantity'] * $row['product_price'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns true if at least one order details uses the
|
||||||
|
* One After Another tax computation method.
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function useOneAfterAnotherTaxComputationMethod()
|
||||||
|
{
|
||||||
|
// if one of the order details use the tax computation method the display will be different
|
||||||
|
return Db::getInstance()->getValue('
|
||||||
|
SELECT od.`tax_computation_method`
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||||
|
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||||
|
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||||
|
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the correct product taxes breakdown.
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getProductTaxesBreakdown()
|
||||||
|
{
|
||||||
|
$tmp_tax_infos = array();
|
||||||
|
if ($this->useOneAfterAnotherTaxComputationMethod())
|
||||||
|
{
|
||||||
|
// sum by taxes
|
||||||
|
$taxes_by_tax = Db::getInstance()->executeS('
|
||||||
|
SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount`
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||||
|
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||||
|
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||||
|
GROUP BY odt.`id_tax`
|
||||||
|
');
|
||||||
|
|
||||||
|
// format response
|
||||||
|
$tmp_tax_infos = array();
|
||||||
|
foreach ($taxes_infos as $tax_infos)
|
||||||
|
{
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount'];
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// sum by order details in order to retrieve real taxes rate
|
||||||
|
$taxes_infos = Db::getInstance()->executeS('
|
||||||
|
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||||
|
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||||
|
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||||
|
GROUP BY odt.`id_order_detail`
|
||||||
|
');
|
||||||
|
|
||||||
|
// sum by taxes
|
||||||
|
$tmp_tax_infos = array();
|
||||||
|
foreach ($taxes_infos as $tax_infos)
|
||||||
|
{
|
||||||
|
if (!isset($tmp_tax_infos[$tax_infos['rate']]))
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']] = array('total_amount' => 0,
|
||||||
|
'name' => 0,
|
||||||
|
'total_price_tax_excl' => 0);
|
||||||
|
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['total_amount'];
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
||||||
|
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tmp_tax_infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shipping taxes breakdown
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getShippingTaxesBreakdown($order)
|
||||||
|
{
|
||||||
|
$taxes_breakdown = array();
|
||||||
|
|
||||||
|
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;
|
||||||
|
|
||||||
|
if ($shipping_tax_amount > 0)
|
||||||
|
$taxes_breakdown[] = array(
|
||||||
|
'rate' => $order->carrier_tax_rate,
|
||||||
|
'total_amount' => $shipping_tax_amount
|
||||||
|
);
|
||||||
|
|
||||||
|
return $taxes_breakdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the wrapping taxes breakdown
|
||||||
|
* @todo
|
||||||
|
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getWrappingTaxesBreakdown()
|
||||||
|
{
|
||||||
|
$taxes_breakdown = array();
|
||||||
|
return $taxes_breakdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ecotax taxes breakdown
|
||||||
|
*
|
||||||
|
* @since 1.5.0.1
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getEcoTaxTaxesBreakdown()
|
||||||
|
{
|
||||||
|
return Db::getInstance()->executeS('
|
||||||
|
SELECT `ecotax_tax_rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail`
|
||||||
|
WHERE `id_order` = '.(int)$this->id_order.'
|
||||||
|
AND `id_order_invoice` = '.(int)$this->id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/osl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 10336 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class OrderPaymentCore extends ObjectModel
|
||||||
|
{
|
||||||
|
public $id_order;
|
||||||
|
public $id_currency;
|
||||||
|
public $amount;
|
||||||
|
public $payment_method;
|
||||||
|
public $conversion_rate;
|
||||||
|
public $transaction_id;
|
||||||
|
public $card_number;
|
||||||
|
public $card_brand;
|
||||||
|
public $card_expiration;
|
||||||
|
public $card_holder;
|
||||||
|
public $date_add;
|
||||||
|
|
||||||
|
protected $fieldsRequired = array('id_order', 'id_currency', 'amount');
|
||||||
|
protected $fieldsSize = array('transaction_id' => 254, 'card_number' => 254, 'card_brand' => 254, 'card_expiration' => 254, 'card_holder' => 254);
|
||||||
|
protected $fieldsValidate = array(
|
||||||
|
'id_order' => 'isUnsignedId',
|
||||||
|
'id_currency' => 'isUnsignedId',
|
||||||
|
'amount' => 'isPrice',
|
||||||
|
'payment_method' => 'isName',
|
||||||
|
'conversion_rate' => 'isFloat',
|
||||||
|
'transaction_id' => 'isAnything',
|
||||||
|
'card_number' => 'isAnything',
|
||||||
|
'card_brand' => 'isAnything',
|
||||||
|
'card_expiration' => 'isAnything',
|
||||||
|
'card_holder' => 'isAnything'
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $table = 'order_payment';
|
||||||
|
protected $identifier = 'id_order_payment';
|
||||||
|
|
||||||
|
public function getFields()
|
||||||
|
{
|
||||||
|
$this->validateFields();
|
||||||
|
$fields['id_order'] = (int)($this->id_order);
|
||||||
|
$fields['id_currency'] = (int)($this->id_currency);
|
||||||
|
$fields['amount'] = (float)($this->amount);
|
||||||
|
$fields['payment_method'] = pSQL($this->payment_method);
|
||||||
|
$fields['transaction_id'] = pSQL($this->transaction_id);
|
||||||
|
$fields['card_number'] = pSQL($this->card_number);
|
||||||
|
$fields['card_brand'] = pSQL($this->card_brand);
|
||||||
|
$fields['card_expiration'] = pSQL($this->card_expiration);
|
||||||
|
$fields['card_holder'] = pSQL($this->card_holder);
|
||||||
|
$fields['date_add'] = pSQL($this->date_add);
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add($autodate = true, $nullValues = false)
|
||||||
|
{
|
||||||
|
if (parent::add($autodate, $nullValues))
|
||||||
|
{
|
||||||
|
Hook::exec('paymentCCAdded', array('paymentCC' => $this));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the detailed payment of an order
|
||||||
|
* @param int $id_order
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getByOrderId($id_order)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->ExecuteS('
|
||||||
|
SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'payment_order`
|
||||||
|
WHERE `id_order` = '.(int)$id_order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -143,10 +143,13 @@ class OrderReturnCore extends ObjectModel
|
|||||||
($order_id ? ' AND `id_order` = '.(int)($order_id) : '').
|
($order_id ? ' AND `id_order` = '.(int)($order_id) : '').
|
||||||
($no_denied ? ' AND `state` != 4' : '').'
|
($no_denied ? ' AND `state` != 4' : '').'
|
||||||
ORDER BY `date_add` DESC');
|
ORDER BY `date_add` DESC');
|
||||||
foreach ($data AS $k => $or)
|
foreach ($data as $k => $or)
|
||||||
{
|
{
|
||||||
$state = new OrderReturnState($or['state']);
|
$state = new OrderReturnState($or['state']);
|
||||||
$data[$k]['state_name'] = $state->name[$context->language->id];
|
$data[$k]['state_name'] = $state->name[$context->language->id];
|
||||||
|
$data[$k]['type'] = 'Return';
|
||||||
|
$data[$k]['tracking_number'] = $or['id_order_return'];
|
||||||
|
$data[$k]['can_edit'] = false;
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class OrderSlipCore extends ObjectModel
|
|||||||
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
|
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO clean getProducts($resTab) => now getProducts method don't use his parameters
|
||||||
public static function getOrdersSlipProducts($orderSlipId, $order)
|
public static function getOrdersSlipProducts($orderSlipId, $order)
|
||||||
{
|
{
|
||||||
$cart_rules = $order->getCartRules(true);
|
$cart_rules = $order->getCartRules(true);
|
||||||
|
|||||||
@@ -34,17 +34,18 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
|||||||
|
|
||||||
public $available_in_your_account = false;
|
public $available_in_your_account = false;
|
||||||
|
|
||||||
public function __construct(Order $order, $smarty)
|
public function __construct(OrderInvoice $order_invoice, $smarty)
|
||||||
{
|
{
|
||||||
$this->order = $order;
|
$this->order_invoice = $order_invoice;
|
||||||
$this->smarty = $smarty;
|
$this->order = new Order($this->order_invoice->id_order);
|
||||||
|
$this->smarty = $smarty;
|
||||||
|
|
||||||
// header informations
|
// header informations
|
||||||
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang);
|
$this->date = Tools::displayDate($order_invoice->date_add, (int)$this->order->id_lang);
|
||||||
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number);
|
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order_invoice->number);
|
||||||
|
|
||||||
// footer informations
|
// footer informations
|
||||||
$shop = new Shop((int)$order->id_shop);
|
$shop = new Shop((int)$this->order->id_shop);
|
||||||
$this->address = $shop->getAddress();
|
$this->address = $shop->getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
|||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'order' => $this->order,
|
'order' => $this->order,
|
||||||
'order_details' => $this->order->getProducts(),
|
'order_details' => $this->order_invoice->getProducts(),
|
||||||
'delivery_address' => $formatted_delivery_address,
|
'delivery_address' => $formatted_delivery_address,
|
||||||
'invoice_address' => $formatted_invoice_address,
|
'invoice_address' => $formatted_invoice_address,
|
||||||
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
|
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
|
||||||
@@ -91,11 +92,12 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
|||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'tax_exempt' => $tax_exempt,
|
'tax_exempt' => $tax_exempt,
|
||||||
'use_one_after_another_method' => $this->order->useOneAfterAnotherTaxComputationMethod(),
|
'use_one_after_another_method' => $this->order_invoice->useOneAfterAnotherTaxComputationMethod(),
|
||||||
'product_tax_breakdown' => $this->order->getProductTaxesBreakdown(),
|
'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown(),
|
||||||
'shipping_tax_breakdown' => $this->order->getShippingTaxesBreakdown(),
|
'shipping_tax_breakdown' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
|
||||||
'ecotax_tax_breakdown' => $this->order->getEcoTaxTaxesBreakdown(),
|
'ecotax_tax_breakdown' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
|
||||||
'order' => $this->order,
|
'order' => $this->order,
|
||||||
|
'order_invoice' => $this->order_invoice
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
|
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
|
||||||
@@ -131,7 +133,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
|||||||
*/
|
*/
|
||||||
public function getFilename()
|
public function getFilename()
|
||||||
{
|
{
|
||||||
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf';
|
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order_invoice->number).'.pdf';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
class AdminOrdersControllerCore extends AdminController
|
class AdminOrdersControllerCore extends AdminController
|
||||||
{
|
{
|
||||||
|
public $toolbar_title;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->table = 'order';
|
$this->table = 'order';
|
||||||
@@ -52,7 +54,8 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
|
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
|
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
|
||||||
$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';
|
$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';
|
||||||
$this->_orderWay = 'DESC';
|
$this->_orderBy = '`id_order`';
|
||||||
|
$this->_orderWay = 'DESC'; // FIXME
|
||||||
|
|
||||||
$statesArray = array();
|
$statesArray = array();
|
||||||
$states = OrderState::getOrderStates((int)$this->context->language->id);
|
$states = OrderState::getOrderStates((int)$this->context->language->id);
|
||||||
@@ -65,7 +68,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 65),
|
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 65),
|
||||||
'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),
|
'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),
|
||||||
'customer' => array('title' => $this->l('Customer'), 'filter_key' => 'customer', 'tmpTableFilter' => true),
|
'customer' => array('title' => $this->l('Customer'), 'filter_key' => 'customer', 'tmpTableFilter' => true),
|
||||||
'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true),
|
'total_paid_tax_incl' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true),
|
||||||
'payment' => array('title' => $this->l('Payment'), 'width' => 100),
|
'payment' => array('title' => $this->l('Payment'), 'width' => 100),
|
||||||
'osname' => array('title' => $this->l('Status'), 'width' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
|
'osname' => array('title' => $this->l('Status'), 'width' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
|
||||||
'date_add' => array('title' => $this->l('Date'), 'width' => 120, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
|
'date_add' => array('title' => $this->l('Date'), 'width' => 120, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
|
||||||
@@ -82,73 +85,118 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
parent::initForm();
|
parent::initForm();
|
||||||
$this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
|
$this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
|
||||||
$cart = new Cart((int)Tools::getValue('id_cart'));
|
$cart = new Cart((int)Tools::getValue('id_cart'));
|
||||||
$this->context->smarty->assign(array('recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'),
|
$this->context->smarty->assign(array(
|
||||||
'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'),
|
'recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'),
|
||||||
'cart' => $cart,
|
'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'),
|
||||||
'currencies' => Currency::getCurrencies(),
|
'cart' => $cart,
|
||||||
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
|
'currencies' => Currency::getCurrencies(),
|
||||||
'payment_modules' => PaymentModule::getInstalledPaymentModules(),
|
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
|
||||||
'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang)));
|
'payment_modules' => PaymentModule::getInstalledPaymentModules(),
|
||||||
|
'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang)));
|
||||||
$this->content .= $this->context->smarty->fetch('orders/form.tpl');
|
$this->content .= $this->context->smarty->fetch('orders/form.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function initToolbar()
|
||||||
|
{
|
||||||
|
if ($this->display == 'view')
|
||||||
|
{
|
||||||
|
$this->toolbar_btn['new'] = array(
|
||||||
|
'short' => 'Create',
|
||||||
|
'href' => '',
|
||||||
|
'desc' => $this->l('Add a product'),
|
||||||
|
'class' => 'add_product'
|
||||||
|
);
|
||||||
|
$this->toolbar_btn['standard_refund'] = array(
|
||||||
|
'short' => 'Create',
|
||||||
|
'href' => '',
|
||||||
|
'desc' => $this->l('Standard refund'),
|
||||||
|
'class' => 'process-icon-new standard_refund'
|
||||||
|
);
|
||||||
|
$this->toolbar_btn['partial_refund'] = array(
|
||||||
|
'short' => 'Create',
|
||||||
|
'href' => '',
|
||||||
|
'desc' => $this->l('Partial refund'),
|
||||||
|
'class' => 'process-icon-new partial_refund'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return parent::initToolbar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMedia()
|
||||||
|
{
|
||||||
|
parent::setMedia();
|
||||||
|
$this->addJqueryUI('ui.datepicker');
|
||||||
|
if ($this->tabAccess['edit'] == 1 && $this->display == 'view')
|
||||||
|
{
|
||||||
|
$this->addJS(_PS_JS_DIR_.'admin_order.js');
|
||||||
|
$this->addJS(_PS_JS_DIR_.'tools.js');
|
||||||
|
$this->addJqueryPlugin('autocomplete');
|
||||||
|
$this->addJqueryPlugin('scrollTo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function printPDFIcons($id_order, $tr)
|
public function printPDFIcons($id_order, $tr)
|
||||||
{
|
{
|
||||||
$order = new Order($id_order);
|
$order = new Order($id_order);
|
||||||
$orderState = OrderHistory::getLastOrderState($id_order);
|
$order_state = OrderHistory::getLastOrderState($id_order);
|
||||||
if (!Validate::isLoadedObject($orderState) OR !Validate::isLoadedObject($order))
|
if (!Validate::isLoadedObject($order_state) OR !Validate::isLoadedObject($order))
|
||||||
die(Tools::displayError('Invalid objects'));
|
die(Tools::displayError('Invalid objects'));
|
||||||
|
|
||||||
// Generate HTML code for printing Invoice Icon with link
|
$this->context->smarty->assign(array(
|
||||||
$content = '<span style="width:20px; margin-right:5px;">';
|
'order' => $order,
|
||||||
if (($orderState->invoice && $order->invoice_number) && (int)$tr['product_number'])
|
'order_state' => $order_state,
|
||||||
$content .= '<a href="pdf.php?id_order='.(int)$order->id.'&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>';
|
'tr' => $tr
|
||||||
else
|
));
|
||||||
$content .= '-';
|
|
||||||
$content .= '</span>';
|
|
||||||
|
|
||||||
// Generate HTML code for printing Delivery Icon with link
|
return $this->context->smarty->fetch('orders/_print_pdf_icon.tpl');
|
||||||
$content .= '<span style="width:20px;">';
|
|
||||||
if ($orderState->delivery && $order->delivery_number)
|
|
||||||
$content .= '<a href="pdf.php?id_delivery='.(int)$order->delivery_number.'"><img src="../img/admin/delivery.gif" alt="delivery" /></a>';
|
|
||||||
else
|
|
||||||
$content .= '-';
|
|
||||||
$content .= '</span>';
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postProcess()
|
public function postProcess()
|
||||||
{
|
{
|
||||||
/* Update shipping number */
|
/* Update shipping number */
|
||||||
if (Tools::isSubmit('submitShippingNumber') AND ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order)))
|
if (Tools::isSubmit('submitShippingNumber') AND ($id_order = (int)Tools::getValue('id_order')) AND Validate::isLoadedObject($order = new Order($id_order)))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
if (!$order->hasBeenShipped())
|
if (Validate::isUrl(Tools::getValue('tracking_number')))
|
||||||
throw new PrestashopException('The shipping number can only be set once the order has been shipped.');
|
|
||||||
$_GET['view'.$this->table] = true;
|
|
||||||
|
|
||||||
$shipping_number = pSQL(Tools::getValue('shipping_number'));
|
|
||||||
$order->shipping_number = $shipping_number;
|
|
||||||
$order->update();
|
|
||||||
if ($shipping_number)
|
|
||||||
{
|
{
|
||||||
global $_LANGMAIL;
|
// update shipping number
|
||||||
$customer = new Customer((int)($order->id_customer));
|
$order->shipping_number = Tools::getValue('tracking_number');
|
||||||
$carrier = new Carrier((int)($order->id_carrier));
|
if ($order->update())
|
||||||
if (!Validate::isLoadedObject($customer) OR !Validate::isLoadedObject($carrier))
|
{
|
||||||
die(Tools::displayError());
|
// Update order_carrier
|
||||||
$templateVars = array(
|
$id_order_invoice = Tools::getValue('id_order_invoice');
|
||||||
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
|
$id_carrier = Tools::getValue('id_carrier');
|
||||||
'{firstname}' => $customer->firstname,
|
Db::getInstance()->execute('
|
||||||
'{lastname}' => $customer->lastname,
|
UPDATE `'._DB_PREFIX_.'order_carrier`
|
||||||
'{id_order}' => (int)($order->id)
|
SET `tracking_number` = '.pSQL(Tools::getValue('tracking_number')).'
|
||||||
);
|
WHERE `id_order` = '.(int)$order->id.
|
||||||
@Mail::Send((int)($order->id_lang), 'in_transit', Mail::l('Package in transit'), $templateVars,
|
' AND `id_carrier` = '.(int)$id_carrier.
|
||||||
$customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,
|
($id_order_invoice ? ' AND `id_order_invoice` = '.(int)$id_order_invoice : ''));
|
||||||
_PS_MAIL_DIR_, true);
|
|
||||||
|
global $_LANGMAIL;
|
||||||
|
$customer = new Customer((int)$order->id_customer);
|
||||||
|
$carrier = new Carrier((int)$order->id_carrier);
|
||||||
|
if (!Validate::isLoadedObject($customer))
|
||||||
|
throw new PrestashopException('Can\'t load Customer object');
|
||||||
|
if (!Validate::isLoadedObject($carrier))
|
||||||
|
throw new PrestashopException('Can\'t load Carrier object');
|
||||||
|
$templateVars = array(
|
||||||
|
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
|
||||||
|
'{firstname}' => $customer->firstname,
|
||||||
|
'{lastname}' => $customer->lastname,
|
||||||
|
'{id_order}' => (int)$order->id
|
||||||
|
);
|
||||||
|
@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit'), $templateVars,
|
||||||
|
$customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,
|
||||||
|
_PS_MAIL_DIR_, true);
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('An error occured on updating of order');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('Shipping number is incorrect');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
@@ -256,11 +304,11 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
if (Validate::isLoadedObject($order))
|
if (Validate::isLoadedObject($order))
|
||||||
{
|
{
|
||||||
$varsTpl = array(
|
$varsTpl = array(
|
||||||
'{lastname}' => $customer->lastname,
|
'{lastname}' => $customer->lastname,
|
||||||
'{firstname}' => $customer->firstname,
|
'{firstname}' => $customer->firstname,
|
||||||
'{id_order}' => $order->id,
|
'{id_order}' => $order->id,
|
||||||
'{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $cm->message : Tools::nl2br($cm->message))
|
'{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $cm->message : Tools::nl2br($cm->message))
|
||||||
);
|
);
|
||||||
if (@Mail::Send((int)($order->id_lang), 'order_merchant_comment',
|
if (@Mail::Send((int)($order->id_lang), 'order_merchant_comment',
|
||||||
Mail::l('New message regarding your order'), $varsTpl, $customer->email,
|
Mail::l('New message regarding your order'), $varsTpl, $customer->email,
|
||||||
$customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true))
|
$customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true))
|
||||||
@@ -349,10 +397,11 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
$reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected);
|
$reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected);
|
||||||
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
|
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
|
||||||
if (!Product::reinjectQuantities($orderDetail, $quantityToReinject))
|
// TODO (Denis) : fix reinject quantities
|
||||||
$this->_errors[] = Tools::displayError('Cannot re-stock product').' <span class="bold">'.$orderDetail->product_name.'</span>';
|
// if (!Product::reinjectQuantities($orderDetail, $quantityToReinject))
|
||||||
else
|
// $this->_errors[] = Tools::displayError('Cannot re-stock product').' <span class="bold">'.$orderDetail->product_name.'</span>';
|
||||||
{
|
// else
|
||||||
|
// {
|
||||||
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int)($orderDetail->product_attribute_id) : NULL;
|
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int)($orderDetail->product_attribute_id) : NULL;
|
||||||
$newProductQty = Product::getQuantity($orderDetail->product_id, $updProductAttributeID);
|
$newProductQty = Product::getQuantity($orderDetail->product_id, $updProductAttributeID);
|
||||||
$product = get_object_vars(new Product($orderDetail->product_id, false, $this->context->language->id, $order->id_shop));
|
$product = get_object_vars(new Product($orderDetail->product_id, false, $this->context->language->id, $order->id_shop));
|
||||||
@@ -367,7 +416,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$product['stock_quantity'] = $updProduct['stock_quantity'];
|
$product['stock_quantity'] = $updProduct['stock_quantity'];
|
||||||
}
|
}
|
||||||
Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
|
Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete product
|
// Delete product
|
||||||
@@ -436,6 +485,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
Message::markAsReaded($_GET['messageReaded'], $this->context->employee->id);
|
Message::markAsReaded($_GET['messageReaded'], $this->context->employee->id);
|
||||||
}
|
}
|
||||||
|
// TODO clean PaymentCC
|
||||||
else if (Tools::isSubmit('setTransactionId') && ((int)Tools::getValue('id_order')))
|
else if (Tools::isSubmit('setTransactionId') && ((int)Tools::getValue('id_order')))
|
||||||
{
|
{
|
||||||
$order = new Order((int)(Tools::getValue('id_order')));
|
$order = new Order((int)(Tools::getValue('id_order')));
|
||||||
@@ -449,9 +499,34 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
|
|
||||||
unset($order, $pcc);
|
unset($order, $pcc);
|
||||||
}
|
}
|
||||||
|
else if (Tools::isSubmit('submitAddPayment'))
|
||||||
|
{
|
||||||
|
if ($this->tabAccess['edit'] === '1')
|
||||||
|
{
|
||||||
|
$order = new Order(Tools::getValue('id_order'));
|
||||||
|
$amount = str_replace(',', '.', Tools::getValue('payment_amount'));
|
||||||
|
$currency = new Currency(Tools::getValue('payment_currency'));
|
||||||
|
if (!Validate::isLoadedObject($order))
|
||||||
|
$this->_errors[] = Tools::displayError('Order can\'t be found');
|
||||||
|
elseif (!Validate::isPrice($amount))
|
||||||
|
$this->_errors[] = Tools::displayError('Amount is invalid');
|
||||||
|
elseif (!Validate::isString(Tools::getValue('payment_method')))
|
||||||
|
$this->_errors[] = Tools::displayError('Payment method is invalid');
|
||||||
|
elseif (!Validate::isString(Tools::getValue('payment_transaction_id')))
|
||||||
|
$this->_errors[] = Tools::displayError('Transaction ID is invalid');
|
||||||
|
elseif (!Validate::isLoadedObject($currency))
|
||||||
|
$this->_errors[] = Tools::displayError('Currency is invalid');
|
||||||
|
elseif (!Validate::isDate(Tools::getValue('payment_date')))
|
||||||
|
$this->_errors[] = Tools::displayError('Date is invalid');
|
||||||
|
else
|
||||||
|
if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date')))
|
||||||
|
$this->_errors[] = Tools::displayError('An error occured on adding of order payment');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
|
}
|
||||||
elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state')))
|
elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state')))
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
$payment_module = Module::getInstanceByName($module_name);
|
$payment_module = Module::getInstanceByName($module_name);
|
||||||
@@ -463,6 +538,29 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||||
}
|
}
|
||||||
|
elseif (Tools::isSubmit('submitAddressShipping') || Tools::isSubmit('submitAddressInvoice'))
|
||||||
|
{
|
||||||
|
if ($this->tabAccess['edit'] === '1')
|
||||||
|
{
|
||||||
|
$address = new Address(Tools::getValue('id_address'));
|
||||||
|
if (Validate::isLoadedObject($address))
|
||||||
|
{
|
||||||
|
// Update the address on order
|
||||||
|
$order = new Order(Tools::getValue('id_order'));
|
||||||
|
if (Tools::isSubmit('submitAddressShipping'))
|
||||||
|
$order->id_address_delivery = $address->id;
|
||||||
|
elseif (Tools::isSubmit('submitAddressInvoice'))
|
||||||
|
$order->id_address_invoice = $address->id;
|
||||||
|
$order->update();
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayErrror('This address can\'t be loaded');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
|
}
|
||||||
|
|
||||||
parent::postProcess();
|
parent::postProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,22 +568,11 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
$order = $this->loadObject();
|
$order = $this->loadObject();
|
||||||
if (!Validate::isLoadedObject($order))
|
if (!Validate::isLoadedObject($order))
|
||||||
return;
|
throw new PrestashopException('object can\'t be loaded');
|
||||||
|
|
||||||
$customer = new Customer($order->id_customer);
|
$customer = new Customer($order->id_customer);
|
||||||
$carrier = new Carrier($order->id_carrier);
|
$carrier = new Carrier($order->id_carrier);
|
||||||
$products = $order->getProducts();
|
$products = $this->getProducts($order);
|
||||||
|
|
||||||
foreach ($products as &$product)
|
|
||||||
{
|
|
||||||
if ($product['image'] != null)
|
|
||||||
{
|
|
||||||
$name = 'product_mini_'.(int)$product['product_id'].(isset($product['product_attribute_id']) ? '_'.(int)$product['product_attribute_id'] : '').'.jpg';
|
|
||||||
// generate image cache, only for back office
|
|
||||||
$product['image_tag'] = cacheImage(_PS_IMG_DIR_.'p/'.$product['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg');
|
|
||||||
$product['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carrier module call
|
// Carrier module call
|
||||||
$carrier_module_call = null;
|
$carrier_module_call = null;
|
||||||
@@ -514,11 +601,14 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$deliveryState = new State((int)($addressDelivery->id_state));
|
$deliveryState = new State((int)($addressDelivery->id_state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->toolbar_title = $this->l('Order #').sprintf('%06d', $order->id).' - '.$customer->firstname.' '.$customer->lastname;
|
||||||
|
|
||||||
// Smarty assign
|
// Smarty assign
|
||||||
$this->tpl_view_vars = array(
|
$this->tpl_view_vars = array(
|
||||||
'order' => $order,
|
'order' => $order,
|
||||||
'cart' => new Cart($order->id),
|
'cart' => new Cart($order->id),
|
||||||
'customer' => $customer,
|
'customer' => $customer,
|
||||||
|
'customer_addresses' => $customer->getAddresses($this->context->language->id),
|
||||||
'addresses' => array(
|
'addresses' => array(
|
||||||
'delivery' => $addressDelivery,
|
'delivery' => $addressDelivery,
|
||||||
'deliveryState' => isset($deliveryState) ? $deliveryState : null,
|
'deliveryState' => isset($deliveryState) ? $deliveryState : null,
|
||||||
@@ -528,6 +618,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
'customerStats' => $customer->getStats(),
|
'customerStats' => $customer->getStats(),
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
'discounts' => $order->getCartRules(),
|
'discounts' => $order->getCartRules(),
|
||||||
|
'total_paid' => $order->getTotalPaid(),
|
||||||
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
|
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
|
||||||
'slips' => OrderSlip::getOrdersSlip($order->id_customer, $order->id),
|
'slips' => OrderSlip::getOrdersSlip($order->id_customer, $order->id),
|
||||||
'orderMessages' => OrderMessage::getOrderMessages($order->id_lang),
|
'orderMessages' => OrderMessage::getOrderMessages($order->id_lang),
|
||||||
@@ -539,20 +630,23 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
'sources' => ConnectionsSource::getOrderSources($order->id),
|
'sources' => ConnectionsSource::getOrderSources($order->id),
|
||||||
'currentState' => OrderHistory::getLastOrderState($order->id),
|
'currentState' => OrderHistory::getLastOrderState($order->id),
|
||||||
'currency' => new Currency($order->id_currency),
|
'currency' => new Currency($order->id_currency),
|
||||||
|
'currencies' => Currency::getCurrencies(),
|
||||||
'previousOrder' => $order->getPreviousOrderId(),
|
'previousOrder' => $order->getPreviousOrderId(),
|
||||||
'nextOrder' => $order->getNextOrderId(),
|
'nextOrder' => $order->getNextOrderId(),
|
||||||
'currentIndex' => self::$currentIndex,
|
'currentIndex' => self::$currentIndex,
|
||||||
'carrierModuleCall' => $carrier_module_call,
|
'carrierModuleCall' => $carrier_module_call,
|
||||||
'iso_code_lang' => $this->context->language->iso_code,
|
'iso_code_lang' => $this->context->language->iso_code,
|
||||||
'id_lang' => $this->context->language->id,
|
'id_lang' => $this->context->language->id,
|
||||||
'paymentCCDetails' => PaymentCC::getByOrderId($order->id),
|
'can_edit' => ($this->tabAccess['edit'] == 1),
|
||||||
|
'current_id_lang' => $this->context->language->id,
|
||||||
|
'invoices_collection' => $order->getInvoicesCollection(),
|
||||||
'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)),
|
'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)),
|
||||||
'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id))
|
'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id))
|
||||||
);
|
);
|
||||||
|
|
||||||
return parent::initView();
|
return parent::initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessSearchCustomers()
|
public function ajaxProcessSearchCustomers()
|
||||||
{
|
{
|
||||||
if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search'))))
|
if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search'))))
|
||||||
@@ -571,11 +665,18 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
foreach ($products AS &$product)
|
foreach ($products AS &$product)
|
||||||
{
|
{
|
||||||
$product['price'] = Tools::displayPrice(Tools::convertPrice($product['price'], $currency), $currency);
|
// 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);
|
$productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id);
|
||||||
$combinations = array();
|
$combinations = array();
|
||||||
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
|
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
|
||||||
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID());
|
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID());
|
||||||
|
// Tax rate for this customer
|
||||||
|
if (Tools::isSubmit('id_address'))
|
||||||
|
$product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
|
||||||
foreach($attributes AS $attribute)
|
foreach($attributes AS $attribute)
|
||||||
{
|
{
|
||||||
if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
|
if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
|
||||||
@@ -584,7 +685,13 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
|
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
|
||||||
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
|
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
|
||||||
if (!isset($combinations[$attribute['id_product_attribute']]['price']))
|
if (!isset($combinations[$attribute['id_product_attribute']]['price']))
|
||||||
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']), $currency), $currency);
|
{
|
||||||
|
$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_incl, $currency), $currency);
|
||||||
|
}
|
||||||
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
|
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->getID());
|
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
|
||||||
}
|
}
|
||||||
@@ -593,8 +700,10 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
|
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
|
||||||
$product['combinations'] = $combinations;
|
$product['combinations'] = $combinations;
|
||||||
}
|
}
|
||||||
$to_return = array('products' => $products,
|
$to_return = array(
|
||||||
'found' => true);
|
'products' => $products,
|
||||||
|
'found' => true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$to_return = array('found' => false);
|
$to_return = array('found' => false);
|
||||||
@@ -623,4 +732,480 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.')));
|
$this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessAddProductOnOrder()
|
||||||
|
{
|
||||||
|
// Load object
|
||||||
|
$order = new Order(Tools::getValue('id_order'));
|
||||||
|
if (!Validate::isLoadedObject($order))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Order object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
$product_informations = $_POST['add_product'];
|
||||||
|
$product = new Product($product_informations['product_id'], false, $order->id_lang);
|
||||||
|
if (!Validate::isLoadedObject($product))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Product object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if (isset($product_informations['product_attribute_id']) && $product_informations['product_attribute_id'])
|
||||||
|
{
|
||||||
|
$combination = new Combination($product_informations['product_attribute_id']);
|
||||||
|
if (!Validate::isLoadedObject($combination))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Combination object')
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new cart
|
||||||
|
$cart = new Cart();
|
||||||
|
$cart->id_group_shop = $order->id_group_shop;
|
||||||
|
$cart->id_shop = $order->id_shop;
|
||||||
|
$cart->id_customer = $order->id_customer;
|
||||||
|
$cart->id_carrier = $order->id_carrier;
|
||||||
|
$cart->id_address_delivery = $order->id_address_delivery;
|
||||||
|
$cart->id_address_invoice = $order->id_address_invoice;
|
||||||
|
$cart->id_currency = $order->id_currency;
|
||||||
|
$cart->id_customer = $order->id_customer;
|
||||||
|
$cart->id_lang = $order->id_lang;
|
||||||
|
$cart->id_carrier = $order->id_carrier;
|
||||||
|
$cart->secure_key = $order->secure_key;
|
||||||
|
|
||||||
|
// Save new cart
|
||||||
|
$cart->add();
|
||||||
|
|
||||||
|
// Save context (in order to apply cart rule)
|
||||||
|
$this->context->cart = $cart;
|
||||||
|
$this->context->customer = new Customer($order->id_customer);
|
||||||
|
|
||||||
|
// Add product to cart
|
||||||
|
$cart->updateQty($product_informations['product_quantity'], $product->id, isset($combination) ? $combination->id : null, false, 'up', new Shop($cart->id_shop));
|
||||||
|
|
||||||
|
$use_taxes = ($order->getTaxCalculationMethod() == PS_TAX_INC);
|
||||||
|
|
||||||
|
$initial_prodcut_price_tax_incl = Product::getPriceStatic($product->id, $use_taxes, isset($combination) ? $combination->id : null, 2, null, false, true, 1,
|
||||||
|
false, $order->id_customer, $cart->id, $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||||
|
|
||||||
|
if ($product_informations['product_price_tax_incl'] < $initial_prodcut_price_tax_incl)
|
||||||
|
{
|
||||||
|
$reduction_tax_incl = $initial_prodcut_price_tax_incl - $product_informations['product_price_tax_incl'];
|
||||||
|
|
||||||
|
// FIXME Cart Rule isn't applied but correctly save in database
|
||||||
|
$cart_rule = new CartRule();
|
||||||
|
$cart_rule->id_customer = $order->id_customer;
|
||||||
|
$cart_rule->date_from = date('Y-m-d H:i:s', time());
|
||||||
|
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
|
||||||
|
$cart_rule->quantity = 1;
|
||||||
|
$cart_rule->quantity_per_user = 1;
|
||||||
|
$cart_rule->minimum_amount_currency = $order->id_currency;
|
||||||
|
$cart_rule->reduction_product = $product->id;
|
||||||
|
$cart_rule->reduction_amount = $reduction_tax_incl;
|
||||||
|
$cart_rule->reduction_currency = $order->id_currency;
|
||||||
|
$cart_rule->active = 1;
|
||||||
|
$cart_rule->add();
|
||||||
|
|
||||||
|
$cart->addCartRule($cart_rule->id);
|
||||||
|
//$order->addCartRule($cart_rule->id, $cart_rule->name, $cart_rule->getContextualValue(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If order is valid, we can create a new invoice or edit an existing invoice
|
||||||
|
if ($order->valid)
|
||||||
|
{
|
||||||
|
$order_invoice = new OrderInvoice($product_informations['invoice']);
|
||||||
|
// Create new invoice
|
||||||
|
if ($order_invoice->id == 0)
|
||||||
|
{
|
||||||
|
// Create Cart rule in order to make free shipping
|
||||||
|
if (isset($invoice_informations['free_shipping']) && $invoice_informations['free_shipping'])
|
||||||
|
{
|
||||||
|
// FIXME Cart Rule isn't applied but correctly save in database
|
||||||
|
$cart_rule = new CartRule();
|
||||||
|
$cart_rule->id_customer = $order->id_customer;
|
||||||
|
$cart_rule->date_from = date('Y-m-d H:i:s', time());
|
||||||
|
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
|
||||||
|
$cart_rule->quantity = 1;
|
||||||
|
$cart_rule->quantity_per_user = 1;
|
||||||
|
$cart_rule->minimum_amount_currency = $order->id_currency;
|
||||||
|
$cart_rule->reduction_currency = $order->id_currency;
|
||||||
|
$cart_rule->free_shipping = true;
|
||||||
|
$cart_rule->active = 1;
|
||||||
|
$cart_rule->add();
|
||||||
|
|
||||||
|
$cart->addCartRule($cart_rule->id);
|
||||||
|
//$order->addCartRule($cart_rule->id, $cart_rule->name, $cart_rule->getContextualValue(true));
|
||||||
|
}
|
||||||
|
if (Tools::isSubmit('add_invoice'))
|
||||||
|
$invoice_informations = $_POST['add_invoice'];
|
||||||
|
$order_invoice->id_order = $order->id;
|
||||||
|
if ($order_invoice->number)
|
||||||
|
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
|
||||||
|
else
|
||||||
|
$order_invoice->number = Order::getLastInvoiceNumber() + 1;
|
||||||
|
$order_invoice->total_paid_tax_excl = Tools::ps_round((float)$cart->getOrderTotal(false, Cart::BOTH), 2);
|
||||||
|
$order_invoice->total_paid_tax_incl = Tools::ps_round((float)$cart->getOrderTotal($use_taxes, Cart::BOTH), 2);
|
||||||
|
$order_invoice->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||||
|
$order_invoice->total_products_wt = (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
|
||||||
|
$order_invoice->total_shipping_tax_excl = (float)$cart->getOrderShippingCost(null, false);
|
||||||
|
$order_invoice->total_shipping_tax_incl = (float)$cart->getOrderShippingCost();
|
||||||
|
$order_invoice->total_wrapping_tax_excl = abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
|
||||||
|
$order_invoice->total_wrapping_tax_incl = abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
|
||||||
|
|
||||||
|
// Update current order field, only shipping because other field is updated later
|
||||||
|
$order->total_shipping += (float)$cart->getOrderShippingCost();
|
||||||
|
$order->total_shipping_tax_excl += (float)$cart->getOrderShippingCost(null, false);
|
||||||
|
$order->total_shipping_tax_incl += (float)$cart->getOrderShippingCost(null, $use_taxes);
|
||||||
|
|
||||||
|
$order->total_wrapping += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
|
||||||
|
$order->total_wrapping_tax_excl += abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
|
||||||
|
$order->total_wrapping_tax_incl += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
|
||||||
|
$order_invoice->add();
|
||||||
|
// Adding an entry in order_carrier table
|
||||||
|
Db::getInstance()->execute('
|
||||||
|
INSERT INTO `'._DB_PREFIX_.'order_carrier` (`id_order`, `id_carrier`, `id_order_invoice`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `date_add`) VALUES
|
||||||
|
('.(int)$order->id.', '.(int)$order->id_carrier.', '.(int)$order_invoice->id.', '.(float)$cart->getTotalWeight().', '.(float)$cart->getOrderShippingCost(null, false).', '.(float)$cart->getOrderShippingCost(null, $use_taxes).', NOW())');
|
||||||
|
}
|
||||||
|
// Update current invoice
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$order_invoice->total_paid_tax_excl += Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH)), 2);
|
||||||
|
$order_invoice->total_paid_tax_incl += Tools::ps_round((float)($cart->getOrderTotal($use_taxes, Cart::BOTH)), 2);
|
||||||
|
$order_invoice->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||||
|
$order_invoice->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
|
||||||
|
$order_invoice->total_shipping_tax_excl += (float)$cart->getOrderShippingCost(null, false);
|
||||||
|
$order_invoice->total_shipping_tax_incl += (float)$cart->getOrderShippingCost(null, $use_taxes);
|
||||||
|
$order_invoice->total_wrapping_tax_excl += abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
|
||||||
|
$order_invoice->total_wrapping_tax_incl += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
|
||||||
|
$order_invoice->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Order detail information
|
||||||
|
$order_detail = new OrderDetail();
|
||||||
|
$order_detail->createList($order, $cart, OrderHistory::getLastOrderState($order->id), $cart->getProducts(), (isset($order_invoice) ? $order_invoice->id : 0), $use_taxes);
|
||||||
|
|
||||||
|
// update totals amount of order
|
||||||
|
$order->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||||
|
$order->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
|
||||||
|
|
||||||
|
$order->total_paid += Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
|
||||||
|
$order->total_paid_tax_excl += Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH)), 2);
|
||||||
|
$order->total_paid_tax_incl += Tools::ps_round((float)($cart->getOrderTotal($use_taxes, Cart::BOTH)), 2);
|
||||||
|
|
||||||
|
// Save changes of order
|
||||||
|
$order->update();
|
||||||
|
|
||||||
|
$products = $this->getProducts($order);
|
||||||
|
// Get the last product
|
||||||
|
$product = $products[max(array_keys($products))];
|
||||||
|
|
||||||
|
// Assign to smarty informations in order to show the new product line
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'product' => $product,
|
||||||
|
'order' => $order,
|
||||||
|
'currency' => new Currency($order->id_currency),
|
||||||
|
'can_edit' => $this->tabAccess['edit'],
|
||||||
|
'invoices_collection' => $order->getInvoicesCollection()
|
||||||
|
));
|
||||||
|
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => true,
|
||||||
|
'view' => $this->context->smarty->fetch('orders/_product_line.tpl'),
|
||||||
|
'can_edit' => $this->tabAccess['add'],
|
||||||
|
'order' => $order
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessLoadProductInformation()
|
||||||
|
{
|
||||||
|
$order_detail = new OrderDetail(Tools::getValue('id_order_detail'));
|
||||||
|
if (!Validate::isLoadedObject($order_detail))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load OrderDetail object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
$product = new Product($order_detail->product_id);
|
||||||
|
if (!Validate::isLoadedObject($product))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Product object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
$address = new Address(Tools::getValue('id_address'));
|
||||||
|
if (!Validate::isLoadedObject($address))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Address object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => true,
|
||||||
|
'product' => $product,
|
||||||
|
'tax_rate' => $product->getTaxesRate($address),
|
||||||
|
'price_tax_incl' => Product::getPriceStatic($product->id, true, $order_detail->product_attribute_id, 2),
|
||||||
|
'price_tax_excl' => Product::getPriceStatic($product->id, false, $order_detail->product_attribute_id, 2)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessEditProductOnOrder()
|
||||||
|
{
|
||||||
|
// Return value
|
||||||
|
$res = true;
|
||||||
|
|
||||||
|
$order_detail = new OrderDetail(Tools::getValue('product_id_order_detail'));
|
||||||
|
if (Tools::isSubmit('product_invoice'))
|
||||||
|
$order_invoice = new OrderInvoice(Tools::getValue('product_invoice'));
|
||||||
|
|
||||||
|
$this->doEditProductValidation($order_detail, isset($order_invoice) ? $order_invoice : null);
|
||||||
|
|
||||||
|
$product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);
|
||||||
|
$product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);
|
||||||
|
$total_products_tax_incl = $product_price_tax_incl * Tools::getValue('product_quantity');
|
||||||
|
$total_products_tax_excl = $product_price_tax_excl * Tools::getValue('product_quantity');
|
||||||
|
|
||||||
|
// Calculate differences of price (Before / After)
|
||||||
|
$diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;
|
||||||
|
$diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;
|
||||||
|
|
||||||
|
// Apply change on OrderInvoice
|
||||||
|
if (isset($order_invoice))
|
||||||
|
// If OrderInvoice to use is different, we update the old invoice and new invoice
|
||||||
|
if ($order_detail->id_order_invoice != $order_invoice->id)
|
||||||
|
{
|
||||||
|
$old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);
|
||||||
|
// We remove cost of products
|
||||||
|
$old_order_invoice->total_products -= $order_detail->total_price_tax_excl;
|
||||||
|
$old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
|
||||||
|
|
||||||
|
$old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
|
||||||
|
$old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
|
||||||
|
|
||||||
|
$res &= $old_order_invoice->update();
|
||||||
|
// TODO remove invoice if no item ?
|
||||||
|
|
||||||
|
$order_invoice->total_products += $order_detail->total_price_tax_excl;
|
||||||
|
$order_invoice->total_products_wt += $order_detail->total_price_tax_incl;
|
||||||
|
|
||||||
|
$order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl;
|
||||||
|
$order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl;
|
||||||
|
|
||||||
|
$order_detail->id_order_invoice = $order_invoice->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0)
|
||||||
|
{
|
||||||
|
$order_detail->unit_price_tax_excl = $product_price_tax_excl;
|
||||||
|
$order_detail->unit_price_tax_incl = $product_price_tax_incl;
|
||||||
|
|
||||||
|
$order_detail->total_price_tax_incl += $diff_price_tax_incl;
|
||||||
|
$order_detail->total_price_tax_excl += $diff_price_tax_excl;
|
||||||
|
|
||||||
|
if (isset($order_invoice))
|
||||||
|
{
|
||||||
|
// Apply changes on OrderInvoice
|
||||||
|
$order_invoice->total_products += $diff_price_tax_excl;
|
||||||
|
$order_invoice->total_products_wt += $diff_price_tax_incl;
|
||||||
|
|
||||||
|
$order_invoice->total_paid_tax_excl += $diff_price_tax_excl;
|
||||||
|
$order_invoice->total_paid_tax_incl += $diff_price_tax_incl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply changes on Order
|
||||||
|
$order = new Order($order_detail->id_order);
|
||||||
|
$order->total_products += $diff_price_tax_excl;
|
||||||
|
$order->total_products_wt += $diff_price_tax_incl;
|
||||||
|
|
||||||
|
$order->total_paid += $diff_price_tax_incl;
|
||||||
|
$order->total_paid_tax_excl += $diff_price_tax_excl;
|
||||||
|
$order->total_paid_tax_incl += $diff_price_tax_incl;
|
||||||
|
|
||||||
|
$res &= $order->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$order_detail->product_quantity = Tools::getValue('product_quantity');
|
||||||
|
// Save order detail
|
||||||
|
$res &= $order_detail->update();
|
||||||
|
// Save order invoice
|
||||||
|
if (isset($order_invoice))
|
||||||
|
$res &= $order_invoice->update();
|
||||||
|
|
||||||
|
$products = $this->getProducts($order);
|
||||||
|
// Get the last product
|
||||||
|
$product = $products[$order_detail->id];
|
||||||
|
|
||||||
|
// Assign to smarty informations in order to show the new product line
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'product' => $product,
|
||||||
|
'order' => $order,
|
||||||
|
'currency' => new Currency($order->id_currency),
|
||||||
|
'can_edit' => $this->tabAccess['edit']
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!$res)
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => $res,
|
||||||
|
'error' => Tools::displayError('Error occured on edition of this product line')
|
||||||
|
)));
|
||||||
|
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => $res,
|
||||||
|
'view' => $this->context->smarty->fetch('orders/_product_line.tpl'),
|
||||||
|
'can_edit' => $this->tabAccess['add'],
|
||||||
|
'invoices_collection' => $order->getInvoicesCollection(),
|
||||||
|
'order' => $order
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessDeleteProductLine()
|
||||||
|
{
|
||||||
|
$res = true;
|
||||||
|
|
||||||
|
$order_detail = new OrderDetail(Tools::getValue('id_order_detail'));
|
||||||
|
$order = new Order(Tools::getValue('id_order'));
|
||||||
|
|
||||||
|
$this->doDeleteProductLinveValidation($order_detail, $order);
|
||||||
|
|
||||||
|
// Update OrderInvoice of this OrderDetail
|
||||||
|
if ($order_detail->id_order_invoice != 0)
|
||||||
|
{
|
||||||
|
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO refresh total_discount
|
||||||
|
$order_invoice->total_discount_tax_excl -= ;
|
||||||
|
$order_invoice->total_discount_tax_incl -= ;
|
||||||
|
$order_invoice->total_shipping_tax_excl -= ;
|
||||||
|
$order_invoice->total_shipping_tax_incl -= ;
|
||||||
|
$order_invoice->total_wrapping_tax_excl -= ;
|
||||||
|
$order_invoice->total_wrapping_tax_incl -= ;
|
||||||
|
*/
|
||||||
|
$order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_incl;
|
||||||
|
$order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_excl;
|
||||||
|
$order_invoice->total_products -= $order_detail->total_price_tax_incl;
|
||||||
|
$order_invoice->total_products_wt -= $order_detail->total_price_tax_excl;
|
||||||
|
$res &= $order_invoice->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Order
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
$order->total_discounts -= ;
|
||||||
|
$order->total_discounts_tax_incl -= ;
|
||||||
|
$order->total_discounts_tax_excl -= ;
|
||||||
|
$order->total_discounts_tax_excl -= ;
|
||||||
|
$order->total_shipping -= ;
|
||||||
|
$order->total_shipping_tax_incl -= ;
|
||||||
|
$order->total_shipping_tax_excl -= ;
|
||||||
|
$order->total_wrapping -= ;
|
||||||
|
$order->total_wrapping_tax_incl -= ;
|
||||||
|
$order->total_wrapping_tax_excl -= ;
|
||||||
|
*/
|
||||||
|
$order->total_paid -= $order_detail->total_price_tax_incl;
|
||||||
|
$order->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
|
||||||
|
$order->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
|
||||||
|
$order->total_products -= $order_detail->total_price_tax_incl;
|
||||||
|
$order->total_products_wt -= $order_detail->total_price_tax_excl;
|
||||||
|
|
||||||
|
$res &= $order->update();
|
||||||
|
|
||||||
|
// Delete OrderDetail
|
||||||
|
$res &= $order_detail->delete();
|
||||||
|
|
||||||
|
if (!$res)
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => $res,
|
||||||
|
'error' => Tools::displayError('Error occured on deletion of this product line')
|
||||||
|
)));
|
||||||
|
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => $res,
|
||||||
|
'order' => $order
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doEditProductValidation(OrderDetail $order_detail, OrderInvoice $order_invoice = null)
|
||||||
|
{
|
||||||
|
if (!Validate::isLoadedObject($order_detail))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Order Detail object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if (!empty($order_invoice) && !Validate::isLoadedObject($order_invoice))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Invoice object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if ($order_detail->id_order != Tools::getValue('id_order'))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t edit this Order Detail for this order')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if ($order_invoice->id_order != Tools::getValue('id_order'))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t use this invoice for this order')
|
||||||
|
)));
|
||||||
|
|
||||||
|
// Clean price
|
||||||
|
$product_price_tax_incl = str_replace(',', '.', Tools::getValue('product_price_tax_incl'));
|
||||||
|
$product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl'));
|
||||||
|
|
||||||
|
if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Invalid price')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if (!Validate::isUnsignedInt(Tools::getValue('product_quantity')))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Invalid quantity')
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doDeleteProductLinveValidation(OrderDetail $order_detail, Order $order)
|
||||||
|
{
|
||||||
|
if (!Validate::isLoadedObject($order_detail))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Order Detail object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if (!Validate::isLoadedObject($order))
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t load Order object')
|
||||||
|
)));
|
||||||
|
|
||||||
|
if ($order_detail->id_order != $order->id)
|
||||||
|
die(Tools::jsonEncode(array(
|
||||||
|
'result' => false,
|
||||||
|
'error' => Tools::displayError('Can\'t delete this Order Detail for this order')
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProducts($order)
|
||||||
|
{
|
||||||
|
$products = $order->getProducts();
|
||||||
|
|
||||||
|
foreach ($products as &$product)
|
||||||
|
{
|
||||||
|
if ($product['image'] != null)
|
||||||
|
{
|
||||||
|
$name = 'product_mini_'.(int)$product['product_id'].(isset($product['product_attribute_id']) ? '_'.(int)$product['product_attribute_id'] : '').'.jpg';
|
||||||
|
// generate image cache, only for back office
|
||||||
|
$product['image_tag'] = cacheImage(_PS_IMG_DIR_.'p/'.$product['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg');
|
||||||
|
$product['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $products;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1912,8 +1912,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
|
|
||||||
public function getPreviewUrl(Product $product)
|
public function getPreviewUrl(Product $product)
|
||||||
{
|
{
|
||||||
$shop_url = new ShopUrl($this->context->shop->id);
|
if (!(bool)$this->context->shop->virtual_uri)
|
||||||
if (!$shop_url->id && !empty($this->context->cookie->shopContext))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$preview_url = $this->context->link->getProductLink(
|
$preview_url = $this->context->link->getProductLink(
|
||||||
|
|||||||
+44
-4
@@ -1047,16 +1047,36 @@ CREATE TABLE `PREFIX_orders` (
|
|||||||
INDEX `date_add`(`date_add`)
|
INDEX `date_add`(`date_add`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `PREFIX_order_detail_tax` (
|
CREATE TABLE `PREFIX_order_detail_tax` (
|
||||||
`id_order_detail` int(11) NOT NULL,
|
`id_order_detail` int(11) NOT NULL,
|
||||||
`id_tax` int(11) NOT NULL,
|
`id_tax` int(11) NOT NULL,
|
||||||
`unit_amount` DECIMAL( 10,6 ) NOT NULL default '0.00',
|
`unit_amount` DECIMAL( 10,6 ) NOT NULL default '0.00',
|
||||||
`total_amount` DECIMAL( 10, 6 ) NOT NULL default '0.00'
|
`total_amount` DECIMAL( 10, 6 ) NOT NULL default '0.00'
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
CREATE TABLE `PREFIX_order_invoice` (
|
||||||
|
`id_order_invoice` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_order` int(11) NOT NULL,
|
||||||
|
`number` int(11) NOT NULL,
|
||||||
|
`total_discount_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_discount_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_paid_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_paid_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_products` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_products_wt` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_shipping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_shipping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_wrapping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_wrapping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`date_add` datetime NOT NULL,
|
||||||
|
PRIMARY KEY (`id_order_invoice`),
|
||||||
|
KEY `id_order` (`id_order`)
|
||||||
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `PREFIX_order_detail` (
|
CREATE TABLE `PREFIX_order_detail` (
|
||||||
`id_order_detail` int(10) unsigned NOT NULL auto_increment,
|
`id_order_detail` int(10) unsigned NOT NULL auto_increment,
|
||||||
`id_order` int(10) unsigned NOT NULL,
|
`id_order` int(10) unsigned NOT NULL,
|
||||||
|
`id_order_invoice` int(11) default NULL,
|
||||||
`product_id` int(10) unsigned NOT NULL,
|
`product_id` int(10) unsigned NOT NULL,
|
||||||
`product_attribute_id` int(10) unsigned default NULL,
|
`product_attribute_id` int(10) unsigned default NULL,
|
||||||
`product_name` varchar(255) NOT NULL,
|
`product_name` varchar(255) NOT NULL,
|
||||||
@@ -1183,6 +1203,8 @@ CREATE TABLE `PREFIX_order_slip` (
|
|||||||
`id_customer` int(10) unsigned NOT NULL,
|
`id_customer` int(10) unsigned NOT NULL,
|
||||||
`id_order` int(10) unsigned NOT NULL,
|
`id_order` int(10) unsigned NOT NULL,
|
||||||
`shipping_cost` tinyint(3) unsigned NOT NULL default '0',
|
`shipping_cost` tinyint(3) unsigned NOT NULL default '0',
|
||||||
|
`amount` DECIMAL(10,2) NOT NULL,
|
||||||
|
`shipping_cost_amount` DECIMAL(10,2) NOT NULL,
|
||||||
`date_add` datetime NOT NULL,
|
`date_add` datetime NOT NULL,
|
||||||
`date_upd` datetime NOT NULL,
|
`date_upd` datetime NOT NULL,
|
||||||
PRIMARY KEY (`id_order_slip`),
|
PRIMARY KEY (`id_order_slip`),
|
||||||
@@ -1194,6 +1216,7 @@ CREATE TABLE `PREFIX_order_slip_detail` (
|
|||||||
`id_order_slip` int(10) unsigned NOT NULL,
|
`id_order_slip` int(10) unsigned NOT NULL,
|
||||||
`id_order_detail` int(10) unsigned NOT NULL,
|
`id_order_detail` int(10) unsigned NOT NULL,
|
||||||
`product_quantity` int(10) unsigned NOT NULL default '0',
|
`product_quantity` int(10) unsigned NOT NULL default '0',
|
||||||
|
`amount` DECIMAL(10,2) NOT NULL,
|
||||||
PRIMARY KEY (`id_order_slip`,`id_order_detail`)
|
PRIMARY KEY (`id_order_slip`,`id_order_detail`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@@ -1250,18 +1273,21 @@ CREATE TABLE `PREFIX_page_viewed` (
|
|||||||
PRIMARY KEY (`id_page`, `id_date_range`, `id_shop`)
|
PRIMARY KEY (`id_page`, `id_date_range`, `id_shop`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `PREFIX_payment_cc` (
|
CREATE TABLE `PREFIX_order_payment` (
|
||||||
`id_payment_cc` INT NOT NULL auto_increment,
|
`id_order_payment` INT NOT NULL auto_increment,
|
||||||
|
`id_order_invoice` INT UNSIGNED NULL,
|
||||||
`id_order` INT UNSIGNED NULL,
|
`id_order` INT UNSIGNED NULL,
|
||||||
`id_currency` INT UNSIGNED NOT NULL,
|
`id_currency` INT UNSIGNED NOT NULL,
|
||||||
`amount` DECIMAL(10,2) NOT NULL,
|
`amount` DECIMAL(10,2) NOT NULL,
|
||||||
|
`payment_method` varchar(255) NOT NULL,
|
||||||
|
`conversion_rate` decimal(13,6) NOT NULL DEFAULT 1,
|
||||||
`transaction_id` VARCHAR(254) NULL,
|
`transaction_id` VARCHAR(254) NULL,
|
||||||
`card_number` VARCHAR(254) NULL,
|
`card_number` VARCHAR(254) NULL,
|
||||||
`card_brand` VARCHAR(254) NULL,
|
`card_brand` VARCHAR(254) NULL,
|
||||||
`card_expiration` CHAR(7) NULL,
|
`card_expiration` CHAR(7) NULL,
|
||||||
`card_holder` VARCHAR(254) NULL,
|
`card_holder` VARCHAR(254) NULL,
|
||||||
`date_add` DATETIME NOT NULL,
|
`date_add` DATETIME NOT NULL,
|
||||||
PRIMARY KEY (`id_payment_cc`),
|
PRIMARY KEY (`id_order_payment`),
|
||||||
KEY `id_order` (`id_order`)
|
KEY `id_order` (`id_order`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@@ -2245,3 +2271,17 @@ CREATE TABLE `PREFIX_accounting_product_zone_shop` (
|
|||||||
PRIMARY KEY (`id_accounting_product_zone_shop`),
|
PRIMARY KEY (`id_accounting_product_zone_shop`),
|
||||||
UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`)
|
UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
CREATE TABLE `PREFIX_order_carrier` (
|
||||||
|
`id_order` int(11) unsigned NOT NULL,
|
||||||
|
`id_carrier` int(11) unsigned NOT NULL,
|
||||||
|
`id_order_invoice` int(11) unsigned DEFAULT NULL,
|
||||||
|
`weight` float DEFAULT NULL,
|
||||||
|
`shipping_cost_tax_excl` decimal(20,6) DEFAULT NULL,
|
||||||
|
`shipping_cost_tax_incl` decimal(20,6) DEFAULT NULL,
|
||||||
|
`tracking_number` int(11) unsigned DEFAULT NULL,
|
||||||
|
`date_add` datetime NOT NULL,
|
||||||
|
KEY `id_order` (`id_order`,`id_carrier`),
|
||||||
|
KEY `id_order_2` (`id_order`),
|
||||||
|
KEY `id_order_invoice` (`id_order_invoice`)
|
||||||
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|||||||
@@ -180,8 +180,11 @@ INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`,
|
|||||||
VALUES (1, 1, 7, 23, 'iPod touch - Capacité: 32Go', 1, 0, '392.140500', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
|
VALUES (1, 1, 7, 23, 'iPod touch - Capacité: 32Go', 1, 0, '392.140500', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
|
||||||
INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_return`, `product_price`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `ecotax`, `download_hash`, `download_nb`, `download_deadline`, `tax_name`)
|
INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_return`, `product_price`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `ecotax`, `download_hash`, `download_nb`, `download_deadline`, `tax_name`)
|
||||||
VALUES (2, 1, 9, 0, 'Écouteurs à isolation sonore Shure SE210', 1, 0, '124.581900', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
|
VALUES (2, 1, 9, 0, 'Écouteurs à isolation sonore Shure SE210', 1, 0, '124.581900', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
|
||||||
|
|
||||||
INSERT INTO `PREFIX_order_history` (`id_order_history`, `id_employee`, `id_order`, `id_order_state`, `date_add`) VALUES (1, 0, 1, 1, NOW());
|
INSERT INTO `PREFIX_order_history` (`id_order_history`, `id_employee`, `id_order`, `id_order_state`, `date_add`) VALUES (1, 0, 1, 1, NOW());
|
||||||
|
|
||||||
|
INSERT INTO `PREFIX_order_payment` (`id_order`, `id_currency`, `amount`, `payment_method`, `date_add`) VALUES (1, 1, '625.98', 'Chèque', NOW());
|
||||||
|
|
||||||
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES (1, 'Apple Computer, Inc', NOW(), NOW(), 1);
|
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES (1, 'Apple Computer, Inc', NOW(), NOW(), 1);
|
||||||
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES(2, 'Shure Incorporated', NOW(), NOW(), 1);
|
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES(2, 'Shure Incorporated', NOW(), NOW(), 1);
|
||||||
|
|
||||||
@@ -1367,3 +1370,6 @@ INSERT INTO `PREFIX_stock_available` (`id_stock_available`, `id_product`, `id_pr
|
|||||||
(28, 6, 0, 1, 4, 0, 2),
|
(28, 6, 0, 1, 4, 0, 2),
|
||||||
(29, 8, 0, 1, 8, 0, 2),
|
(29, 8, 0, 1, 8, 0, 2),
|
||||||
(30, 9, 0, 1, 15, 0, 2);
|
(30, 9, 0, 1, 15, 0, 2);
|
||||||
|
|
||||||
|
INSERT INTO `PREFIX_order_carrier` (`id_order`, `id_carrier`, `date_add`) VALUES
|
||||||
|
(1, 2, NOW());
|
||||||
|
|||||||
@@ -239,6 +239,33 @@ ALTER TABLE `PREFIX_carrier` ADD `position` INT( 10 ) UNSIGNED NOT NULL DEFAULT
|
|||||||
ALTER TABLE `PREFIX_order_state` ADD COLUMN `shipped` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `delivery`;
|
ALTER TABLE `PREFIX_order_state` ADD COLUMN `shipped` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `delivery`;
|
||||||
UPDATE `PREFIX_order_state` SET `shipped` = 1 WHERE id_order_states IN (4, 5);
|
UPDATE `PREFIX_order_state` SET `shipped` = 1 WHERE id_order_states IN (4, 5);
|
||||||
|
|
||||||
|
CREATE TABLE `PREFIX_order_invoice` (
|
||||||
|
`id_order_invoice` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_order` int(11) NOT NULL,
|
||||||
|
`number` int(11) NOT NULL,
|
||||||
|
`total_discount_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_discount_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_paid_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_paid_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_products` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_products_wt` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_shipping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_shipping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_wrapping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`total_wrapping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
|
||||||
|
`date_add` datetime NOT NULL,
|
||||||
|
PRIMARY KEY (`id_order_invoice`),
|
||||||
|
KEY `id_order` (`id_order`)
|
||||||
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_order_detail` ADD `id_order_invoice` int(11) NULL AFTER `id_order`;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_payment_cc` CHANGE `id_payment_cc` `id_order_payment` INT NOT NULL auto_increment;
|
||||||
|
ALTER TABLE `PREFIX_payment_cc` ADD `id_order_invoice` varchar(255) NOT NULL AFTER `id_order_payment`;
|
||||||
|
ALTER TABLE `PREFIX_payment_cc` ADD `payment_method` varchar(255) NOT NULL AFTER `amount`;
|
||||||
|
ALTER TABLE `PREFIX_payment_cc` ADD `conversion_rate` decimal(13,6) NOT NULL DEFAULT 1 AFTER `payment_method`;
|
||||||
|
|
||||||
|
RENAME TABLE `PREFIX_payment_cc` TO `PREFIX_order_payment`;
|
||||||
|
|
||||||
ALTER TABLE `PREFIX_carrier`
|
ALTER TABLE `PREFIX_carrier`
|
||||||
ADD COLUMN `max_width` int(10) DEFAULT 0 AFTER `position`,
|
ADD COLUMN `max_width` int(10) DEFAULT 0 AFTER `position`,
|
||||||
@@ -264,7 +291,6 @@ ALTER TABLE `PREFIX_customization` ADD COLUMN `id_address_delivery` int(10) UNSI
|
|||||||
DROP PRIMARY KEY,
|
DROP PRIMARY KEY,
|
||||||
ADD PRIMARY KEY USING BTREE(`id_customization`, `id_cart`, `id_product`, `id_address_delivery`);
|
ADD PRIMARY KEY USING BTREE(`id_customization`, `id_cart`, `id_product`, `id_address_delivery`);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `PREFIX_cart_rule` (
|
CREATE TABLE `PREFIX_cart_rule` (
|
||||||
`id_cart_rule` int(10) unsigned NOT NULL auto_increment,
|
`id_cart_rule` int(10) unsigned NOT NULL auto_increment,
|
||||||
`id_customer` int unsigned NOT NULL default 0,
|
`id_customer` int unsigned NOT NULL default 0,
|
||||||
@@ -581,4 +607,22 @@ UPDATE `PREFIX_employee` SET `bo_theme` = 'default';
|
|||||||
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsContent' WHERE `class_name` = 'AdminCMSContent';
|
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsContent' WHERE `class_name` = 'AdminCMSContent';
|
||||||
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCms' WHERE `class_name` = 'AdminCMS';
|
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCms' WHERE `class_name` = 'AdminCMS';
|
||||||
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsCategories' WHERE `class_name` = 'AdminCMSCategories';
|
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsCategories' WHERE `class_name` = 'AdminCMSCategories';
|
||||||
UPDATE `PREFIX_tab` SET `class_name` = 'AdminPdf' WHERE `class_name` = 'AdminPDF';
|
UPDATE `PREFIX_tab` SET `class_name` = 'AdminPdf' WHERE `class_name` = 'AdminPDF';
|
||||||
|
|
||||||
|
CREATE TABLE `PREFIX_order_carrier` (
|
||||||
|
`id_order` int(11) unsigned NOT NULL,
|
||||||
|
`id_carrier` int(11) unsigned NOT NULL,
|
||||||
|
`id_order_invoice` int(11) unsigned DEFAULT NULL,
|
||||||
|
`weight` float DEFAULT NULL,
|
||||||
|
`shipping_cost_tax_excl` decimal(20,6) DEFAULT NULL,
|
||||||
|
`shipping_cost_tax_incl` decimal(20,6) DEFAULT NULL,
|
||||||
|
`tracking_number` int(11) unsigned DEFAULT NULL,
|
||||||
|
`date_add` datetime NOT NULL,
|
||||||
|
KEY `id_order` (`id_order`,`id_carrier`),
|
||||||
|
KEY `id_order_2` (`id_order`),
|
||||||
|
KEY `id_order_invoice` (`id_order_invoice`)
|
||||||
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_order_slip` ADD COLUMN `amount` DECIMAL(10,2) NOT NULL AFTER `shipping_cost`;
|
||||||
|
ALTER TABLE `PREFIX_order_slip` ADD COLUMN `shipping_cost_amount` DECIMAL(10,2) NOT NULL AFTER `amount`;
|
||||||
|
ALTER TABLE `PREFIX_order_slip_detail` ADD COLUMN `amount` DECIMAL(10,2) NOT NULL AFTER `product_quantity`;
|
||||||
|
|||||||
@@ -0,0 +1,621 @@
|
|||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/afl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 10575 $
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
var current_product = null;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.add_product').click(function() {
|
||||||
|
$('.cancel_product_change_link:visible').trigger('click');
|
||||||
|
$('tr#new_product').slideDown('fast', function () {
|
||||||
|
$('tr#new_product td').fadeIn('fast');
|
||||||
|
});
|
||||||
|
|
||||||
|
$.scrollTo('tr#new_product', 1200, {offset: -100});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#add_product_product_name").autocomplete(admin_order_tab_link,
|
||||||
|
{
|
||||||
|
minChars: 3,
|
||||||
|
max: 10,
|
||||||
|
width: 500,
|
||||||
|
selectFirst: false,
|
||||||
|
scroll: false,
|
||||||
|
dataType: "json",
|
||||||
|
highlightItem: true,
|
||||||
|
formatItem: function(data, i, max, value, term) {
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
parse: function(data) {
|
||||||
|
var products = new Array();
|
||||||
|
for (var i = 0; i < data.products.length; i++)
|
||||||
|
products[i] = { data: data.products[i], value: data.products[i].name };
|
||||||
|
return products;
|
||||||
|
},
|
||||||
|
extraParams: {
|
||||||
|
ajax: true,
|
||||||
|
token: token,
|
||||||
|
action: 'searchProducts',
|
||||||
|
id_lang: id_lang,
|
||||||
|
id_currency: id_currency,
|
||||||
|
id_address: id_address,
|
||||||
|
product_search: function() { return $('#add_product_product_name').val(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.result(function(event, data, formatted) {
|
||||||
|
if (!data)
|
||||||
|
{
|
||||||
|
$('tr#new_product input, tr#new_product select').each(function() {
|
||||||
|
if ($(this).attr('id') != 'add_product_product_name')
|
||||||
|
$('tr#new_product input, tr#new_product select').attr('disabled', 'disabled');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$('tr#new_product input, tr#new_product select').removeAttr('disabled');
|
||||||
|
// Keep product variable
|
||||||
|
current_product = data;
|
||||||
|
$('#add_product_product_id').val(data.id_product);
|
||||||
|
$('#add_product_product_name').val(data.name);
|
||||||
|
$('#add_product_product_price_tax_incl').val(data.price_tax_incl);
|
||||||
|
$('#add_product_product_price_tax_excl').val(data.price_tax_excl);
|
||||||
|
addProductRefreshTotal();
|
||||||
|
$('#add_product_product_stock').html(data.qty_in_stock);
|
||||||
|
|
||||||
|
if (current_product.combinations.length !== 0)
|
||||||
|
{
|
||||||
|
// Reset combinations list
|
||||||
|
$('select#add_product_product_attribute_id').html('');
|
||||||
|
$.each(current_product.combinations, function() {
|
||||||
|
$('select#add_product_product_attribute_id').append('<option value="'+this.id_product_attribute+'"'+(this.default_on == 1 ? ' selected="selected"' : '')+'>'+this.attributes+'</option>');
|
||||||
|
if (this.default_on == 1)
|
||||||
|
$('#add_product_product_stock').html(this.qty_in_stock);
|
||||||
|
});
|
||||||
|
// Show select list
|
||||||
|
$('#add_product_product_attribute_area').show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Reset combinations list
|
||||||
|
$('select#add_product_product_attribute_id').html('');
|
||||||
|
// Hide select list
|
||||||
|
$('#add_product_product_attribute_area').hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('select#add_product_product_attribute_id').change(function() {
|
||||||
|
$('#add_product_product_price_tax_incl').val(current_product.combinations[$(this).val()].price_tax_incl);
|
||||||
|
$('#add_product_product_price_tax_excl').val(current_product.combinations[$(this).val()].price_tax_excl);
|
||||||
|
|
||||||
|
addProductRefreshTotal();
|
||||||
|
|
||||||
|
$('#add_product_product_stock').html(current_product.combinations[$(this).val()].qty_in_stock);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('input#add_product_product_quantity').keyup(function() {
|
||||||
|
var quantity = parseInt($(this).val());
|
||||||
|
if (quantity < 1 || isNaN(quantity))
|
||||||
|
quantity = 1;
|
||||||
|
var stock_available = parseInt($('#add_product_product_stock').html());
|
||||||
|
// total update
|
||||||
|
addProductRefreshTotal();
|
||||||
|
|
||||||
|
// stock status update
|
||||||
|
if (quantity > stock_available)
|
||||||
|
$('#add_product_product_stock').css('font-weight', 'bold').css('color', 'red').css('font-size', '1.2em');
|
||||||
|
else
|
||||||
|
$('#add_product_product_stock').css('font-weight', 'normal').css('color', 'black').css('font-size', '1em');;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#submitAddProduct').click(function() {
|
||||||
|
var go = true;
|
||||||
|
|
||||||
|
if ($('input#add_product_product_id').val() == 0)
|
||||||
|
{
|
||||||
|
alert(txt_add_product_no_product);
|
||||||
|
go = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('input#add_product_product_quantity').val() == 0)
|
||||||
|
{
|
||||||
|
alert(txt_add_product_no_product_quantity);
|
||||||
|
go = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('input#add_product_product_price_excl').val() == 0)
|
||||||
|
{
|
||||||
|
alert(txt_add_product_no_product_price);
|
||||||
|
go = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (go)
|
||||||
|
{
|
||||||
|
if (parseInt($('input#add_product_product_quantity').val()) > parseInt($('#add_product_product_stock').html()))
|
||||||
|
go = confirm(txt_add_product_stock_issue);
|
||||||
|
|
||||||
|
if (go && $('select#add_product_product_invoice').val() == 0)
|
||||||
|
go = confirm(txt_add_product_new_invoice);
|
||||||
|
|
||||||
|
if (go)
|
||||||
|
{
|
||||||
|
var query = 'ajax=1&token='+token+'&action=addProductOnOrder&id_order='+id_order+'&';
|
||||||
|
|
||||||
|
query += $('tr#new_product select, tr#new_product input').serialize();
|
||||||
|
if ($('select#add_product_product_invoice').val() == 0)
|
||||||
|
query += '&'+$('tr#new_invoice select, tr#new_invoice input').serialize();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: admin_order_tab_link,
|
||||||
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
|
data : query,
|
||||||
|
success : function(data)
|
||||||
|
{
|
||||||
|
if (data.result)
|
||||||
|
{
|
||||||
|
addViewOrderDetailRow(data.view);
|
||||||
|
updateAmounts(data.order);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#edit_shipping_cost_link').click(function() {
|
||||||
|
$('#shipping_cost_show').hide();
|
||||||
|
$('#shipping_cost_edit').show();
|
||||||
|
|
||||||
|
$('#edit_shipping_cost_link').hide();
|
||||||
|
$('#cancel_shipping_cost_link').show();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#cancel_shipping_cost_link').click(function() {
|
||||||
|
$('#shipping_cost_show').show();
|
||||||
|
$('#shipping_cost_edit').hide();
|
||||||
|
|
||||||
|
$('#edit_shipping_cost_link').show();
|
||||||
|
$('#cancel_shipping_cost_link').hide();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.edit_shipping_number_link').click(function() {
|
||||||
|
$(this).parent().find('.shipping_number_show').hide();
|
||||||
|
$(this).parent().find('.shipping_number_edit').show();
|
||||||
|
|
||||||
|
$(this).parent().find('.edit_shipping_number_link').hide();
|
||||||
|
$(this).parent().find('.cancel_shipping_number_link').show();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.cancel_shipping_number_link').click(function() {
|
||||||
|
$(this).parent().find('.shipping_number_show').show();
|
||||||
|
$(this).parent().find('.shipping_number_edit').hide();
|
||||||
|
|
||||||
|
$(this).parent().find('.edit_shipping_number_link').show();
|
||||||
|
$(this).parent().find('.cancel_shipping_number_link').hide();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add_product_product_invoice').change(function() {
|
||||||
|
if ($(this).val() == '0')
|
||||||
|
$('#new_invoice').slideDown('slow');
|
||||||
|
else
|
||||||
|
$('#new_invoice').slideUp('slow');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add_product_product_price_tax_excl').keyup(function() {
|
||||||
|
var price_tax_excl = parseFloat($(this).val());
|
||||||
|
if (price_tax_excl < 0 || isNaN(price_tax_excl))
|
||||||
|
price_tax_excl = 0;
|
||||||
|
|
||||||
|
var tax_rate = current_product.tax_rate / 100 + 1;
|
||||||
|
$('#add_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2));
|
||||||
|
|
||||||
|
// Update total product
|
||||||
|
addProductRefreshTotal();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add_product_product_price_tax_incl').keyup(function() {
|
||||||
|
var price_tax_incl = parseFloat($(this).val());
|
||||||
|
if (price_tax_incl < 0 || isNaN(price_tax_incl))
|
||||||
|
price_tax_incl = 0;
|
||||||
|
|
||||||
|
var tax_rate = current_product.tax_rate / 100 + 1;
|
||||||
|
$('#add_product_product_price_tax_excl').val(ps_round(price_tax_incl / tax_rate, 2));
|
||||||
|
|
||||||
|
// Update total product
|
||||||
|
addProductRefreshTotal();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.edit_product_change_link').click(function() {
|
||||||
|
$('.cancel_product_change_link:visible').trigger('click');
|
||||||
|
closeAddProduct();
|
||||||
|
|
||||||
|
query = 'ajax=1&token='+token+'&action=loadProductInformation&id_order_detail='+
|
||||||
|
$(this).parent().parent().find('input.edit_product_id_order_detail').val()+'&id_address='+id_address;
|
||||||
|
var element = $(this);
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: admin_order_tab_link,
|
||||||
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
|
data : query,
|
||||||
|
success : function(data)
|
||||||
|
{
|
||||||
|
if (data.result)
|
||||||
|
{
|
||||||
|
current_product = data;
|
||||||
|
element.parent().parent().css('background-color', '#E8EDC2');
|
||||||
|
|
||||||
|
element.parent().parent().find('td .product_price_show').hide();
|
||||||
|
element.parent().parent().find('td .product_quantity_show').hide();
|
||||||
|
element.parent().parent().find('td .product_price_edit').parent().attr('align', 'left');
|
||||||
|
element.parent().parent().find('td .product_price_edit').show();
|
||||||
|
element.parent().parent().find('td .product_quantity_edit').show();
|
||||||
|
|
||||||
|
element.parent().parent().find('td.cancelCheck').hide();
|
||||||
|
element.parent().parent().find('td.cancelQuantity').hide();
|
||||||
|
element.parent().parent().find('td.product_invoice').show();
|
||||||
|
|
||||||
|
element.parent().children('.delete_product_line').hide();
|
||||||
|
element.parent().children('.edit_product_change_link').hide();
|
||||||
|
element.parent().children('input[name=submitProductChange]').show();
|
||||||
|
element.parent().children('.cancel_product_change_link').show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.cancel_product_change_link').click(function() {
|
||||||
|
current_product = null;
|
||||||
|
|
||||||
|
$(this).parent().parent().css('background-color', '#FFF');
|
||||||
|
|
||||||
|
$(this).parent().parent().find('td .product_price_show').show();
|
||||||
|
$(this).parent().parent().find('td .product_quantity_show').show();
|
||||||
|
$(this).parent().parent().find('td .product_price_edit').parent().attr('align', 'center');
|
||||||
|
$(this).parent().parent().find('td .product_price_edit').hide();
|
||||||
|
$(this).parent().parent().find('td .product_quantity_edit').hide();
|
||||||
|
|
||||||
|
$(this).parent().parent().find('td.product_invoice').hide();
|
||||||
|
$(this).parent().parent().find('td.cancelCheck').show();
|
||||||
|
$(this).parent().parent().find('td.cancelQuantity').show();
|
||||||
|
|
||||||
|
$(this).parent().children('.delete_product_line').show();
|
||||||
|
$(this).parent().children('.edit_product_change_link').show();
|
||||||
|
$(this).parent().children('input[name=submitProductChange]').hide();
|
||||||
|
$(this).parent().children('.cancel_product_change_link').hide();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('input[name=submitProductChange]').click(function() {
|
||||||
|
if ($(this).parent().parent().find('td .edit_product_quantity').val() <= 0)
|
||||||
|
{
|
||||||
|
alert(txt_add_product_no_product_quantity);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($(this).parent().parent().find('td .edit_product_price').val() <= 0)
|
||||||
|
{
|
||||||
|
alert(txt_add_product_no_product_price);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confirm(txt_confirm))
|
||||||
|
{
|
||||||
|
var element = $(this);
|
||||||
|
|
||||||
|
query = 'ajax=1&token='+token+'&action=editProductOnOrder&id_order='+id_order+'&'+
|
||||||
|
element.parent().parent().find('input:visible, select:visible, input.edit_product_id_order_detail').serialize();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: admin_order_tab_link,
|
||||||
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
|
data : query,
|
||||||
|
success : function(data)
|
||||||
|
{
|
||||||
|
if (data.result)
|
||||||
|
{
|
||||||
|
refreshProductLineView(element, data.view);
|
||||||
|
updateAmounts(data.order);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.edit_product_price_tax_excl').keyup(function() {
|
||||||
|
var price_tax_excl = parseFloat($(this).val());
|
||||||
|
if (price_tax_excl < 0 || isNaN(price_tax_excl))
|
||||||
|
price_tax_excl = 0;
|
||||||
|
|
||||||
|
var tax_rate = current_product.tax_rate / 100 + 1;
|
||||||
|
$('.edit_product_price_tax_incl:visible').val(ps_round(price_tax_excl * tax_rate, 2));
|
||||||
|
|
||||||
|
// Update total product
|
||||||
|
editProductRefreshTotal($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.edit_product_price_tax_incl').keyup(function() {
|
||||||
|
var price_tax_incl = parseFloat($(this).val());
|
||||||
|
if (price_tax_incl < 0 || isNaN(price_tax_incl))
|
||||||
|
price_tax_incl = 0;
|
||||||
|
|
||||||
|
var tax_rate = current_product.tax_rate / 100 + 1;
|
||||||
|
$('.edit_product_price_tax_excl:visible').val(ps_round(price_tax_incl / tax_rate, 2));
|
||||||
|
|
||||||
|
// Update total product
|
||||||
|
editProductRefreshTotal($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.edit_product_quantity').keyup(function() {
|
||||||
|
var quantity = parseInt($(this).val());
|
||||||
|
if (quantity < 1 || isNaN(quantity))
|
||||||
|
quantity = 1;
|
||||||
|
|
||||||
|
var stock_available = parseInt($(this).parent().parent().parent().find('td.product_stock').html());
|
||||||
|
// total update
|
||||||
|
editProductRefreshTotal($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.delete_product_line').click(function() {
|
||||||
|
if (!confirm(txt_confirm))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var tr_product = $(this).parent().parent();
|
||||||
|
var id_order_detail = $(this).parent().parent().find('td .edit_product_id_order_detail').val();
|
||||||
|
var query = 'ajax=1&action=deleteProductLine&token='+token+'&id_order_detail='+id_order_detail+'&id_order='+id_order;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: admin_order_tab_link,
|
||||||
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
|
data : query,
|
||||||
|
success : function(data)
|
||||||
|
{
|
||||||
|
if (data.result)
|
||||||
|
{
|
||||||
|
tr_product.fadeOut('slow', function() {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
updateAmounts(data.order);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function addProductRefreshTotal()
|
||||||
|
{
|
||||||
|
var quantity = parseInt($('#add_product_product_quantity').val());
|
||||||
|
if (quantity < 1|| isNaN(quantity))
|
||||||
|
quantity = 1;
|
||||||
|
if (use_taxes)
|
||||||
|
var price = parseFloat($('#add_product_product_price_tax_incl').val());
|
||||||
|
else
|
||||||
|
var price = parseFloat($('#add_product_product_price_tax_excl').val());
|
||||||
|
|
||||||
|
if (price < 0 || isNaN(price))
|
||||||
|
price = 0;
|
||||||
|
var total = makeTotalProductCaculation(quantity, price);
|
||||||
|
$('#add_product_product_total').html(formatCurrency(total, currency_format, currency_sign, currency_blank));
|
||||||
|
}
|
||||||
|
|
||||||
|
function editProductRefreshTotal(element)
|
||||||
|
{
|
||||||
|
element = element.parent().parent().parent();
|
||||||
|
|
||||||
|
var quantity = parseInt(element.find('td .edit_product_quantity').val());
|
||||||
|
if (quantity < 1 || isNaN(quantity))
|
||||||
|
quantity = 1;
|
||||||
|
if (use_taxes)
|
||||||
|
var price = parseFloat(element.find('td .edit_product_price_tax_incl').val());
|
||||||
|
else
|
||||||
|
var price = parseFloat(element.find('td .edit_product_price_tax_excl').val())
|
||||||
|
|
||||||
|
if (price < 0 || isNaN(price))
|
||||||
|
price = 0;
|
||||||
|
|
||||||
|
var total = makeTotalProductCaculation(quantity, price);
|
||||||
|
element.find('td.total_product').html(formatCurrency(total, currency_format, currency_sign, currency_blank));
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTotalProductCaculation(quantity, price)
|
||||||
|
{
|
||||||
|
return Math.round(quantity * price * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addViewOrderDetailRow(view)
|
||||||
|
{
|
||||||
|
html = $(view);
|
||||||
|
html.find('td').hide();
|
||||||
|
$('tr#new_invoice').hide();
|
||||||
|
$('tr#new_product').hide();
|
||||||
|
|
||||||
|
// Initialize fields
|
||||||
|
closeAddProduct();
|
||||||
|
|
||||||
|
$('tr#new_product').before(html);
|
||||||
|
html.find('td').each(function() {
|
||||||
|
if (!$(this).is('.product_invoice'))
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshProductLineView(element, view)
|
||||||
|
{
|
||||||
|
var new_product_line = $(view);
|
||||||
|
new_product_line.find('td').hide();
|
||||||
|
|
||||||
|
var current_product_line = element.parent().parent();
|
||||||
|
current_product_line.before(new_product_line);
|
||||||
|
current_product_line.remove();
|
||||||
|
|
||||||
|
new_product_line.find('td').each(function() {
|
||||||
|
if (!$(this).is('.product_invoice'))
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAmounts(order)
|
||||||
|
{
|
||||||
|
$('#total_products td:last').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_products_wt), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
$('#total_discounts td:last').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_discounts_tax_incl), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
if (order.total_discounts_tax_incl > 0)
|
||||||
|
$('#total_discounts').slideDown('slow');
|
||||||
|
$('#total_wrapping td:last').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_wrapping_tax_incl), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
if (order.total_wrapping_tax_incl > 0)
|
||||||
|
$('#total_wrapping').slideDown('slow');
|
||||||
|
$('#total_shipping td:last').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_shipping_tax_incl), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
$('#total_order td:last').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
$('.total_paid').fadeOut('slow', function() {
|
||||||
|
$(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank));
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
$('.alert').slideDown('slow');
|
||||||
|
$('#product_number').fadeOut('slow', function() {
|
||||||
|
var old_quantity = parseInt($(this).html());
|
||||||
|
$(this).html(old_quantity + 1);
|
||||||
|
$(this).fadeIn('slow');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeAddProduct()
|
||||||
|
{
|
||||||
|
$('tr#new_invoice').hide();
|
||||||
|
$('tr#new_product').hide();
|
||||||
|
|
||||||
|
// Initialize fields
|
||||||
|
$('tr#new_product select, tr#new_product input').each(function() {
|
||||||
|
if (!$(this).is('.button'))
|
||||||
|
$(this).val('')
|
||||||
|
});
|
||||||
|
$('tr#new_invoice select, tr#new_invoice input').val('');
|
||||||
|
$('#add_product_product_quantity').val('1');
|
||||||
|
$('#add_product_product_attribute_id option').remove();
|
||||||
|
$('#add_product_product_attribute_area').hide();
|
||||||
|
$('#add_product_product_stock').html('0');
|
||||||
|
current_product = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Refund system script */
|
||||||
|
var flagRefund = '';
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.standard_refund').click(function() {
|
||||||
|
|
||||||
|
$.scrollTo('#refundForm', 1200, {offset: -100});
|
||||||
|
|
||||||
|
if (flagRefund == 'standard')
|
||||||
|
{
|
||||||
|
flagRefund = '';
|
||||||
|
$('.partial_refund_fields').hide();
|
||||||
|
$('.standard_refund_fields').hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flagRefund = 'standard';
|
||||||
|
$('.partial_refund_fields').hide();
|
||||||
|
$('.standard_refund_fields').fadeIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.partial_refund').click(function() {
|
||||||
|
|
||||||
|
$.scrollTo('#refundForm', 1200, {offset: -100});
|
||||||
|
|
||||||
|
if (flagRefund == 'partial')
|
||||||
|
{
|
||||||
|
flagRefund = '';
|
||||||
|
$('.partial_refund_fields').hide();
|
||||||
|
$('.standard_refund_fields').hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flagRefund = 'partial';
|
||||||
|
$('.standard_refund_fields').hide();
|
||||||
|
$('.partial_refund_fields').fadeIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+52
@@ -24,6 +24,58 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function formatedNumberToFloat(price, currencyFormat, currencySign)
|
||||||
|
{
|
||||||
|
price = price.replace(currencySign, '');
|
||||||
|
if (currencyFormat == 1)
|
||||||
|
return parseFloat(price.replace(',', '').replace(' ', ''));
|
||||||
|
else if (currencyFormat == 2)
|
||||||
|
return parseFloat(price.replace(' ', '').replace(',', '.'));
|
||||||
|
else if (currencyFormat == 3)
|
||||||
|
return parseFloat(price.replace('.', '').replace(' ', '').replace(',', '.'));
|
||||||
|
else if (currencyFormat == 4)
|
||||||
|
return parseFloat(price.replace(',', '').replace(' ', ''));
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return a formatted number
|
||||||
|
function formatNumber(value, numberOfDecimal, thousenSeparator, virgule)
|
||||||
|
{
|
||||||
|
value = value.toFixed(numberOfDecimal);
|
||||||
|
var val_string = value+'';
|
||||||
|
var tmp = val_string.split('.');
|
||||||
|
var abs_val_string = (tmp.length == 2) ? tmp[0] : val_string;
|
||||||
|
var deci_string = ('0.' + (tmp.length == 2 ? tmp[1] : 0)).substr(2);
|
||||||
|
var nb = abs_val_string.length;
|
||||||
|
|
||||||
|
for (var i = 1 ; i < 4; i++)
|
||||||
|
if (value >= Math.pow(10, (3 * i)))
|
||||||
|
abs_val_string = abs_val_string.substring(0, nb - (3 * i)) + thousenSeparator + abs_val_string.substring(nb - (3 * i));
|
||||||
|
|
||||||
|
if (parseInt(numberOfDecimal) == 0)
|
||||||
|
return abs_val_string;
|
||||||
|
return abs_val_string + virgule + (deci_string > 0 ? deci_string : '00');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatCurrency(price, currencyFormat, currencySign, currencyBlank)
|
||||||
|
{
|
||||||
|
// if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)
|
||||||
|
blank = '';
|
||||||
|
price = parseFloat(price.toFixed(6));
|
||||||
|
price = ps_round(price, priceDisplayPrecision);
|
||||||
|
if (currencyBlank > 0)
|
||||||
|
blank = ' ';
|
||||||
|
if (currencyFormat == 1)
|
||||||
|
return currencySign + blank + formatNumber(price, priceDisplayPrecision, ',', '.');
|
||||||
|
if (currencyFormat == 2)
|
||||||
|
return (formatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign);
|
||||||
|
if (currencyFormat == 3)
|
||||||
|
return (currencySign + blank + formatNumber(price, priceDisplayPrecision, '.', ','));
|
||||||
|
if (currencyFormat == 4)
|
||||||
|
return (formatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign);
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
function ps_round(value, precision)
|
function ps_round(value, precision)
|
||||||
{
|
{
|
||||||
if (typeof(roundMode) == 'undefined')
|
if (typeof(roundMode) == 'undefined')
|
||||||
|
|||||||
@@ -301,6 +301,34 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="table_block">
|
||||||
|
{if $order->getShipping()|count > 0}
|
||||||
|
<table class="std">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="first_item">{l s='Date'}</th>
|
||||||
|
<th class="item">{l s='Carrier'}</th>
|
||||||
|
<th class="item">{l s='Weight'}</th>
|
||||||
|
<th class="item">{l s='Shipping cost'}</th>
|
||||||
|
<th class="last_item">{l s='Tracking number'}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{foreach from=$order->getShipping() item=line}
|
||||||
|
<tr class="item">
|
||||||
|
<td>{$line.date_add}</td>
|
||||||
|
<td>{$line.state_name}</td>
|
||||||
|
<td>{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')}</td>
|
||||||
|
<td>{if $order->getTaxCalculationMethod() == $smarty.const.PS_TAX_INC}{displayPrice price=$line.shipping_cost_tax_incl currency=$currency->id}{else}{displayPrice price=$line.shipping_cost_tax_excl currency=$currency->id}{/if}</td>
|
||||||
|
<td>
|
||||||
|
<span id="shipping_number_show">{if $line.url && $line.tracking_number}<a href="{$line.url|replace:'@':$line.tracking_number}">{$line.tracking_number}</a>{else}{$line.tracking_number}{/if}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<br />
|
<br />
|
||||||
{if !$is_guest}
|
{if !$is_guest}
|
||||||
{if $return_allowed}
|
{if $return_allowed}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<tr style="line-height:6px;background-color:{cycle values='#FFF,#DDD'};">
|
<tr style="line-height:6px;background-color:{cycle values='#FFF,#DDD'};">
|
||||||
<td style="width: 30%">{l s='Shipping' pdf='true'}</td>
|
<td style="width: 30%">{l s='Shipping' pdf='true'}</td>
|
||||||
<td style="width: 20%">{$shipping_tax_infos.rate}</td>
|
<td style="width: 20%">{$shipping_tax_infos.rate}</td>
|
||||||
<td style="width: 20%">{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_excl}</td>
|
<td style="width: 20%">{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}</td>
|
||||||
<td style="width: 20%; text-align: right;">{displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_amount}</td>
|
<td style="width: 20%; text-align: right;">{displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_amount}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
|
|||||||
@@ -130,66 +130,66 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table style="width: 100%">
|
<table style="width: 100%">
|
||||||
{if (($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0)}
|
{if (($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0)}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Excl.)' pdf='true'}</td>
|
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Excl.)' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products}</td>
|
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Incl.)' pdf='true'}</td>
|
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Incl.)' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products_wt}</td>
|
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products_wt}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{else}
|
{else}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total' pdf='true'}</td>
|
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products}</td>
|
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if $order->total_discounts_tax_incl > 0}
|
{if $order_invoice->total_discount_tax_incl > 0}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td>
|
<td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">-{displayPrice currency=$order->id_currency price=$order->total_discounts_tax_incl}</td>
|
<td style="width: 15%; text-align: right;">-{displayPrice currency=$order->id_currency price=$order_invoice->total_discount_tax_incl}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if $order->total_wrapping_tax_incl > 0}
|
{if $order_invoice->total_wrapping_tax_incl > 0}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td>
|
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">
|
<td style="width: 15%; text-align: right;">
|
||||||
{if $tax_excluded_display}
|
{if $tax_excluded_display}
|
||||||
{displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_excl}
|
{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_excl}
|
||||||
{else}
|
{else}
|
||||||
{displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_incl}
|
{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_incl}
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if $order->total_shipping_tax_incl > 0}
|
{if $order_invoice->total_shipping_tax_incl > 0}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td>
|
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">
|
<td style="width: 15%; text-align: right;">
|
||||||
{if $tax_excluded_display}
|
{if $tax_excluded_display}
|
||||||
{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_excl}
|
{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}
|
||||||
{else}
|
{else}
|
||||||
{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_incl}
|
{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_incl}
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0}
|
{if ($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0}
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="text-align: right; font-weight: bold">{l s='Total Tax' pdf='true'}</td>
|
<td style="text-align: right; font-weight: bold">{l s='Total Tax' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_tax_excl)}</td>
|
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<tr style="line-height:5px;">
|
<tr style="line-height:5px;">
|
||||||
<td style="text-align: right; font-weight: bold">{l s='Total' pdf='true'}</td>
|
<td style="text-align: right; font-weight: bold">{l s='Total' pdf='true'}</td>
|
||||||
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_paid_tax_incl}</td>
|
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user