Created new file CsvOrder to handle the imported orders

This commit is contained in:
vishalsingh.qlo325
2024-06-14 13:17:50 +05:30
parent 84bf37b58f
commit 514e43eeb5
4 changed files with 197 additions and 171 deletions

32
classes/CsvOrder.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade QloApps to newer
* versions in the future. If you wish to customize QloApps for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*/
class CsvOrder extends PaymentModule
{
public $active = 1;
public $name = 'csvorder';
public function __construct()
{
$this->payment_type = OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT;
}
}

View File

@@ -420,7 +420,7 @@ abstract class PaymentModuleCore extends Module
&& number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_)
&& $this->name != 'wsorder'
&& $this->name != 'bo_order'
&& $this->name != 'csvbooking'
&& $this->name != 'csvorder'
) {
// if customer is paying full payment amount
$id_order_state = Configuration::get('PS_OS_ERROR');
@@ -694,7 +694,7 @@ abstract class PaymentModuleCore extends Module
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
if ($this->name != 'csvbooking') {
if ($this->name != 'csvorder') {
Mail::Send(
(int)$order->id_lang,
'voucher',
@@ -1101,7 +1101,7 @@ abstract class PaymentModuleCore extends Module
$order = new Order((int)$order->id);
// Send an e-mail to customer (one order = one email)
if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id && $this->name != 'csvbooking') {
if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id && $this->name != 'csvorder') {
$invoice = new Address($order->id_address_invoice);
$delivery = new Address($order->id_address_delivery);
$delivery_state = $delivery->id_state ? new State($delivery->id_state) : false;

View File

@@ -414,7 +414,7 @@ class OrderHistoryCore extends ObjectModel
return false;
}
if (Tools::getValue('controller') != 'AdminImport') {
if ($order->module != 'csvorder') {
if (!$this->sendEmail($order, $template_vars)) {
return false;
}

View File

@@ -37,18 +37,6 @@ define('MAX_COLUMNS', 6);
/** correct Mac error on eof */
@ini_set('auto_detect_line_endings', '1');
class CsvBooking extends PaymentModule
{
public $active = 1;
public $name = 'csvbooking';
public function __construct()
{
$this->payment_type = OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT;
}
}
class AdminImportControllerCore extends AdminController
{
public static $column_mask;
@@ -2801,191 +2789,197 @@ class AdminImportControllerCore extends AdminController
foreach ($ordersRow as $orderRefKey => $orderRow) {
$idCustomer = $orderInfo[$orderRefKey]['id_customer'];
$objCustomer = new Customer((int) $idCustomer);
if (!$objCustomer->is_guest) {
$idGuest = Guest::getFromCustomer($objCustomer->id);
$id_order_state = (int) $orderInfo[$orderRefKey]['id_order_status'];
$objCartBooking = new HotelCartBookingData();
$this->context->cart = new Cart();
$this->context->customer = $objCustomer;
$this->context->cart->id_customer = $idCustomer;
$this->context->cart->id_guest = $idGuest;
if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists()) {
continue;
}
if (Validate::isLoadedObject($objCustomer = new Customer((int) $idCustomer))) {
if (!$objCustomer->is_guest) {
$idGuest = Guest::getFromCustomer($objCustomer->id);
$id_order_state = (int) $orderInfo[$orderRefKey]['id_order_status'];
$objCartBooking = new HotelCartBookingData();
$this->context->cart = new Cart();
$this->context->customer = $objCustomer;
$this->context->cart->id_customer = $idCustomer;
$this->context->cart->id_guest = $idGuest;
if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists()) {
continue;
}
if (!$this->context->cart->secure_key) {
$this->context->cart->secure_key = $this->context->customer->secure_key;
}
if (!$this->context->cart->secure_key) {
$this->context->cart->secure_key = $this->context->customer->secure_key;
}
if (!$this->context->cart->id_shop) {
$this->context->cart->id_shop = Configuration::get('PS_SHOP_DEFAULT');
}
if (!$this->context->cart->id_shop) {
$this->context->cart->id_shop = Configuration::get('PS_SHOP_DEFAULT');
}
if (!$this->context->cart->id_lang) {
$this->context->cart->id_lang = Configuration::get('PS_LANG_DEFAULT');
}
if (!$this->context->cart->id_lang) {
$this->context->cart->id_lang = Configuration::get('PS_LANG_DEFAULT');
}
if (!$this->context->cart->id_currency) {
$this->context->cart->id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
}
if (!$this->context->cart->id_currency) {
$this->context->cart->id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
}
if ($addresses = $objCustomer->getAddresses((int)$this->context->cart->id_lang)){
$objCountry = new Country($addresses[0]['id_country'], $this->context->language->id);
$objHotelBookingDetails = new HotelBookingDetail();
$amount = 0;
$due_amount = 0;
if ($objCountry->active) {
if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
}
if ($addresses = $objCustomer->getAddresses((int)$this->context->cart->id_lang)){
$objCountry = new Country($addresses[0]['id_country'], $this->context->language->id);
$objHotelBookingDetails = new HotelBookingDetail();
$amount = 0;
$due_amount = 0;
if ($objCountry->active) {
if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
}
if (!$this->context->cart->id_address_delivery && isset($addresses[0])) {
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
}
if (!$this->context->cart->id_address_delivery && isset($addresses[0])) {
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
}
$this->context->cart->setNoMultishipping();
$this->context->cart->save();
$occupancy = $featurePrices = array();
foreach ($orderRow as $idHotel => $orderByHotel) {
foreach($orderByHotel as $key => $orderProduct) {
$date_from = $orderProduct['duration_dates'][0];
$date_to = $orderProduct['duration_dates'][1];
$bookingParams = array(
'date_from' => $date_from,
'date_to' => $date_to,
'hotel_id' => $idHotel,
'id_room_type' => $orderProduct['id_product'],
'only_search_data' => 1,
);
$due_amount += isset($orderProduct['due_amount']) ? $orderProduct['due_amount'] : 0;
$data = $objHotelBookingDetails->getBookingData($bookingParams);
if ($data['stats']['num_avail'] >= $orderProduct['num_rooms']) {
for ($i = 0; $i < $orderProduct['num_rooms']; $i++) {
$occupancy[$i]['adults'] = $orderProduct['adults'];
$occupancy[$i]['children'] = 0;
}
$serviceProduct = array();
$globalDemand = array();
if (isset($orderProduct['id_service_products']) && count($orderProduct['id_service_products'])) {
foreach ($orderProduct['id_service_products'] as $serviceProdKey => $serviceProd) {
$objServiceProduct = new Product($serviceProd);
if (Validate::isLoadedObject($objServiceProduct)) {
$serviceProduct[$serviceProdKey]['id_product'] = $serviceProd;
$serviceProduct[$serviceProdKey]['quantity'] = 1;
}
}
}
if (isset($orderProduct['id_additional_facilities']) && count($orderProduct['id_additional_facilities'])) {
foreach ($orderProduct['id_additional_facilities'] as $globalDemandKey => $idGlobalDemand) {
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $this->context->language->id);
if (Validate::isLoadedObject($objGlobalDemand)) {
$globalDemand[$globalDemandKey]['id_global_demand'] = $idGlobalDemand;
$globalDemand[$globalDemandKey]['id_option'] = 0;
}
}
}
$globalDemand = json_encode($globalDemand);
$objCartBooking->updateCartBooking(
$orderProduct['id_product'],
$occupancy,
'up',
$idHotel,
0,
date('Y-m-d', strtotime($date_from)),
date('Y-m-d', strtotime($date_to)),
$globalDemand,
$serviceProduct,
$this->context->cart->id,
$this->context->cart->id_guest
$this->context->cart->setNoMultishipping();
$this->context->cart->save();
$occupancy = $featurePrices = array();
foreach ($orderRow as $idHotel => $orderByHotel) {
foreach($orderByHotel as $key => $orderProduct) {
$date_from = $orderProduct['duration_dates'][0];
$date_to = $orderProduct['duration_dates'][1];
$bookingParams = array(
'date_from' => $date_from,
'date_to' => $date_to,
'hotel_id' => $idHotel,
'id_room_type' => $orderProduct['id_product'],
'only_search_data' => 1,
);
$objHotelCartBookingData = new HotelCartBookingData();
if ($idRooms = $objHotelCartBookingData->getCustomerIdRoomsByIdCartIdProduct(
$this->context->cart->id,
$orderProduct['id_product'],
date('Y-m-d', strtotime($date_from)),
date('Y-m-d', strtotime($date_to))
)) {
$productPriceTI = Product::getPriceStatic((int) $orderProduct['id_product'], true);
$productPriceTE = Product::getPriceStatic((int) $orderProduct['id_product'], false);
if ($productPriceTE) {
$taxRate = (($productPriceTI-$productPriceTE)/$productPriceTE)*100;
} else {
$taxRate = 0;
$due_amount += isset($orderProduct['due_amount']) ? $orderProduct['due_amount'] : 0;
$data = $objHotelBookingDetails->getBookingData($bookingParams);
if ($data['stats']['num_avail'] >= $orderProduct['num_rooms']) {
for ($i = 0; $i < $orderProduct['num_rooms']; $i++) {
$occupancy[$i]['adults'] = $orderProduct['adults'];
$occupancy[$i]['children'] = 0;
}
$taxRateM = $taxRate/100;
if (isset($orderProduct['amount'])) {
$orderProduct['amount'] = (float)$orderProduct['amount']/(1+$taxRateM);
foreach ($idRooms as $idRoom) {
$hrt_feature_price = new HotelRoomTypeFeaturePricing();
$hrt_feature_price->id_product = (int) $orderProduct['id_product'];
$hrt_feature_price->id_cart = (int) $this->context->cart->id;
$hrt_feature_price->id_guest = (int) $this->context->cart->id_guest;
foreach(Language::getLanguages(true) as $lang) {
$hrt_feature_price->feature_price_name[$lang['id_lang']] = 'csvprice';
$serviceProduct = array();
$globalDemand = array();
if (isset($orderProduct['id_service_products']) && count($orderProduct['id_service_products'])) {
foreach ($orderProduct['id_service_products'] as $serviceProdKey => $serviceProd) {
$objServiceProduct = new Product($serviceProd);
if (Validate::isLoadedObject($objServiceProduct)) {
$serviceProduct[$serviceProdKey]['id_product'] = $serviceProd;
$serviceProduct[$serviceProdKey]['quantity'] = 1;
}
}
}
$hrt_feature_price->date_selection_type = HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE;
$hrt_feature_price->date_from = date('Y-m-d', strtotime($date_from));
$hrt_feature_price->date_to = date('Y-m-d', strtotime($date_to));
$hrt_feature_price->is_special_days_exists = 0;
$hrt_feature_price->id_room = $idRoom['id_room'];
$hrt_feature_price->special_days = json_encode(false);
$hrt_feature_price->impact_way = HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE;
$hrt_feature_price->impact_type = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE;
$hrt_feature_price->impact_value = $orderProduct['amount'];
$hrt_feature_price->active = 1;
$hrt_feature_price->groupBox = array_column(Group::getGroups($this->context->language->id), 'id_group');
$hrt_feature_price->add();
$featurePrices[] = $hrt_feature_price->id;
if (isset($orderProduct['id_additional_facilities']) && count($orderProduct['id_additional_facilities'])) {
foreach ($orderProduct['id_additional_facilities'] as $globalDemandKey => $idGlobalDemand) {
$objGlobalDemand = new HotelRoomTypeGlobalDemand($idGlobalDemand, $this->context->language->id);
if (Validate::isLoadedObject($objGlobalDemand)) {
$globalDemand[$globalDemandKey]['id_global_demand'] = $idGlobalDemand;
$globalDemand[$globalDemandKey]['id_option'] = 0;
}
}
}
$globalDemand = json_encode($globalDemand);
$objCartBooking->updateCartBooking(
$orderProduct['id_product'],
$occupancy,
'up',
$idHotel,
0,
date('Y-m-d', strtotime($date_from)),
date('Y-m-d', strtotime($date_to)),
$globalDemand,
$serviceProduct,
$this->context->cart->id,
$this->context->cart->id_guest
);
$objHotelCartBookingData = new HotelCartBookingData();
if ($idRooms = $objHotelCartBookingData->getCustomerIdRoomsByIdCartIdProduct(
$this->context->cart->id,
$orderProduct['id_product'],
date('Y-m-d', strtotime($date_from)),
date('Y-m-d', strtotime($date_to))
)) {
$productPriceTI = Product::getPriceStatic((int) $orderProduct['id_product'], true);
$productPriceTE = Product::getPriceStatic((int) $orderProduct['id_product'], false);
if ($productPriceTE) {
$taxRate = (($productPriceTI-$productPriceTE)/$productPriceTE)*100;
} else {
$taxRate = 0;
}
$taxRateM = $taxRate/100;
if (isset($orderProduct['amount'])) {
$orderProduct['amount'] = (float)$orderProduct['amount']/(1+$taxRateM);
foreach ($idRooms as $idRoom) {
$hrt_feature_price = new HotelRoomTypeFeaturePricing();
$hrt_feature_price->id_product = (int) $orderProduct['id_product'];
$hrt_feature_price->id_cart = (int) $this->context->cart->id;
$hrt_feature_price->id_guest = (int) $this->context->cart->id_guest;
foreach(Language::getLanguages(true) as $lang) {
$hrt_feature_price->feature_price_name[$lang['id_lang']] = 'csvprice';
}
$hrt_feature_price->date_selection_type = HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE;
$hrt_feature_price->date_from = date('Y-m-d', strtotime($date_from));
$hrt_feature_price->date_to = date('Y-m-d', strtotime($date_to));
$hrt_feature_price->is_special_days_exists = 0;
$hrt_feature_price->id_room = $idRoom['id_room'];
$hrt_feature_price->special_days = json_encode(false);
$hrt_feature_price->impact_way = HotelRoomTypeFeaturePricing::IMPACT_WAY_FIX_PRICE;
$hrt_feature_price->impact_type = HotelRoomTypeFeaturePricing::IMPACT_TYPE_FIXED_PRICE;
$hrt_feature_price->impact_value = $orderProduct['amount'];
$hrt_feature_price->active = 1;
$hrt_feature_price->groupBox = array_column(Group::getGroups($this->context->language->id), 'id_group');
$hrt_feature_price->add();
$featurePrices[] = $hrt_feature_price->id;
}
}
}
}
}
}
}
$amount = $this->context->cart->getOrderTotal(true);
$amount = $amount - $due_amount;
if ($this->context->cart->getProducts()) {
$objPayment = new CsvBooking();
if (!$objPayment->validateOrder(
(int) $this->context->cart->id,
$id_order_state,
$amount,
$this->l('CSV Import -- Admin'),
null,
array(),
(int) $orderInfo[$orderRefKey]['id_currency'],
false,
$objCustomer->secure_key
)) {
$this->errors[] = $this->l('Failed to create order for order reference '.$orderRefKey);
}
$amount = $this->context->cart->getOrderTotal(true);
$amount = $amount - $due_amount;
if ($this->context->cart->getProducts()) {
$objPayment = new CsvOrder();
if (!$objPayment->validateOrder(
(int) $this->context->cart->id,
$id_order_state,
$amount,
$this->l('CSV Import -- Admin'),
null,
array(),
(int) $orderInfo[$orderRefKey]['id_currency'],
false,
$objCustomer->secure_key
)) {
$this->errors[] = $this->l('Failed to create order for order reference '.$orderRefKey);
}
foreach ($featurePrices as $idPrice) {
$featue_price = new HotelRoomTypeFeaturePricing($idPrice);
$featue_price->delete();
foreach ($featurePrices as $idPrice) {
$featue_price = new HotelRoomTypeFeaturePricing($idPrice);
$featue_price->delete();
}
}
} else {
$this->warnings[] = $this->l('Order creation for the ').$objCountry->name.
$this->l(' is currently unavailable. Please activate the country to enable order creation.');
}
} else {
$this->warnings[] = $this->l('Order creation for the ').$objCountry->name.
$this->l(' is currently unavailable. Please activate the country to enable order creation.');
$this->warnings[] = sprintf(
Tools::displayError('No address found for the customer ID: %1$s'),
(isset($objCustomer->id) && !empty($objCustomer->id))? $objCustomer->id : 'null'
);
}
} else {
$this->warnings[] = sprintf(
Tools::displayError('No address found for the customer ID: %1$s'),
Tools::displayError('You cannot upload booking for guest account. (Customer ID: %1$s)'),
(isset($objCustomer->id) && !empty($objCustomer->id))? $objCustomer->id : 'null'
);
}
} else {
$this->warnings[] = sprintf(
Tools::displayError('You cannot upload booking for guest account. (Customer ID: %1$s)'),
(isset($objCustomer->id) && !empty($objCustomer->id))? $objCustomer->id : 'null'
Tools::displayError('No customer found for Customer ID: %1$s'),
(isset($idCustomer) && !empty($idCustomer))? $idCustomer : 'null'
);
}
}