// StockAvailable: updated synchronize() and updated its usage within the different stock controllers when necessary
This commit is contained in:
@@ -46,59 +46,59 @@ class AdminCartsController extends AdminController
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_cart' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 25
|
||||
),
|
||||
'id_order' => array(
|
||||
'title' => $this->l('ID Order'),
|
||||
'title' => $this->l('ID Order'),
|
||||
'align' => 'center', 'width' => 25
|
||||
),
|
||||
'customer' => array(
|
||||
'title' => $this->l('Customer'),
|
||||
'width' => 80,
|
||||
'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>',
|
||||
'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',
|
||||
'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',
|
||||
'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,
|
||||
'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 initView()
|
||||
{
|
||||
if (!($cart = $this->loadObject(true)))
|
||||
@@ -120,7 +120,7 @@ class AdminCartsController extends AdminController
|
||||
$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'];
|
||||
@@ -152,8 +152,8 @@ class AdminCartsController extends AdminController
|
||||
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);
|
||||
|
||||
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int)$order->id_shop);
|
||||
|
||||
$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') : '--');
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class AdminCartsController extends AdminController
|
||||
|
||||
return parent::initView();
|
||||
}
|
||||
|
||||
|
||||
public function ajaxPreProcess()
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
@@ -195,7 +195,7 @@ class AdminCartsController extends AdminController
|
||||
$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');
|
||||
@@ -221,7 +221,7 @@ class AdminCartsController extends AdminController
|
||||
$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());
|
||||
}
|
||||
@@ -238,11 +238,11 @@ class AdminCartsController extends AdminController
|
||||
elseif (!$qty = Tools::getValue('qty') OR $qty == 0)
|
||||
$errors[] = Tools::displayError('Invalid quantity');
|
||||
if (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0)
|
||||
{
|
||||
{
|
||||
if(!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty))
|
||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||
}
|
||||
else
|
||||
else
|
||||
if(!$product->checkQty((int)$qty))
|
||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||
if (!$id_customization = (int)Tools::getValue('id_customization', 0) AND !$product->hasAllRequiredCustomizableFields())
|
||||
@@ -251,13 +251,13 @@ class AdminCartsController extends AdminController
|
||||
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.');
|
||||
$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'))))
|
||||
@@ -269,7 +269,7 @@ class AdminCartsController extends AdminController
|
||||
$this->context->cart->save();
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessUpdateCurrency()
|
||||
{
|
||||
$currency = new Currency((int)Tools::getValue('id_currency'));
|
||||
@@ -306,20 +306,20 @@ class AdminCartsController extends AdminController
|
||||
$this->context->cart = $new_cart['cart'];
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessDeleteVoucher()
|
||||
{
|
||||
if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule')))
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessAddVoucher()
|
||||
{
|
||||
$errors = array();
|
||||
$customer = new Customer((int)$this->context->cart->id_customer);
|
||||
|
||||
|
||||
if (!$id_cart_rule = Tools::getValue('id_cart_rule') OR !$cartRule = new CartRule((int)$id_cart_rule))
|
||||
$errors[] = Tools::displayError('Invalid voucher');
|
||||
elseif ($err = $cartRule->checkValidity($this->context))
|
||||
@@ -329,16 +329,16 @@ class AdminCartsController extends AdminController
|
||||
$errors[] = Tools::displayError('Can\'t add the voucher');
|
||||
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessUpdateAddresses()
|
||||
{
|
||||
if (($id_address_delivery = (int)Tools::getValue('id_address_delivery')) && $address_delivery = new Address((int)$id_address_delivery) && $address_delivery->id_customer = $this->context->cart->id_customer)
|
||||
$this->context->cart->id_address_delivery = (int)$address_delivery->id;
|
||||
|
||||
|
||||
if (($id_address_invoice = (int)Tools::getValue('id_address_invoice')) && $address_invoice = new Address((int)$id_address_invoice) && $address_invoice->id_customer = $this->context->cart->id_customer)
|
||||
$this->context->cart->id_address_invoice = (int)$address_invoice->id;
|
||||
$this->context->cart->save();
|
||||
|
||||
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
@@ -364,23 +364,23 @@ class AdminCartsController extends AdminController
|
||||
$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)
|
||||
{
|
||||
@@ -394,7 +394,7 @@ class AdminCartsController extends AdminController
|
||||
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(),
|
||||
$to_return = array_merge($this->ajaxReturnVars(),
|
||||
array('carts' => $carts,
|
||||
'orders' => $orders,
|
||||
'found' => true));
|
||||
@@ -403,7 +403,7 @@ class AdminCartsController extends AdminController
|
||||
|
||||
echo Tools::jsonEncode($to_return);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxReturnVars()
|
||||
{
|
||||
|
||||
@@ -416,22 +416,22 @@ class AdminCartsController extends AdminController
|
||||
'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 function ajaxProcessUpdateProductPrice()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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