Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CySSoO committed May 28, 2024
1 parent 5f08afa commit fe0069b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 137 deletions.
110 changes: 54 additions & 56 deletions controllers/front/quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ private function createSimpleProductQuote($id_product, $id_product_attribute, $i

// Then add product
$ever_cart->addProductToQuoteCart(
(int)$id_product,
(int)$id_product_attribute,
(int)$id_customization,
(int)$qty
(int) $id_product,
(int) $id_product_attribute,
(int) $id_customization,
(int) $qty
);

// Get ever cart informations
$cart_details = $ever_cart->getSummaryDetails(
(int)$cart->id
(int) $cart->id
);
// die(var_dump($cart_details));
$cart_products = $ever_cart->getProducts();

// Now create quotation
Expand Down Expand Up @@ -247,7 +246,6 @@ private function createSimpleProductQuote($id_product, $id_product_attribute, $i
$total = (float) $price_without_tax * (int) $cart_product['cart_quantity'];
// $product_taxes = $price_with_tax - $price_without_tax;
// $total_product_taxes = $total_wt - $total;
// die(var_dump($price_without_tax));
$quotedetail = new EverpsquotationDetail();
$quotedetail->id_everpsquotation_quotes = (int) $quote->id;
// $quotedetail->id_warehouse = (int)$cart_details['total_discounts']['id_warehouse'];
Expand Down Expand Up @@ -347,7 +345,7 @@ private function setCartAsQuote(): int
}
parent::initContent();

$customer = new Customer((int)$cart->id_customer);
$customer = new Customer((int) $cart->id_customer);

if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
Expand All @@ -369,7 +367,7 @@ private function setCartAsQuote(): int

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 @@ -380,31 +378,31 @@ private function setCartAsQuote(): int
$cartproducts = $cart->getProducts();

$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->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->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->valid = 0;
$quote->date_add = date('Y-m-d H:i:s');
$quote->date_upd = date('Y-m-d H:i:s');
Expand All @@ -413,26 +411,26 @@ private function setCartAsQuote(): int
//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');
Expand All @@ -454,7 +452,7 @@ private function setCartAsQuote(): int
$id_shop = (int) Context::getContext()->shop->id;
$mailDir = _PS_MODULE_DIR_ . 'everpsquotation/mails/';
$pdf = new PDF($quote->id, 'EverQuotationPdf', Context::getContext()->smarty);
$customerNames = $customer->firstname.' '.$customer->lastname;
$customerNames = $customer->firstname . ' ' . $customer->lastname;
$attachment = array();
$attachment['content'] = $pdf->render(false);
$attachment['name'] = $ever_filename;
Expand All @@ -465,11 +463,11 @@ private function setCartAsQuote(): int
(string)$subject,
array(
'{shop_name}' => Configuration::get('PS_SHOP_NAME'),
'{shop_logo}'=>_PS_IMG_DIR_.Configuration::get(
'{shop_logo}'=>_PS_IMG_DIR_ . Configuration::get(
'PS_LOGO',
null,
null,
(int)$id_shop
(int) $id_shop
),
'{firstname}' => (string) $customer->firstname,
'{lastname}' => (string) $customer->lastname,
Expand Down
20 changes: 1 addition & 19 deletions everpsquotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
{
$this->name = 'everpsquotation';
$this->tab = 'payments_gateways';
$this->version = '5.1.0';
$this->version = '5.1.1';
$this->author = 'Team Ever';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -512,15 +512,6 @@ protected function getConfigForm()
'required' => true,
'tree' => $tree,
],
[
'col' => 3,
'type' => 'text',
'lang' => false,
'label' => $this->l('Conversion ID for Google Ads'),
'desc' => $this->l('Please set here transaction id for Google Ads, such as AW-XXXXXXXXX/XXXXXXXXXXX'),
'hint' => $this->l('Will be used to track quotation creation using Google Ads'),
'name' => 'EVERPSQUOTATION_TRANSACTION_ID',
],
],
'submit' => [
'title' => $this->l('Save'),
Expand Down Expand Up @@ -736,11 +727,6 @@ protected function postProcess()
Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED')
);

Configuration::updateValue(
'EVERPSQUOTATION_TRANSACTION_ID',
Tools::getValue('EVERPSQUOTATION_TRANSACTION_ID')
);

/* Uploads image */
$type = Tools::strtolower(Tools::substr(strrchr($_FILES['image']['name'], '.'), 1));
$imagesize = @getimagesize($_FILES['image']['tmp_name']);
Expand Down Expand Up @@ -872,9 +858,6 @@ protected function getConfigFormValues()
'EVERPSQUOTATION_DURATION' => Configuration::get(
'EVERPSQUOTATION_DURATION'
),
'EVERPSQUOTATION_TRANSACTION_ID' => Configuration::get(
'EVERPSQUOTATION_TRANSACTION_ID'
),
];
}

Expand Down Expand Up @@ -974,7 +957,6 @@ public function hookHeader($params)
Media::addJsDef([
$this->name . '_quote_link ' => $quoteAjaxLink,
$this->name . '_quoterequest_link ' => $quoteRequestAjaxLink,
'quotation_event_id' => Configuration::get('EVERPSQUOTATION_TRANSACTION_ID'),
]);
if ($controller_name == 'product') {
$this->context->controller->addJs($this->_path.'views/js/createProductQuote.js');
Expand Down
Loading

0 comments on commit fe0069b

Please sign in to comment.