Skip to content

Commit

Permalink
Fix create quote on simple product
Browse files Browse the repository at this point in the history
  • Loading branch information
CySSoO committed Apr 22, 2024
1 parent 2644b6d commit 5f08afa
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 179 deletions.
124 changes: 68 additions & 56 deletions controllers/admin/AdminEverPsQuotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct()
INNER JOIN `' . _DB_PREFIX_ . 'country` country ON address.id_country = country.id_country
INNER JOIN `' . _DB_PREFIX_ . 'country_lang` country_lang ON (
country.`id_country` = country_lang.`id_country`
AND country_lang.`id_lang` = ' . (int)$this->context->language->id . '
AND country_lang.`id_lang` = ' . (int) $this->context->language->id . '
)';
$this->_orderBy = 'id_everpsquotation_quotes';
$this->_orderWay = 'DESC';
Expand All @@ -73,6 +73,11 @@ public function __construct()
'align' => 'text-center',
'class' => 'fixed-width-xs'
),
'id_cart' => array(
'title' => $this->l('ID cart'),
'align' => 'text-center',
'class' => 'fixed-width-xs'
),
'customer' => array(
'title' => $this->l('Customer'),
'havingFilter' => true,
Expand Down Expand Up @@ -155,7 +160,7 @@ public function __construct()
$moduleConfUrl .= Tools::getAdminTokenLite('AdminModules');
$this->context->smarty->assign(array(
'moduleConfUrl' => $moduleConfUrl,
'everpsquotation_dir' => Tools::getHttpHost(true).__PS_BASE_URI__.'/modules/everpsquotation'
'everpsquotation_dir' => Tools::getHttpHost(true) . __PS_BASE_URI__ . '/modules/everpsquotation'
));
}

Expand Down Expand Up @@ -219,7 +224,7 @@ public function postProcess()
}
if (Tools::getIsset('statusvalideverpsquotation_quotes')) {
$quote = new EverpsquotationClass(
(int)Tools::getValue('id_everpsquotation_quotes')
(int) Tools::getValue('id_everpsquotation_quotes')
);
$quote->valid = !$quote->valid;
if (!$quote->update()) {
Expand All @@ -228,10 +233,10 @@ public function postProcess()
}
if (Tools::getIsset('deleteeverpsquotation_quotes')) {
$quote = new EverpsquotationClass(
(int)Tools::getValue('id_everpsquotation_quotes')
(int) Tools::getValue('id_everpsquotation_quotes')
);
$quote_cart = new EverpsquotationCart(
(int)$quote->id_cart
(int) $quote->id_cart
);
if (!$quote->deleteQuoteCart() || $quote_cart->dropQuoteCartProducts()) {
$this->errors[] = Tools::displayError('An error has occurred: Can\'t update the current object');
Expand All @@ -242,9 +247,9 @@ public function postProcess()
(int) Tools::getValue('id_everpsquotation_quotes')
);
$products = EverpsquotationDetail::getQuoteDetailByQuoteId(
(int)$quote->id,
(int)$this->context->shop->id,
(int)$this->context->language->id
(int) $quote->id,
(int) $this->context->shop->id,
(int) $this->context->language->id
);
$cart = new Cart();
$cart->id_customer = (int) $quote->id_customer;
Expand Down Expand Up @@ -278,7 +283,7 @@ public function displayDropQuoteLink($token, $id_everpsquotation)
}
$quote_controller_link = 'index.php?controller=AdminEverPsQuotation&token=';
$quote_controller_link .= Tools::getAdminTokenLite('AdminEverPsQuotation');
$quote_controller_link .= '&id_everpsquotation_quotes='.(int)$id_everpsquotation;
$quote_controller_link .= '&id_everpsquotation_quotes=' . (int) $id_everpsquotation;
$quote_controller_link .= '&deleteeverpsquotation_quotes';

$this->context->smarty->assign(array(
Expand All @@ -288,18 +293,25 @@ public function displayDropQuoteLink($token, $id_everpsquotation)
));

return $this->context->smarty->fetch(
_PS_MODULE_DIR_.'everpsquotation/views/templates/admin/helpers/lists/list_action_drop_quote.tpl'
_PS_MODULE_DIR_ . 'everpsquotation/views/templates/admin/helpers/lists/list_action_drop_quote.tpl'
);
}

public function displayViewCartLink($token, $id_everpsquotation)
{
if (!$token) {
return;
}
}

public function displayConvertToOrderLink($token, $id_everpsquotation)
{
if (!$token) {
return;
}
$quote_controller_link = 'index.php?controller=AdminEverPsQuotation&token=';
$quote_controller_link .= Tools::getAdminTokenLite('AdminEverPsQuotation');
$quote_controller_link .= '&id_everpsquotation_quotes='.(int)$id_everpsquotation;
$quote_controller_link .= '&id_everpsquotation_quotes=' . (int) $id_everpsquotation;
$quote_controller_link .= '&convert_to_order';

$this->context->smarty->assign(array(
Expand All @@ -320,7 +332,7 @@ protected function processTransformCartToQuote()
);
Hook::exec('actionBeforeCreateEverQuote');
$id_quote_cart = EverpsquotationCart::copyCartToQuoteCart(
(int)$cart->id
(int) $cart->id
);
if (!Validate::isInt($id_quote_cart)) {
die($this->trans('An error has occured.', array(), 'Modules.Everpsquotation.Shop'));
Expand All @@ -333,31 +345,31 @@ protected function processTransformCartToQuote()
return;
}
$quote = new EverpsquotationClass();
$quote->reference = (string)Configuration::get('EVERPSQUOTATION_PREFIX');
$quote->id_shop_group = (int)$cart->id_shop_group;
$quote->id_shop = (int)$cart->id_shop;
$quote->id_carrier = (int)$cart->id_carrier;
$quote->id_lang = (int)$cart->id_lang;
$quote->id_customer = (int)$cart->id_customer;
$quote->id_cart = (int)$cart->id;
$quote->id_currency = (int)$cart->id_currency;
$quote->id_address_delivery = (int)$cart->id_address_delivery;
$quote->id_address_invoice = (int)$cart->id_address_invoice;
$quote->reference = (string) Configuration::get('EVERPSQUOTATION_PREFIX');
$quote->id_shop_group = (int) $cart->id_shop_group;
$quote->id_shop = (int) $cart->id_shop;
$quote->id_carrier = (int) $cart->id_carrier;
$quote->id_lang = (int) $cart->id_lang;
$quote->id_customer = (int) $cart->id_customer;
$quote->id_cart = (int) $cart->id;
$quote->id_currency = (int) $cart->id_currency;
$quote->id_address_delivery = (int) $cart->id_address_delivery;
$quote->id_address_invoice = (int) $cart->id_address_invoice;
$quote->secure_key = (string)$cart->secure_key;
$quote->recyclable = (int)$cart->recyclable;
$quote->total_discounts = (float)$cartdetails['total_discounts'];
$quote->total_discounts_tax_incl = (float)$cartdetails['total_discounts'];
$quote->total_discounts_tax_excl = (float)$cartdetails['total_discounts_tax_exc'];
$quote->total_paid_tax_incl = (float)$cartdetails['total_price'];
$quote->total_paid_tax_excl = (float)$cartdetails['total_price_without_tax'];
$quote->total_products = (float)$cartdetails['total_products'];
$quote->total_products_wt = (float)$cartdetails['total_products_wt'];
$quote->total_shipping = (float)$cartdetails['total_shipping'];
$quote->total_shipping_tax_incl = (float)$cartdetails['total_shipping'];
$quote->total_shipping_tax_excl = (float)$cartdetails['total_shipping_tax_exc'];
$quote->total_wrapping = (float)$cartdetails['total_wrapping'];
$quote->total_wrapping_tax_incl = (float)$cartdetails['total_wrapping'];
$quote->total_wrapping_tax_excl = (float)$cartdetails['total_wrapping_tax_exc'];
$quote->recyclable = (int) $cart->recyclable;
$quote->total_discounts = (float) $cartdetails['total_discounts'];
$quote->total_discounts_tax_incl = (float) $cartdetails['total_discounts'];
$quote->total_discounts_tax_excl = (float) $cartdetails['total_discounts_tax_exc'];
$quote->total_paid_tax_incl = (float) $cartdetails['total_price'];
$quote->total_paid_tax_excl = (float) $cartdetails['total_price_without_tax'];
$quote->total_products = (float) $cartdetails['total_products'];
$quote->total_products_wt = (float) $cartdetails['total_products_wt'];
$quote->total_shipping = (float) $cartdetails['total_shipping'];
$quote->total_shipping_tax_incl = (float) $cartdetails['total_shipping'];
$quote->total_shipping_tax_excl = (float) $cartdetails['total_shipping_tax_exc'];
$quote->total_wrapping = (float) $cartdetails['total_wrapping'];
$quote->total_wrapping_tax_incl = (float) $cartdetails['total_wrapping'];
$quote->total_wrapping_tax_excl = (float) $cartdetails['total_wrapping_tax_exc'];
$quote->valid = 0;
$quote->date_add = date('Y-m-d H:i:s');
$quote->date_upd = date('Y-m-d H:i:s');
Expand All @@ -366,30 +378,30 @@ protected function processTransformCartToQuote()
//Now create new Everpsquotationdetail object
foreach ($cartproducts as $cartproduct) {
$quotedetail = new EverpsquotationDetail();
$quotedetail->id_everpsquotation_quotes = (int)$quote->id;
$quotedetail->id_shop = (int)$cartproduct['id_shop'];
$quotedetail->product_id = (int)$cartproduct['id_product'];
$quotedetail->product_attribute_id = (int)$cartproduct['id_product_attribute'];
$quotedetail->id_customization = (int)$cartproduct['id_customization'];
$quotedetail->product_name = (string)$cartproduct['name'];
$quotedetail->product_quantity = (int)$cartproduct['cart_quantity'];
$quotedetail->product_quantity_in_stock = (int)$cartproduct['stock_quantity'];
$quotedetail->id_everpsquotation_quotes = (int) $quote->id;
$quotedetail->id_shop = (int) $cartproduct['id_shop'];
$quotedetail->product_id = (int) $cartproduct['id_product'];
$quotedetail->product_attribute_id = (int) $cartproduct['id_product_attribute'];
$quotedetail->id_customization = (int) $cartproduct['id_customization'];
$quotedetail->product_name = (string) $cartproduct['name'];
$quotedetail->product_quantity = (int) $cartproduct['cart_quantity'];
$quotedetail->product_quantity_in_stock = (int) $cartproduct['stock_quantity'];
$quotedetail->product_price = $cartproduct['price'];
$quotedetail->product_ean13 = (string)$cartproduct['ean13'];
$quotedetail->product_isbn = (string)$cartproduct['isbn'];
$quotedetail->product_upc = (string)$cartproduct['upc'];
$quotedetail->product_reference = (string)$cartproduct['reference'];
$quotedetail->product_supplier_reference = (string)$cartproduct['supplier_reference'];
$quotedetail->product_weight = (float)$cartproduct['weight'];
$quotedetail->tax_name = (string)$cartproduct['tax_name'];
$quotedetail->ecotax = (float)$cartproduct['ecotax'];
$quotedetail->unit_price_tax_excl = (float)$cartproduct['price'];
$quotedetail->total_price_tax_incl = (float)$cartproduct['total_wt'];
$quotedetail->total_price_tax_excl = (float)$cartproduct['total'];
$quotedetail->product_ean13 = (string) $cartproduct['ean13'];
$quotedetail->product_isbn = (string) $cartproduct['isbn'];
$quotedetail->product_upc = (string) $cartproduct['upc'];
$quotedetail->product_reference = (string) $cartproduct['reference'];
$quotedetail->product_supplier_reference = (string) $cartproduct['supplier_reference'];
$quotedetail->product_weight = (float) $cartproduct['weight'];
$quotedetail->tax_name = (string) $cartproduct['tax_name'];
$quotedetail->ecotax = (float) $cartproduct['ecotax'];
$quotedetail->unit_price_tax_excl = (float) $cartproduct['price'];
$quotedetail->total_price_tax_incl = (float) $cartproduct['total_wt'];
$quotedetail->total_price_tax_excl = (float) $cartproduct['total'];
$quotedetail->add();
}
Hook::exec('actionAfterCreateEverQuote');
if ((bool)Configuration::get('EVERPSQUOTATION_RENDER_ON_VALIDATION') === true) {
if ((bool) Configuration::get('EVERPSQUOTATION_RENDER_ON_VALIDATION') === true) {
$pdf = new PDF($quote->id, 'EverQuotationPdf', Context::getContext()->smarty);
$pdf->render();
}
Expand Down
Loading

0 comments on commit 5f08afa

Please sign in to comment.