// Add CartController
This commit is contained in:
@@ -1,336 +0,0 @@
|
||||
<?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: 7310 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php');
|
||||
|
||||
class AdminCarts extends AdminTab
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'cart';
|
||||
$this->className = 'Cart';
|
||||
$this->lang = false;
|
||||
$this->edit = false;
|
||||
$this->view = true;
|
||||
$this->delete = true;
|
||||
|
||||
$this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, ca.name carrier, o.id_order ';
|
||||
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer)
|
||||
LEFT JOIN '._DB_PREFIX_.'currency cu ON (cu.id_currency = a.id_currency)
|
||||
LEFT JOIN '._DB_PREFIX_.'carrier ca ON (ca.id_carrier = a.id_carrier)
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_cart = a.id_cart) ';
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_cart' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'id_order' => array('title' => $this->l('ID Order'), 'align' => 'center', 'width' => 25),
|
||||
'customer' => array('title' => $this->l('Customer'), 'width' => 80, 'filter_key' => 'c!lastname'),
|
||||
'total' => array('title' => $this->l('Total'), 'callback' => 'getOrderTotalUsingTaxCalculationMethod', 'orderby' => false, 'search' => false, 'width' => 50, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'currency' => true),
|
||||
'carrier' => array('title' => $this->l('Carrier'), 'width' => 25, 'align' => 'center', 'callback' => 'replaceZeroByShopName', 'filter_key' => 'ca!name'),
|
||||
'date_add' => array('title' => $this->l('Date'), 'width' => 90, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'));
|
||||
$this->shopLinkType = 'shop';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function viewDetails()
|
||||
{
|
||||
if (!($cart = $this->loadObject(true)))
|
||||
return;
|
||||
$customer = new Customer($cart->id_customer);
|
||||
$customerStats = $customer->getStats();
|
||||
$products = $cart->getProducts();
|
||||
$customizedDatas = Product::getAllCustomizedDatas((int)($cart->id));
|
||||
Product::addCustomizationPrice($products, $customizedDatas);
|
||||
$summary = $cart->getSummaryDetails();
|
||||
$discounts = $cart->getDiscounts();
|
||||
$currency = new Currency($cart->id_currency);
|
||||
|
||||
// display cart header
|
||||
echo '<h2>'.(($customer->id) ? $customer->firstname.' '.$customer->lastname : $this->l('Guest')).' - '.$this->l('Cart #').sprintf('%06d', $cart->id).' '.$this->l('from').' '.$cart->date_upd.'</h2>';
|
||||
|
||||
/* Display customer information */
|
||||
echo '
|
||||
<br />
|
||||
<div style="float: left;">
|
||||
<fieldset style="width: 400px">
|
||||
<legend><img src="../img/admin/tab-customers.gif" /> '.$this->l('Customer information').'</legend>
|
||||
<span style="font-weight: bold; font-size: 14px;">';
|
||||
if ($customer->id)
|
||||
echo '
|
||||
<a href="?tab=AdminCustomers&id_customer='.$customer->id.'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'"> '.$customer->firstname.' '.$customer->lastname.'</a></span> ('.$this->l('#').$customer->id.')<br />
|
||||
(<a href="mailto:'.$customer->email.'">'.$customer->email.'</a>)<br /><br />
|
||||
'.$this->l('Account registered:').' '.Tools::displayDate($customer->date_add, $this->context->language->id, true).'<br />
|
||||
'.$this->l('Valid orders placed:').' <b>'.$customerStats['nb_orders'].'</b><br />
|
||||
'.$this->l('Total paid since registration:').' <b>'.Tools::displayPrice($customerStats['total_orders'], $currency, false).'</b><br />';
|
||||
else
|
||||
echo $this->l('Guest not registered').'</span>';
|
||||
echo '</fieldset>';
|
||||
echo '
|
||||
</div>
|
||||
<div style="float: left; margin-left: 40px">';
|
||||
|
||||
/* Display order information */
|
||||
$id_order = (int)(Order::getOrderByCartId($cart->id));
|
||||
$order = new Order($id_order);
|
||||
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
{
|
||||
$total_products = $summary['total_products'];
|
||||
$total_discount = $summary['total_discounts_tax_exc'];
|
||||
$total_wrapping = $summary['total_wrapping_tax_exc'];
|
||||
$total_price = $summary['total_price_without_tax'];
|
||||
$total_shipping = $summary['total_shipping_tax_exc'];
|
||||
} else {
|
||||
$total_products = $summary['total_products_wt'];
|
||||
$total_discount = $summary['total_discounts'];
|
||||
$total_wrapping = $summary['total_wrapping'];
|
||||
$total_price = $summary['total_price'];
|
||||
$total_shipping = $summary['total_shipping'];
|
||||
}
|
||||
|
||||
echo '
|
||||
<fieldset style="width: 400px">
|
||||
<legend><img src="../img/admin/cart.gif" /> '.$this->l('Order information').'</legend>
|
||||
<span style="font-weight: bold; font-size: 14px;">';
|
||||
if ($order->id)
|
||||
echo '
|
||||
<a href="?tab=AdminOrders&id_order='.(int)($order->id).'&vieworder&token='.Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)$this->context->employee->id).'"> '.$this->l('Order #').sprintf('%06d', $order->id).'</a></span>
|
||||
<br /><br />
|
||||
'.$this->l('Made on:').' '.Tools::displayDate($order->date_add, $this->context->language->id, true).'<br /><br /><br /><br />';
|
||||
else
|
||||
echo $this->l('No order created from this cart').'</span>';
|
||||
echo '</fieldset>';
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
|
||||
// List of products
|
||||
echo '
|
||||
<br style="clear:both;" />
|
||||
<fieldset style="margin-top:25px; width: 715px; ">
|
||||
<legend><img src="../img/admin/cart.gif" alt="'.$this->l('Products').'" />'.$this->l('Cart summary').'</legend>
|
||||
<div style="float:left;">
|
||||
<table style="width: 700px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts">
|
||||
<tr>
|
||||
<th align="center" style="width: 60px"> </th>
|
||||
<th>'.$this->l('Product').'</th>
|
||||
<th style="width: 80px; text-align: center">'.$this->l('UP').'</th>
|
||||
<th style="width: 20px; text-align: center">'.$this->l('Qty').'</th>
|
||||
<th style="width: 30px; text-align: center">'.$this->l('Stock').'</th>
|
||||
<th style="width: 90px; text-align: right; font-weight:bold;">'.$this->l('Total').'</th>
|
||||
</tr>';
|
||||
$tokenCatalog = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id);
|
||||
foreach ($products as $k => $product)
|
||||
{
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
{
|
||||
$product_price = $product['price'];
|
||||
$product_total = $product['total'];
|
||||
} else {
|
||||
$product_price = $product['price_wt'];
|
||||
$product_total = $product['total_wt'];
|
||||
}
|
||||
|
||||
|
||||
$image = array();
|
||||
if (isset($product['id_product_attribute']) AND (int)($product['id_product_attribute']))
|
||||
$image = Db::getInstance()->getRow('
|
||||
SELECT id_image
|
||||
FROM '._DB_PREFIX_.'product_attribute_image
|
||||
WHERE id_product_attribute = '.(int)($product['id_product_attribute']));
|
||||
if (!isset($image['id_image']))
|
||||
$image = Db::getInstance()->getRow('
|
||||
SELECT id_image
|
||||
FROM '._DB_PREFIX_.'image
|
||||
WHERE id_product = '.(int)($product['id_product']).' AND cover = 1');
|
||||
|
||||
$productObj = new Product($product['id_product']);
|
||||
|
||||
/* Customization display */
|
||||
$this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock);
|
||||
if ($product['cart_quantity'] > $product['customizationQuantityTotal'])
|
||||
{
|
||||
$imageProduct = new Image($image['id_image']);
|
||||
echo '
|
||||
<tr>
|
||||
<td align="center">'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$imageProduct->getExistingImgPath().'.jpg',
|
||||
'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').'</td>
|
||||
<td><a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&updateproduct&token='.$tokenCatalog.'">
|
||||
<span class="productName">'.$product['name'].'</span><br />
|
||||
'.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '')
|
||||
.(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '')
|
||||
.'</a></td>
|
||||
<td align="center">'.Tools::displayPrice($product_price, $currency, false).'</td>
|
||||
<td align="center" class="productQuantity">'.((int)($product['cart_quantity']) - $product['customizationQuantityTotal']).'</td>
|
||||
<td align="center" class="productQuantity">'.$productObj->getStock(isset($product['id_product_attribute']) ? $product['id_product_attribute'] : 0).'</td>
|
||||
<td align="right">'.Tools::displayPrice($product_total, $currency, false).'</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
echo '
|
||||
<tr class="cart_total_product">
|
||||
<td colspan="5">'.$this->l('Total products:').'</td>
|
||||
<td class="price bold right">'.Tools::displayPrice($total_products, $currency, false).'</td>
|
||||
</tr>';
|
||||
|
||||
if ($summary['total_discounts'] != 0)
|
||||
echo '
|
||||
<tr class="cart_total_voucher">
|
||||
<td colspan="5">'.$this->l('Total vouchers:').'</td>
|
||||
<td class="price-discount bold right">'.Tools::displayPrice($total_discount, $currency, false).'</td>
|
||||
</tr>';
|
||||
if ($summary['total_wrapping'] > 0)
|
||||
echo '
|
||||
<tr class="cart_total_voucher">
|
||||
<td colspan="5">'.$this->l('Total gift-wrapping:').'</td>
|
||||
<td class="price-discount bold right">'.Tools::displayPrice($total_wrapping, $currency, false).'</td>
|
||||
</tr>';
|
||||
if ($cart->getOrderTotal(true, Cart::ONLY_SHIPPING) > 0)
|
||||
echo '
|
||||
<tr class="cart_total_delivery">
|
||||
<td colspan="5">'.$this->l('Total shipping:').'</td>
|
||||
<td class="price bold right">'.Tools::displayPrice($total_shipping, $currency, false).'</td>
|
||||
</tr>';
|
||||
echo '
|
||||
<tr class="cart_total_price">
|
||||
<td colspan="5" class="bold">'.$this->l('Total:').'</td>
|
||||
<td class="price bold right">'.Tools::displayPrice($total_price, $currency, false).'</td>
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
if (sizeof($discounts))
|
||||
{
|
||||
echo '
|
||||
<table cellspacing="0" cellpadding="0" class="table" style="width:280px; margin:15px 0px 0px 420px;">
|
||||
<tr>
|
||||
<th><img src="../img/admin/coupon.gif" alt="'.$this->l('Discounts').'" />'.$this->l('Discount name').'</th>
|
||||
<th align="center" style="width: 100px">'.$this->l('Value').'</th>
|
||||
</tr>';
|
||||
|
||||
foreach ($discounts as $discount)
|
||||
echo '
|
||||
<tr>
|
||||
<td><a href="?tab=AdminDiscounts&id_discount='.$discount['id_discount'].'&updatediscount&token='.Tools::getAdminToken('AdminDiscounts'.(int)(Tab::getIdFromClassName('AdminDiscounts')).(int)$this->context->employee->id).'">'.$discount['name'].'</a></td>
|
||||
<td align="center">- '.Tools::displayPrice($discount['value_real'], $currency, false).'</td>
|
||||
</tr>';
|
||||
echo '
|
||||
</table>';
|
||||
}
|
||||
echo '<div style="float:left; margin-top:15px;">'.
|
||||
$this->l('According to the group of this customer, prices are printed:').' <b>'.($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')).'</b>
|
||||
</div></div>';
|
||||
|
||||
// Cancel product
|
||||
echo '
|
||||
</fieldset>
|
||||
<div class="clear" style="height:20px;"> </div>';
|
||||
}
|
||||
|
||||
private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, &$stock)
|
||||
{
|
||||
if (!($order = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
if (is_array($customizedDatas) AND isset($customizedDatas[(int)($product['id_product'])][(int)($product['id_product_attribute'])]))
|
||||
{
|
||||
if ($image = new Image($image['id_image']))
|
||||
echo '
|
||||
<tr>
|
||||
<td align="center">'.($image->id ? cacheImage(_PS_IMG_DIR_.'p/'.$image->getExistingImgPath().'.jpg',
|
||||
'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').'</td>
|
||||
<td><a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&updateproduct&token='.$tokenCatalog.'">
|
||||
<span class="productName">'.$product['name'].'</span>'.(isset($product['attributes']) ? '<br />'.$product['attributes'] : '').'<br />
|
||||
'.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '')
|
||||
.(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '')
|
||||
.'</a></td>
|
||||
<td align="center">'.Tools::displayPrice($product['price_wt'], $currency, false).'</td>
|
||||
<td align="center" class="productQuantity">'.$product['customizationQuantityTotal'].'</td>
|
||||
<td align="center" class="productQuantity">'.(int)($stock['quantity']).'</td>
|
||||
<td align="right">'.Tools::displayPrice($product['total_customization_wt'], $currency, false).'</td>
|
||||
</tr>';
|
||||
foreach ($customizedDatas[(int)($product['id_product'])][(int)($product['id_product_attribute'])] AS $customization)
|
||||
{
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="2">';
|
||||
foreach ($customization['datas'] AS $type => $datas)
|
||||
if ($type == Product::CUSTOMIZE_FILE)
|
||||
{
|
||||
$i = 0;
|
||||
echo '<ul style="margin: 0; padding: 0; list-style-type: none;">';
|
||||
foreach ($datas AS $data)
|
||||
echo '<li style="display: inline; margin: 2px;">
|
||||
<a href="displayImage.php?img='.$data['value'].'&name='.(int)($order->id).'-file'.++$i.'" target="_blank"><img src="'._THEME_PROD_PIC_DIR_.$data['value'].'_small" alt="" /></a>
|
||||
</li>';
|
||||
echo '</ul>';
|
||||
}
|
||||
elseif ($type == Product::CUSTOMIZE_TEXTFIELD)
|
||||
{
|
||||
$i = 0;
|
||||
echo '<ul style="margin-bottom: 4px; padding: 0; list-style-type: none;">';
|
||||
foreach ($datas AS $data)
|
||||
echo '<li>'.($data['name'] ? $data['name'] : $this->l('Text #').++$i).$this->l(':').' <b>'.$data['value'].'</b></li>';
|
||||
echo '</ul>';
|
||||
}
|
||||
echo '</td>
|
||||
<td align="center"></td>
|
||||
<td align="center" class="productQuantity">'.$customization['quantity'].'</td>
|
||||
<td align="center" class="productQuantity"></td>
|
||||
<td align="center"></td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
if (isset($_GET['view'.$this->table]))
|
||||
$this->viewDetails();
|
||||
else
|
||||
{
|
||||
$this->getList(Context::getContext()->language->id, !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
|
||||
$this->displayList();
|
||||
}
|
||||
}
|
||||
|
||||
protected function _displayDeleteLink($token = NULL, $id)
|
||||
{
|
||||
foreach ($this->_list as $cart)
|
||||
if ($id == $cart['id_cart'])
|
||||
if ($cart['id_order'])
|
||||
return;
|
||||
|
||||
$_cacheLang['Delete'] = $this->l('Delete', __CLASS__, true, false);
|
||||
$_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, true, false).$id.' ?)';
|
||||
|
||||
echo '
|
||||
<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token).'" onclick="return confirm(\''.$_cacheLang['DeleteItem'].'\');">
|
||||
<img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a>
|
||||
';
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1390,7 +1390,7 @@ class CartCore extends ObjectModel
|
||||
return Tools::displayError('This voucher is not yet valid');
|
||||
if (strtotime($discountObj->date_to) < time())
|
||||
return Tools::displayError('This voucher has expired.');
|
||||
if (!$discountObj->isAssociatedToShop($shop))
|
||||
if (!$discountObj->isAssociatedToShop((int)$shop->id))
|
||||
return Tools::displayError('This voucher is not available with this shop.');
|
||||
if (sizeof($discounts) >= 1 AND $checkCartDiscount)
|
||||
{
|
||||
|
||||
+12
-10
@@ -120,18 +120,20 @@ abstract class ControllerCore
|
||||
// postProcess handles ajaxProcess
|
||||
$this->postProcess();
|
||||
|
||||
if ($this->display_header)
|
||||
{
|
||||
$this->setMedia();
|
||||
$this->initHeader();
|
||||
}
|
||||
|
||||
$this->setMedia();
|
||||
$this->initHeader();
|
||||
|
||||
$this->initContent();
|
||||
if ($this->display_footer)
|
||||
$this->initFooter();
|
||||
$this->initFooter();
|
||||
|
||||
if ($this->ajax && method_exists($this, 'displayAjax'))
|
||||
$this->displayAjax();
|
||||
if ($this->ajax)
|
||||
{
|
||||
$action = Tools::getValue('action');
|
||||
if (!empty($action) && method_exists($this, 'displayAjax'.Tools::toCamelCase($action)))
|
||||
$this->{'displayAjax'.$action}();
|
||||
elseif (method_exists($this, 'displayAjax'))
|
||||
$this->displayAjax();
|
||||
}
|
||||
else
|
||||
$this->display();
|
||||
}
|
||||
|
||||
Executable
+414
@@ -0,0 +1,414 @@
|
||||
<?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: 8971 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminCartsController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'cart';
|
||||
$this->className = 'Cart';
|
||||
$this->lang = false;
|
||||
$this->requiredDatabase = true;
|
||||
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
$this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, ca.name carrier, o.id_order, g.id_guest';
|
||||
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer)
|
||||
LEFT JOIN '._DB_PREFIX_.'currency cu ON (cu.id_currency = a.id_currency)
|
||||
LEFT JOIN '._DB_PREFIX_.'carrier ca ON (ca.id_carrier = a.id_carrier)
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_cart = a.id_cart)
|
||||
LEFT JOIN `'._DB_PREFIX_.'guest` g ON (a.id_guest = g.id_guest AND TIME_TO_SEC(TIMEDIFF(NOW(), c.`date_add`)) < 900)';
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_cart' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 25
|
||||
),
|
||||
'id_order' => array(
|
||||
'title' => $this->l('ID Order'),
|
||||
'align' => 'center', 'width' => 25
|
||||
),
|
||||
'customer' => array(
|
||||
'title' => $this->l('Customer'),
|
||||
'width' => 80,
|
||||
'filter_key' => 'c!lastname'
|
||||
),
|
||||
'total' => array(
|
||||
'title' => $this->l('Total'),
|
||||
'callback' => 'getOrderTotalUsingTaxCalculationMethod',
|
||||
'orderby' => false,
|
||||
'search' => false,
|
||||
'width' => 50,
|
||||
'align' => 'right',
|
||||
'prefix' => '<b>',
|
||||
'suffix' => '</b>',
|
||||
'currency' => true
|
||||
),
|
||||
'carrier' => array(
|
||||
'title' => $this->l('Carrier'),
|
||||
'width' => 25,
|
||||
'align' => 'center',
|
||||
'callback' => 'replaceZeroByShopName',
|
||||
'filter_key' => 'ca!name'
|
||||
),
|
||||
'date_add' => array(
|
||||
'title' => $this->l('Date'),
|
||||
'width' => 90,
|
||||
'align' => 'right',
|
||||
'type' => 'datetime',
|
||||
'filter_key' => 'a!date_add'
|
||||
),
|
||||
'id_guest' => array(
|
||||
'title' => $this->l('Online'),
|
||||
'width' => 25,
|
||||
'align' => 'center',
|
||||
'type' => 'bool',
|
||||
'filter_key' => 'guest',
|
||||
'tmpTableFilter' => true,
|
||||
'icon' => array(0 => 'blank.gif', 1 => 'tab-customers.gif')
|
||||
)
|
||||
);
|
||||
$this->shopLinkType = 'shop';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function viewCart()
|
||||
{
|
||||
if (!($cart = $this->loadObject(true)))
|
||||
return;
|
||||
$customer = new Customer($cart->id_customer);
|
||||
$products = $cart->getProducts();
|
||||
$customizedDatas = Product::getAllCustomizedDatas((int)($cart->id));
|
||||
Product::addCustomizationPrice($products, $customizedDatas);
|
||||
$summary = $cart->getSummaryDetails();
|
||||
$currency = new Currency($cart->id_currency);
|
||||
|
||||
/* Display order information */
|
||||
$id_order = (int)(Order::getOrderByCartId($cart->id));
|
||||
$order = new Order($id_order);
|
||||
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
{
|
||||
$total_products = $summary['total_products'];
|
||||
$total_discounts = $summary['total_discounts_tax_exc'];
|
||||
$total_wrapping = $summary['total_wrapping_tax_exc'];
|
||||
$total_price = $summary['total_price_without_tax'];$total_shipping = $summary['total_shipping_tax_exc'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$total_products = $summary['total_products_wt'];
|
||||
$total_discounts = $summary['total_discounts'];
|
||||
$total_wrapping = $summary['total_wrapping'];
|
||||
$total_price = $summary['total_price'];
|
||||
$total_shipping = $summary['total_shipping'];
|
||||
}
|
||||
foreach ($products as $k => &$product)
|
||||
{
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
{
|
||||
$product['product_price'] = $product['price'];
|
||||
$product['product_total'] = $product['total'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$product['product_price'] = $product['price_wt'];
|
||||
$product['product_total'] = $product['total_wt'];
|
||||
}
|
||||
$image = array();
|
||||
if (isset($product['id_product_attribute']) AND (int)($product['id_product_attribute']))
|
||||
$image = Db::getInstance()->getRow('SELECT id_image
|
||||
FROM '._DB_PREFIX_.'product_attribute_image
|
||||
WHERE id_product_attribute = '.(int)($product['id_product_attribute']));
|
||||
if (!isset($image['id_image']))
|
||||
$image = Db::getInstance()->getRow('SELECT id_image
|
||||
FROM '._DB_PREFIX_.'image
|
||||
WHERE id_product = '.(int)($product['id_product']).' AND cover = 1');
|
||||
|
||||
$productObj = new Product($product['id_product']);
|
||||
$product['qty_in_stock'] = StockAvailable::getStockAvailableForProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int)$order->id_shop);
|
||||
/* Customization display */
|
||||
//$this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock);
|
||||
$imageProduct = new Image($image['id_image']);
|
||||
$product['image'] = (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$imageProduct->getExistingImgPath().'.jpg', 'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--');
|
||||
}
|
||||
$this->context->smarty->assign(array('products' => $products,
|
||||
'discounts' => $cart->getDiscounts(),
|
||||
'order' => $order,
|
||||
'cart' => $cart,
|
||||
'currency' => $currency,
|
||||
'customer' => $customer,
|
||||
'customer_stats' => $customer->getStats(),
|
||||
'total_products' => $total_products,
|
||||
'total_discounts' => $total_discounts,
|
||||
'total_wrapping' => $total_wrapping,
|
||||
'total_price' => $total_price,
|
||||
'total_shipping' => $total_shipping
|
||||
));
|
||||
}
|
||||
|
||||
public function ajaxPreProcess()
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$customer = new Customer((int)$id_customer);
|
||||
$this->context->customer = $customer;
|
||||
$id_cart = (int)Tools::getValue('id_cart');
|
||||
if (!$id_cart)
|
||||
$id_cart = $customer->getLastCart();
|
||||
$this->context->cart = new Cart((int)$id_cart);
|
||||
if (!$this->context->cart->id_customer)
|
||||
$this->context->cart->id_customer = $id_customer;
|
||||
if ($this->context->cart->OrderExists())
|
||||
return;
|
||||
if (!$this->context->cart->id_lang)
|
||||
$this->context->cart->id_lang = (($id_lang = (int)Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'));
|
||||
if (!$this->context->cart->id_currency)
|
||||
$this->context->cart->id_currency = (($id_currency = (int)Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
|
||||
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
|
||||
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
|
||||
$id_address_invoice = (int)Tools::getValue('id_address_delivery');
|
||||
|
||||
if (!$this->context->cart->id_address_invoice && isset($addresses[0]))
|
||||
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
|
||||
elseif ($id_address_invoice)
|
||||
$this->context->cart->id_address_invoice = (int)$id_address_invoice;
|
||||
if (!$this->context->cart->id_address_delivery && isset($addresses[0]))
|
||||
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
|
||||
elseif ($id_address_delivery)
|
||||
$this->context->cart->id_address_delivery = (int)$id_address_delivery;
|
||||
|
||||
$this->context->cart->save();
|
||||
$currency = new Currency((int)$this->context->cart->id_currency);
|
||||
$this->context->currency = $currency;
|
||||
|
||||
}
|
||||
|
||||
public function ajaxProcessDeleteProduct()
|
||||
{
|
||||
$errors = array();
|
||||
if (!$id_product = (int)Tools::getValue('id_product') OR !$id_product_attribute = (int)Tools::getValue('id_product_attribute'))
|
||||
$errors[] = Tools::displayError('Invalid product');
|
||||
if (sizeof($errors))
|
||||
die(Tools::jsonEncode($errors));
|
||||
|
||||
if ($this->context->cart->deleteProduct($id_product, $id_product_attribute))
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateQty()
|
||||
{
|
||||
$errors = array();
|
||||
if (!$this->context->cart->id)
|
||||
return;
|
||||
if ($this->context->cart->OrderExists())
|
||||
$errors[] = Tools::displayErrors('An order already placed with this cart');
|
||||
elseif (!$id_product = (int)Tools::getValue('id_product') OR (!$product = new Product((int)$id_product, true, $this->context->language->id)))
|
||||
$errors[] = Tools::displayError('Invalid product');
|
||||
elseif (!$qty = Tools::getValue('qty') OR $qty == 0)
|
||||
$errors[] = Tools::displayError('Invalid quantity');
|
||||
elseif (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0 && !Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty))
|
||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||
elseif (!$product->checkQty((int)$qty))
|
||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||
elseif (!$id_customization = (int)Tools::getValue('id_customization', 0) AND !$product->hasAllRequiredCustomizableFields())
|
||||
$errors[] = Tools::displayError('Please fill in all required fields');
|
||||
$this->context->cart->save();
|
||||
if (!count($errors))
|
||||
{
|
||||
if (!($qty_upd = $this->context->cart->updateQty($qty, $id_product, (int)$id_product_attribute, (int)$id_customization, 'up')))
|
||||
$errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
|
||||
}
|
||||
|
||||
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
||||
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateCarrier()
|
||||
{
|
||||
if(Validate::isBool(($recyclable = (int)Tools::getValue('recyclable'))))
|
||||
$this->context->cart->recyclable = $recyclable;
|
||||
if(Validate::isBool(($gift = (int)Tools::getValue('gift'))))
|
||||
$this->context->cart->gift = $gift;
|
||||
if(Validate::isMessage(($gift_message = pSQL(Tools::getValue('gift_message')))))
|
||||
$this->context->cart->gift_message = $gift_message;
|
||||
$this->context->cart->save();
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateCurrency()
|
||||
{
|
||||
$currency = new Currency((int)Tools::getValue('id_currency'));
|
||||
if (Validate::isLoadedObject($currency) && !$currency->deleted && $currency->active)
|
||||
{
|
||||
$this->context->cart->id_currency = (int)$currency->id;
|
||||
$this->context->cart->save();
|
||||
}
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
public function ajaxProcessUpdateLang()
|
||||
{
|
||||
$lang = new Language((int)Tools::getValue('id_lang'));
|
||||
if (Validate::isLoadedObject($lang) && $lang->active)
|
||||
{
|
||||
$this->context->cart->id_lang = (int)$lang->id;
|
||||
$this->context->cart->save();
|
||||
}
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
public function ajaxProcessDuplicateOrder()
|
||||
{
|
||||
$errors = array();
|
||||
if (!$id_order = Tools::getValue('id_order'))
|
||||
$errors[] = Tools::displayErrors('Invalid order');
|
||||
$cart = Cart::getCartByOrderId($id_order);
|
||||
$new_cart = $cart->duplicate();
|
||||
if (!$new_cart OR !Validate::isLoadedObject($new_cart['cart']))
|
||||
$errors[] = Tools::displayError('The order cannot be renewed');
|
||||
elseif (!$new_cart['success'])
|
||||
$errors[] = Tools::displayError('The order cannot be renewed');
|
||||
else
|
||||
{
|
||||
$this->context->cart = $new_cart['cart'];
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function ajaxProcessDeleteDiscount()
|
||||
{
|
||||
if ($this->context->cart->deleteDiscount((int)Tools::getValue('id_voucher')))
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
public function ajaxProcessAddVoucher()
|
||||
{
|
||||
$errors = array();
|
||||
$customer = new Customer((int)$this->context->cart->id_customer);
|
||||
|
||||
if (!$id_discount = Tools::getValue('id_voucher') OR !$discount = new Discount((int)$id_discount))
|
||||
$errors[] = Tools::displayError('Invalid voucher');
|
||||
elseif ($err = $this->context->cart->checkDiscountValidity($discount, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true, $customer))
|
||||
$errors[] = $err;
|
||||
if (!sizeof($errors))
|
||||
if (!$this->context->cart->addDiscount((int)$discount->id))
|
||||
$errors[] = Tools::displayError('Can\'t add the voucher');
|
||||
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
||||
}
|
||||
|
||||
protected function getCartSummary()
|
||||
{
|
||||
$summary = $this->context->cart->getSummaryDetails();
|
||||
$currency = new Currency((int)$this->context->cart->id_currency);
|
||||
if (count($summary['products']))
|
||||
foreach ($summary['products'] AS &$product)
|
||||
{
|
||||
$product['price'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($product['price'], $currency), $currency));
|
||||
$product['total'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($product['total'], $currency), $currency));
|
||||
$product['image_link'] = $this->context->link->getImageLink($product['link_rewrite'], $product['id_image'], 'small');
|
||||
if(!isset($product['attributes_small']))
|
||||
$product['attributes_small'] = '';
|
||||
}
|
||||
if (count($summary['discounts']))
|
||||
foreach ($summary['discounts'] AS &$voucher)
|
||||
$voucher['value_real'] = Tools::displayPrice($voucher['value_real'], $currency);
|
||||
$summary['total_products'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_products'], $currency), $currency));
|
||||
$summary['total_discounts_tax_exc'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_discounts_tax_exc'], $currency), $currency));
|
||||
$summary['total_shipping_tax_exc'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_shipping_tax_exc'], $currency), $currency));
|
||||
$summary['total_tax'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_tax'], $currency), $currency));
|
||||
$summary['total_price_without_tax'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_price_without_tax'], $currency), $currency));
|
||||
$summary['total_price'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_price'], $currency), $currency));
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
protected function getAvailableCarriers()
|
||||
{
|
||||
$customer = new Customer((int)$this->context->cart->id_customer);
|
||||
return Carrier::getCarriersForOrder(Address::getZoneById($this->context->cart->id_address_delivery), $customer->getGroups());
|
||||
}
|
||||
|
||||
public function displayAjaxSearchCarts()
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$carts = Cart::getCustomerCarts((int)$id_customer);
|
||||
$orders = Order::getCustomerOrders((int)$id_customer);
|
||||
$customer = new Customer((int)$id_customer);
|
||||
|
||||
if (count($carts))
|
||||
foreach ($carts AS $key => &$cart)
|
||||
{
|
||||
$cartObj = new Cart((int)$cart['id_cart']);
|
||||
if (!Validate::isLoadedObject($cartObj) || $cartObj->OrderExists())
|
||||
unset($carts[$key]);
|
||||
$currency = new Currency((int)($cart['id_currency']));
|
||||
$cart['total_price'] = Tools::displayPrice(Tools::convertPrice($cartObj->getOrderTotal(), $currency), $currency);
|
||||
}
|
||||
if (count($orders))
|
||||
foreach ($orders AS &$order)
|
||||
$order['total_paid_real'] = Tools::displayPrice(Tools::convertPrice($order['total_paid_real'], $currency), $currency);
|
||||
if ($orders || $carts)
|
||||
$to_return = array_merge($this->ajaxReturnVars(),
|
||||
array('carts' => $carts,
|
||||
'orders' => $orders,
|
||||
'found' => true));
|
||||
else
|
||||
$to_return = array_merge($this->ajaxReturnVars(), array('found' => false));
|
||||
|
||||
echo Tools::jsonEncode($to_return);
|
||||
}
|
||||
|
||||
public function ajaxReturnVars()
|
||||
{
|
||||
|
||||
$id_cart = (int)$this->context->cart->id;
|
||||
return array('summary' => $this->getCartSummary(),
|
||||
'carriers' => $this->getAvailableCarriers(),
|
||||
'cart' => $this->context->cart,
|
||||
'carriers' => $this->getAvailableCarriers(),
|
||||
'addresses' => $this->context->customer->getAddresses((int)$this->context->cart->id_lang),
|
||||
'id_cart' => $id_cart,
|
||||
'link_order' => $this->context->link->getPageLink('order', false, (int)$this->context->cart->id_lang, 'step=3&recover_cart='.$id_cart.'&token_cart='.md5(_COOKIE_KEY_.'recover_cart_'.$id_cart)));
|
||||
}
|
||||
|
||||
public function displayAjaxGetSummary()
|
||||
{
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
public static function getOrderTotalUsingTaxCalculationMethod($id_cart)
|
||||
{
|
||||
return Cart::getTotalCart($id_cart, true);
|
||||
}
|
||||
|
||||
public static function replaceZeroByShopName($echo, $tr)
|
||||
{
|
||||
return ($echo == '0' ? Configuration::get('PS_SHOP_NAME') : $echo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user