Пример #1
0
 public function cash_on_economic_delivered_buy_now($cartId = 0)
 {
     $this->session->set_userdata(array('log_MODULE' => 'cash_on_economic_delivered_buy_now', 'log_MID' => ''));
     $this->data['title'] = 'Cash On Delivery';
     $cartId = id_decrypt($cartId);
     $this->custom_log->write_log('custom_log', 'Buy now Cart id is ' . $cartId);
     $userId = $this->session->userdata('userId');
     $this->custom_log->write_log('custom_log', 'login user id is ' . $userId);
     if (!$userId) {
         $this->session->set_flashdata('error', $this->lang->line('error_user_login'));
         $this->custom_log->write_log('custom_log', $this->lang->line('error_user_login'));
         redirect(base_url());
     }
     if (!$cartId) {
         $this->session->set_flashdata('error', 'Buy now cart id not found');
         $this->custom_log->write_log('custom_log', 'Buy now cart id not found');
         redirect(base_url());
     }
     $shippCusAddId = $this->session->userdata('shippingAddressId');
     $this->custom_log->write_log('custom_log', 'Customer shipping address id is ' . $shippCusAddId);
     if (empty($shippCusAddId)) {
         $this->session->set_flashdata('error', 'Shipping Address not found');
         $this->custom_log->write_log('custom_log', 'Shipping Address not found');
         redirect(base_url() . 'frontend/product_buy_now/shipping_address/' . id_encrypt($cartId));
     }
     $cartDetails = $this->cart_m->buy_now_delivery_detail($cartId);
     $this->custom_log->write_log('custom_log', 'Buy Now page details is ' . print_r($cartDetails, true));
     if (empty($cartDetails)) {
         $this->session->set_flashdata('error', 'Buy now details not found');
         $this->custom_log->write_log('custom_log', 'Buy now details not found');
         redirect(base_url());
     }
     if ($_POST) {
         $this->custom_log->write_log('custom_log', 'after submit form is ' . print_r($_POST, true));
         $rules = check_captcha_rules();
         $this->form_validation->set_rules($rules);
         $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
         if ($this->form_validation->run()) {
             $cusOrderId = $this->config->item('add_orderId');
             $cusOrderId = $cusOrderId + $cartDetails->cartId;
             $customOrderId = $this->config->item('pre_orderId') . $cusOrderId;
             $this->custom_log->write_log('custom_log', 'custom order id is ' . $customOrderId);
             $atATimeProduct = $cartDetails->cartId;
             $this->custom_log->write_log('custom_log', 'at a time purchas product id is ' . $atATimeProduct);
             $retailerPrice = $cartDetails->retailerPrice;
             $productWeight = $cartDetails->productWeight;
             $pickupId = $cartDetails->pickupId;
             $displayPrice = $cartDetails->productAmt;
             $shipping_rate = 0;
             $standardDet = $this->cart_m->standard_delivery_details($cartDetails->organizationId, $userId);
             $this->custom_log->write_log('custom_log', 'standard delivery details is ' . print_r($standardDet, true));
             if ($cartDetails->freeShipPrdId) {
             } elseif ($cartDetails->freeShipCatId) {
             } elseif ($cartDetails->genuineShippFee) {
                 if (!empty($standardDet)) {
                     if ($standardDet->isCalculateShipp) {
                         $shipping_rate = $standardDet->shippingRate;
                         if ($standardDet->totalProductWeight > 10) {
                             $shipping_rate = $standardDet->shippingRate * $standardDet->totalProductWeight;
                         }
                     }
                 }
             }
             $this->custom_log->write_log('custom_log', 'Shipping Rate is ' . $shipping_rate);
             $totalAmt = $cartDetails->quantity * $displayPrice + $shipping_rate;
             $this->custom_log->write_log('custom_log', 'total amount after calculate shipping rate = ' . $totalAmt);
             $handlingPrice = $totalAmt * $this->config->item('space_point_comission') / 100;
             $this->custom_log->write_log('custom_log', 'Handling amount of total amout is ' . $handlingPrice);
             $amount = $totalAmt + $handlingPrice;
             $this->custom_log->write_log('custom_log', 'calculate amout is ' . $amount);
             $economicOrderArr = array();
             /********Add Standard Delivery Order************/
             $economicOrderArr['organizationId'] = $standardDet->organizationId;
             $economicOrderArr['fromDropshipId'] = $standardDet->fromDropshipId;
             $economicOrderArr['totalProductWeight'] = $standardDet->totalProductWeight;
             $economicOrderArr['shippingOrgId'] = $standardDet->finalShippingOrgId;
             $economicOrderArr['shippingRateId'] = $standardDet->finalShippingRateId;
             $economicOrderArr['customOrderId'] = $customOrderId;
             $economicOrderArr['cashHandlingPrice'] = $handlingPrice;
             $economicOrderArr['isCalculateShipp'] = $standardDet->isCalculateShipp;
             $this->order_m->unactive_economical_repeate_order_delivery($economicOrderArr);
             $orderEconomicalId = $this->order_m->add_economical_order_delivery($economicOrderArr);
             $this->custom_log->write_log('custom_log', 'economical delivery id is ' . $orderEconomicalId);
             /********Add Standard Delivery Order************/
             /*********Check customer as pointeforce***********/
             $isPointeForce = $this->session->userdata('isPointeForce');
             $this->custom_log->write_log('custom_log', 'customer is pointe force is ' . $isPointeForce);
             $pointeForceVerifiedStatus = 0;
             if (!empty($isPointeForce) && $isPointeForce) {
                 $details = $this->pointe_force_m->pointe_force_verification_details($userId);
                 $this->custom_log->write_log('custom_log', 'pointe force details is ' . print_r($details, true));
                 if (!empty($details)) {
                     $pointeForceVerifiedStatus = $details->verifiedStatus;
                 }
             }
             $this->custom_log->write_log('custom_log', 'verification status is ' . $pointeForceVerifiedStatus);
             /*********Check customer as pointeforce***********/
             $orderArr = array('orderTypeId' => 1, 'totalAmount' => $amount, 'customerId' => $this->session->userdata('userId'), 'quantity' => $cartDetails->quantity, 'chargedAmount' => $displayPrice, 'organizationProductId' => $cartDetails->organizationProductId, 'orderStatusId' => 1, 'orderEmail' => $this->session->userdata('userEmail'), 'shippingOrgId' => $cartDetails->shippingOrgId, 'shippingRateId' => $cartDetails->shippingRateId, 'customOrderId' => $customOrderId, 'atATimeProduct' => $atATimeProduct, 'colorId' => $cartDetails->colorId, 'size' => $cartDetails->size, 'isPickup' => 0, 'pickupId' => 0, 'payment_reference' => '', 'retrieval_reference' => '', 'transaction_reference' => '', 'merchant_reference' => '', 'transaction_date' => '', 'paymentStatus' => 0, 'toDropshipId' => $cartDetails->toDropshipId, 'retailerPrice' => $cartDetails->retailerPrice, 'spacePointePrice' => $cartDetails->spacePointePrice, 'cashAdminPrice' => $cartDetails->cashAdminPrice, 'cashAdminFee' => $cartDetails->cashAdminFee, 'genuineShippFee' => $cartDetails->genuineShippFee, 'categoryCommission' => $cartDetails->categoryCommission, 'marketingProductId' => $cartDetails->marketingProductId, 'productWeight' => $cartDetails->productWeight, 'cashHandlingPrice' => 0, 'pickupProccessPrice' => 0, 'retailerDiscount' => $cartDetails->retailerDiscount, 'freeShipCatId' => $cartDetails->freeShipCatId, 'freeShipPrdId' => $cartDetails->freeShipPrdId, 'productId' => $cartDetails->productId, 'productImageId' => $cartDetails->productImageId, 'isEconomicDelivery' => 1, 'inventoryHistoryId' => $cartDetails->inventoryHistoryId, 'pointeForceVerifiedStatus' => $pointeForceVerifiedStatus, 'spacepointeCommission2' => $cartDetails->spacePointePrice2, 'totalCommissionPrice' => $cartDetails->quantity * $cartDetails->spacePointePrice2);
             $this->custom_log->write_log('custom_log', 'order inserted array is ' . print_r($orderArr, true));
             $orderID = $this->order_m->add_order($orderArr);
             $this->custom_log->write_log('custom_log', 'last inserted query is ' . $this->db->last_query());
             $this->custom_log->write_log('custom_log', 'Created order id is ' . $orderID);
             if ($orderID) {
                 /**********shipping address for customer*************/
                 $shippCusAddId = $this->session->userdata('shippingAddressId');
                 $this->custom_log->write_log('custom_log', 'customer address id is ' . $shippCusAddId);
                 $orderaddressId = $this->order_m->add_order_address($orderID, $shippCusAddId);
                 /********shipping address for customer***************/
                 /**********billing address for customer*************/
                 $billCusDet = $this->customer_m->user_billing_details($this->session->userdata('userId'));
                 $this->custom_log->write_log('custom_log', 'customer billing details is ' . print_r($billCusDet, true));
                 $billCusAddId = 0;
                 if (!empty($billCusDet)) {
                     $billCusAddId = $billCusDet->addressId;
                 } else {
                     $billCusAddId = $shippCusAddId;
                 }
                 $this->order_m->add_billing_order_address($orderID, $billCusAddId);
                 /********billing address for customer***************/
                 $payOrderID = $this->order_m->add_order_payment($orderID, $orderArr);
                 $this->custom_log->write_log('custom_log', 'Payment order id is ' . $payOrderID);
                 if ($payOrderID) {
                     $orderTrackId = $this->order_m->add_order_track_details($orderID, 1);
                     $this->custom_log->write_log('custom_log', 'order track id is ' . $orderTrackId);
                     $orderDropshipCenterId = $this->order_m->add_order_dropship_center($orderID, $orderArr);
                     $this->custom_log->write_log('custom_log', 'order dropship center id is ' . $orderDropshipCenterId);
                     $freeShipOrderId = $this->order_m->add_order_free_shipping($orderID, $orderArr);
                     $this->custom_log->write_log('custom_log', 'free shipping order id is ' . $freeShipOrderId);
                     if ($this->order_m->reduce_product_quantity($cartDetails->organizationProductId, $cartDetails->quantity)) {
                         $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                         $this->custom_log->write_log('custom_log', $cartDetails->quantity . ' quantity is reduce from ' . $cartDetails->organizationProductId);
                         if ($cartDetails->colorId) {
                             if ($cartDetails->marketingProductId) {
                                 $this->order_m->reduce_product_color_quantity_from_marketing($cartDetails->marketingProductId, $cartDetails->colorId, $cartDetails->quantity);
                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                 $this->custom_log->write_log('custom_log', $cartDetails->quantity . ' quantity is reduce from ' . $cartDetails->marketingProductId . ' and color id is ' . $cartDetails->colorId);
                             } else {
                                 /*
                                 	$this->order_m->reduce_product_color_quantity($cartDetails->organizationProductId,$cartDetails->colorId,$cartDetails->quantity);
                                 	$this->custom_log->write_log('custom_log','last query is '.$this->db->last_query());
                                 	$this->custom_log->write_log('custom_log',$cartDetails->quantity.' quantity is reduce from '.$cartDetails->organizationProductId.' and color id is '.$cartDetails->colorId);
                                 */
                             }
                         }
                         if ($cartDetails->size) {
                             if ($cartDetails->marketingProductId) {
                                 $this->order_m->reduce_product_size_quantity_from_marketing($cartDetails->marketingProductId, $cartDetails->size, $cartDetails->quantity);
                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                 $this->custom_log->write_log('custom_log', $cartDetails->quantity . ' quantity is reduce from marketing product id is ' . $cartDetails->organizationProductId . ' and size is ' . $cartDetails->size);
                             } else {
                                 /*
                                 	$this->order_m->reduce_product_size_quantity($cartDetails->organizationProductId,$cartDetails->size,$cartDetails->quantity);
                                 	$this->custom_log->write_log('custom_log','last query is '.$this->db->last_query());
                                 	$this->custom_log->write_log('custom_log',$cartDetails->quantity.' quantity is reduce from '.$cartDetails->organizationProductId.' and size is '.$cartDetails->size);	
                                 */
                             }
                         }
                         if (!empty($cartDetails->marketingProductId) && $cartDetails->marketingProductId) {
                         } elseif (!empty($cartDetails->organizationColorSizeId) && $cartDetails->organizationColorSizeId) {
                             $this->order_m->reduce_orgnization_product_color_size_quantity($cartDetails->organizationColorSizeId, $cartDetails->quantity);
                             $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                             $this->custom_log->write_log('custom_log', $cartDetails->quantity . ' quantity is reduce from ' . $cartDetails->organizationColorSizeId);
                         }
                         $this->session->set_flashdata('success', $this->lang->line('success_add_order'));
                         $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('success_add_order'));
                         /***order History****************/
                         $orderHistoryId = $this->order_m->add_order_history($orderID, 1);
                         $this->custom_log->write_log('custom_log', 'order history id is ' . $orderHistoryId);
                         /***Order History****************/
                     }
                     $shippingVendor = '';
                     $estimateDay = 0;
                     $rateDetails = $this->shipping_m->shipping_vendor_details($cartDetails->shippingRateId);
                     $estimateDay = $rateDetails->ETA + $this->config->item('estimated_time_increase');
                     $shippingVendor = $rateDetails->organizationName;
                     $this->custom_log->write_log('custom_log', 'shipping rate details is ' . print_r($rateDetails, true));
                     $customerShippDet = $this->customer_m->address_details($shippCusAddId);
                     $this->custom_log->write_log('custom_log', 'Customer shipping details is ' . print_r($customerShippDet, true));
                     $shippingAddName = $customerShippDet->firstName . ' ' . $customerShippDet->lastName;
                     $shippingAddress = $customerShippDet->addressLine1 . ' ' . $customerShippDet->address_Line2 . ' ' . $customerShippDet->cityName . ',' . $customerShippDet->areaName . ' ' . $customerShippDet->stateName . ' - ' . $customerShippDet->zip;
                     $retailerDet = $this->order_m->order_retailer_with_product_details($cartDetails->organizationProductId);
                     $this->custom_log->write_log('custom_log', 'Retailer details is ' . print_r($retailerDet, true));
                     $imagePath = base_url() . 'img/no_image.jpg';
                     if (!empty($retailerDet->productImageName) && file_exists('uploads/product/' . $retailerDet->productImageName)) {
                         $imagePath = base_url() . 'uploads/product/' . $retailerDet->productImageName;
                     }
                     $color = '';
                     $size = '';
                     /**********mail for customer***************/
                     $mailData = array('email' => $this->session->userdata('userEmail'), 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerShippDet->phone, 'orderId' => $customOrderId, 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $cartDetails->quantity, 'subTotal' => number_format($displayPrice * $cartDetails->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $cartDetails->quantity, 2), 'subject' => 'Your Order Has Been Placed', 'pickupCenter' => '');
                     if ($this->email_m->send_mail($mailData)) {
                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                     } else {
                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                     }
                     $mailData = array('email' => '*****@*****.**', 'cc' => '', 'bcc' => '', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerShippDet->phone, 'orderId' => $customOrderId, 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $cartDetails->quantity, 'subTotal' => number_format($displayPrice * $cartDetails->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $cartDetails->quantity, 2), 'subject' => 'Your Order Has Been Placed', 'pickupCenter' => '');
                     if ($this->email_m->send_mail($mailData)) {
                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                     } else {
                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                     }
                     /******mail for retailer*******/
                     $mailData = array('email' => $retailerDet->email, 'cc' => '', 'slug' => 'order_placed_for_retailer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerShippDet->phone, 'orderId' => $customOrderId, 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $cartDetails->quantity, 'subTotal' => number_format($displayPrice * $cartDetails->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $cartDetails->quantity, 2), 'subject' => 'An order has been placed', 'pickupCenter' => '');
                     if ($this->email_m->send_mail($mailData)) {
                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                     } else {
                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                     }
                     $message = ' An Order for ' . $cartDetails->quantity . substr($retailerDet->code, 0, 20) . '  has been placed. Please confirm in the panel.';
                     $response = $this->twillo_m->send_mobile_message($retailerDet->businessPhoneCode . $retailerDet->businessPhone, $message);
                     $customer_order_message = substr($retailerDet->code, 0, 20) . ', order #  ' . $customOrderId . ' has been accepted & will be delivered in ' . $estimateDay . ' days.';
                     $response = $this->twillo_m->send_mobile_message('+234' . $customerShippDet->phone, $customer_order_message);
                     $this->custom_log->write_log('custom_log', 'send mail response is ' . print_r($response, true));
                     $response = $this->twillo_m->send_mobile_message($retailerDet->businessPhoneCode . $retailerDet->businessPhone, $message);
                     $this->custom_log->write_log('custom_log', 'send mail response is ' . print_r($response, true));
                     /*********add order pointeforce commission***********/
                     if (!empty($isPointeForce) && $isPointeForce) {
                         $orderPointeForceId = $this->order_m->add_order_pointe_force_commission($orderID, $orderArr);
                         $this->custom_log->write_log('custom_log', 'order pointe force id is ' . $orderPointeForceId);
                     }
                     /*********add order pointeforce commission***********/
                     $this->cart_m->remove_from_cart($cartId);
                     $this->cart_m->remove_economical_delivery_from_cart();
                     $this->cart->destroy();
                     $this->session->unset_userdata('isPickUp');
                     $this->session->unset_userdata('isChkAvl');
                     $this->session->unset_userdata('isBuyNowPickUp');
                     $this->session->unset_userdata('shippingAddressId');
                     $this->session->set_flashdata('success', 'Order created successfully');
                     $this->custom_log->write_log('custom_log', 'Order created successfully');
                     redirect(base_url() . 'frontend/order/order_complete_success/' . id_encrypt($atATimeProduct));
                 }
             }
         }
     }
     $shippCusDet = $this->customer_m->address_details($shippCusAddId);
     $this->data['purchaseFrom'] = 2;
     $this->data['shippCusDet'] = $shippCusDet;
     $this->data['cartDetails'] = $cartDetails;
     $this->data['cartId'] = $cartId;
     $this->data['isPickUp'] = 0;
     $this->data['payOnPickUp'] = 0;
     $this->frontendCustomView('checkout/cash_on_economic_delivered_buy_now', $this->data);
 }
Пример #2
0
 public function shipping_address()
 {
     $this->session->set_userdata(array('log_MODULE' => 'shipping_address', 'log_MID' => ''));
     $this->data['title'] = 'Shipping Address';
     $userId = $this->session->userdata('userId');
     $this->custom_log->write_log('custom_log', 'login user id is ' . $userId);
     if (!$userId) {
         $this->session->set_flashdata('error', $this->lang->line('error_user_login'));
         $this->custom_log->write_log('custom_log', $this->lang->line('error_user_login'));
         $this->session->unset_userdata('shippingAddressId');
         redirect(base_url());
     }
     $contents = $this->cart->contents();
     $total_cart = count($contents);
     if ($total_cart < 1) {
         $this->session->set_flashdata('error', 'cart is empty');
         $this->custom_log->write_log('custom_log', 'cart is empty');
         $this->session->unset_userdata('shippingAddressId');
         redirect(base_url());
     }
     $cartDetails = '';
     if (!empty($contents)) {
         $whereArr = array();
         foreach ($contents as $items) {
             $whereArr[] = '(cart.userIdentifier = "' . $items['rowid'] . '" AND cart.cartId = ' . $items['id'] . ')';
         }
         if (!empty($whereArr)) {
             $where = '(' . implode(' OR ', $whereArr) . ')';
             $cartDetails = $this->cart_m->cart_list($where);
         }
     }
     $this->custom_log->write_log('custom_log', 'cart details is ' . print_r($cartDetails, true));
     if (empty($cartDetails)) {
         $this->session->set_flashdata('error', 'Cart details not found');
         $this->custom_log->write_log('custom_log', 'Cart details not found');
         $this->session->unset_userdata('shippingAddressId');
         redirect(base_url());
     }
     /*********Check customer as pointeforce***********/
     $isPointeForce = $this->session->userdata('isPointeForce');
     $this->custom_log->write_log('custom_log', 'customer is pointe force is ' . $isPointeForce);
     $pointeForceVerifiedStatus = 0;
     if (!empty($isPointeForce) && $isPointeForce) {
         $details = $this->pointe_force_m->pointe_force_verification_details($userId);
         $this->custom_log->write_log('custom_log', 'pointe force details is ' . print_r($details, true));
         if (!empty($details)) {
             $pointeForceVerifiedStatus = $details->verifiedStatus;
         }
     }
     $this->custom_log->write_log('custom_log', 'verification status is ' . $pointeForceVerifiedStatus);
     /*********Check customer as pointeforce***********/
     if ($_POST) {
         if (!empty($_POST['economicCapcha']) && $_POST['economicCapcha'] == 1) {
             $this->custom_log->write_log('custom_log', 'after submit form is ' . print_r($_POST, true));
             $rules = check_captcha_rules();
             $this->form_validation->set_rules($rules);
             $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
             if ($this->form_validation->run()) {
                 //	Customer Information
                 $customerDetails = $this->customer_m->get_customer_user_detail($userId);
                 $shippCusAddId = $this->session->userdata('shippingAddressId');
                 $contents = $this->cart->contents();
                 $total_cart = count($contents);
                 if (!$total_cart) {
                     $this->session->set_flashdata('error', 'cart list not found');
                     $this->custom_log->write_log('custom_log', 'cart list not found');
                     redirect(base_url());
                 }
                 if (!empty($contents)) {
                     $customOrderIdCart = array();
                     $customOrderIdRet = array();
                     $amount = 0;
                     $atATimeProduct = 0;
                     $retailerArr = array();
                     $retailerPrdArr = array();
                     $this->custom_log->write_log('custom_log', 'result array is ' . print_r($cartDetails, true));
                     if (!empty($cartDetails)) {
                         $atATimeProduct = $this->checkout_lib->cash_on_delivery_add_to_cart_single_shippment($cartDetails);
                         $this->custom_log->write_log('custom_log', 'at a time product id is ' . $atATimeProduct);
                         foreach ($cartDetails as $row) {
                             $cusOrderId = $this->config->item('add_orderId');
                             $cusOrderId = $cusOrderId + $row->cartId;
                             $customOrderId = $this->config->item('pre_orderId') . $cusOrderId;
                             $customOrderIdRet[$row->organizationId] = $customOrderId;
                             $this->custom_log->write_log('custom_log', 'custom order id is ' . $customOrderId);
                             $retailerPrdArr[$row->organizationId]['productDet'][$row->productId]['productAmt'] = $row->productAmt;
                             $retailerPrdArr[$row->organizationId]['productDet'][$row->productId]['productQty'] = $row->quantity;
                             $retailerPrdArr[$row->organizationId]['productDet'][$row->productId]['productName'] = $row->code;
                             $retailerPrdArr[$row->organizationId]['productDet'][$row->productId]['imageName'] = $row->imageName;
                         }
                         $this->custom_log->write_log('custom_log', 'custom order id array is ' . print_r($customOrderIdRet, true));
                         $economicOrderArr = array();
                         foreach ($cartDetails as $row) {
                             $customOrderIdCart[$row->cartId] = $customOrderIdRet[$row->organizationId];
                             $displayPrice = $row->productAmt;
                             $shipping_rate = 0;
                             $handlingPrice = 0;
                             $retailerPrdAmt = 0;
                             if (!empty($retailerArr[$row->organizationId])) {
                             } else {
                                 if (!empty($retailerPrdArr[$row->organizationId]['productDet'])) {
                                     foreach ($retailerPrdArr[$row->organizationId]['productDet'] as $retailerPrdKey => $retailerPrdVal) {
                                         $retailerPrdAmt = $retailerPrdAmt + $retailerPrdVal['productAmt'] * $retailerPrdVal['productQty'];
                                     }
                                     $standardDet = $this->cart_m->standard_delivery_details($row->organizationId, $userId);
                                     $this->custom_log->write_log('custom_log', 'standard delivery details is ' . print_r($standardDet, true));
                                     if (!empty($standardDet)) {
                                         if ($standardDet->isCalculateShipp) {
                                             $shippingRate = $standardDet->shippingRate;
                                             if ($standardDet->totalProductWeight > 10) {
                                                 $shippingRate = $standardDet->shippingRate * $standardDet->totalProductWeight;
                                             }
                                             $retailerPrdAmt = $retailerPrdAmt + $shippingRate;
                                         }
                                         $this->custom_log->write_log('custom_log', 'after calculate retailer product amount is ' . $retailerPrdAmt);
                                         $retailerPrdArr[$row->organizationId]['shippingOrgId'] = $standardDet->finalShippingOrgId;
                                         $retailerPrdArr[$row->organizationId]['shippingRateId'] = $standardDet->finalShippingRateId;
                                         $retailerPrdArr[$row->organizationId]['shippingRate'] = $standardDet->shippingRate;
                                         $retailerPrdArr[$row->organizationId]['shippingEta'] = $standardDet->ETA + $this->config->item('estimated_time_increase');
                                         $retailerPrdArr[$row->organizationId]['shippingOrgName'] = $standardDet->organizationName;
                                         $retailerPrdArr[$row->organizationId]['shippingOrgEmail'] = $standardDet->email;
                                         $retailerPrdArr[$row->organizationId]['shippingBsPhone'] = $standardDet->businessPhone;
                                         $retailerPrdArr[$row->organizationId]['isCalculateShipp'] = $standardDet->isCalculateShipp;
                                         $retailerPrdArr[$row->organizationId]['totalProductWeight'] = $standardDet->totalProductWeight;
                                         $retailerPrdArr[$row->organizationId]['retailerName'] = $row->organizationName;
                                         $retailerPrdArr[$row->organizationId]['retailerEmail'] = $row->email;
                                         $retailerPrdArr[$row->organizationId]['retailerBsPhoneCode'] = $row->businessPhoneCode;
                                         $retailerPrdArr[$row->organizationId]['retailerBsPhone'] = $row->businessPhone;
                                         $retailerPrdArr[$row->organizationId]['retailerStateId'] = $row->dropshipStateId;
                                         $this->custom_log->write_log('custom_log', 'retailer product amount is ' . $retailerPrdAmt);
                                         $handlingPrice = $retailerPrdAmt * $this->config->item('space_point_comission') / 100;
                                         $this->custom_log->write_log('custom_log', 'Cash Handling Price is ' . $handlingPrice);
                                         /********Add Standard Delivery Order***********/
                                         $economicOrderArr['organizationId'] = $standardDet->organizationId;
                                         $economicOrderArr['fromDropshipId'] = $standardDet->fromDropshipId;
                                         $economicOrderArr['totalProductWeight'] = $standardDet->totalProductWeight;
                                         $economicOrderArr['shippingOrgId'] = $standardDet->finalShippingOrgId;
                                         $economicOrderArr['shippingRateId'] = $standardDet->finalShippingRateId;
                                         $economicOrderArr['customOrderId'] = $customOrderIdCart[$row->cartId];
                                         $economicOrderArr['cashHandlingPrice'] = $handlingPrice;
                                         $economicOrderArr['isCalculateShipp'] = $standardDet->isCalculateShipp;
                                         $this->order_m->unactive_economical_repeate_order_delivery($economicOrderArr);
                                         $orderEconomicalId = $this->order_m->add_economical_order_delivery($economicOrderArr);
                                         $this->custom_log->write_log('custom_log', 'economical delivery id is ' . $orderEconomicalId);
                                         /********Add Standard Delivery Order**********/
                                     }
                                     $amount = $amount + $retailerPrdAmt + $handlingPrice;
                                     $retailerPrdArr[$row->organizationId]['cashHandlingPrice'] = $handlingPrice;
                                 }
                             }
                             $retailerArr[$row->organizationId] = $row->organizationId;
                         }
                         $this->custom_log->write_log('custom_log', 'at a time purchase id is ' . $atATimeProduct);
                         $this->custom_log->write_log('custom_log', 'Total AMount is ' . $amount);
                         //echo "<pre>"; print_r($retailerPrdArr); exit;
                         $customerAddDetails = $this->customer_m->customer_with_address_details($userId, $shippCusAddId);
                         $this->custom_log->write_log('custom_log', 'customer address details is ' . print_r($customerAddDetails, true));
                         $customerName = $customerAddDetails->addressFirstName . ' ' . $customerAddDetails->addressLastName;
                         $customerPhone = $customerAddDetails->addressPhoneNo;
                         $customerShippAdd = $customerAddDetails->addressLine1 . ' ' . $customerAddDetails->cityName . ',' . $customerAddDetails->areaName . ' ' . $customerAddDetails->stateName;
                         foreach ($cartDetails as $row) {
                             $orderArr = array('orderTypeId' => 2, 'totalAmount' => $amount, 'customerId' => $this->session->userdata('userId'), 'quantity' => $row->quantity, 'chargedAmount' => $row->productAmt, 'organizationProductId' => $row->organizationProductId, 'orderStatusId' => 1, 'orderEmail' => $this->session->userdata('userEmail'), 'shippingOrgId' => $retailerPrdArr[$row->organizationId]['shippingOrgId'], 'shippingRateId' => $retailerPrdArr[$row->organizationId]['shippingRateId'], 'customOrderId' => $customOrderIdCart[$row->cartId], 'atATimeProduct' => $atATimeProduct, 'colorId' => $row->colorId, 'size' => $row->size, 'isPickup' => 0, 'pickupId' => 0, 'payment_reference' => '', 'retrieval_reference' => '', 'transaction_reference' => '', 'merchant_reference' => '', 'transaction_date' => '', 'paymentStatus' => 0, 'toDropshipId' => $row->toDropshipId, 'retailerPrice' => $row->retailerPrice, 'spacePointePrice' => $row->spacePointePrice, 'cashAdminPrice' => $row->cashAdminPrice, 'cashAdminFee' => $row->cashAdminFee, 'genuineShippFee' => $row->genuineShippFee, 'categoryCommission' => $row->categoryCommission, 'marketingProductId' => $row->marketingProductId, 'cashHandlingPrice' => 0, 'pickupProccessPrice' => 0, 'productWeight' => $row->productWeight, 'retailerDiscount' => $row->retailerDiscount, 'freeShipCatId' => $row->freeShipCatId, 'freeShipPrdId' => $row->freeShipPrdId, 'productId' => $row->productId, 'productImageId' => $row->productImageId, 'isEconomicDelivery' => 1, 'inventoryHistoryId' => $row->inventoryHistoryId, 'pointeForceVerifiedStatus' => $pointeForceVerifiedStatus, 'spacepointeCommission2' => $row->spacePointePrice2, 'totalCommissionPrice' => $row->quantity * $row->spacePointePrice2);
                             //echo "<pre>"; print_r($orderArr); exit;
                             $orderID = $this->order_m->add_order($orderArr);
                             $this->custom_log->write_log('custom_log', 'order inserted array is ' . print_r($orderArr, true));
                             $this->custom_log->write_log('custom_log', 'Created order id is ' . $orderID);
                             if ($orderID) {
                                 /**********shipping address for customer*************/
                                 $shippCusAddId = $this->session->userdata('shippingAddressId');
                                 $this->custom_log->write_log('custom_log', 'customer address id is ' . $shippCusAddId);
                                 $orderaddressId = $this->order_m->add_order_address($orderID, $shippCusAddId);
                                 /********shipping address for customer***************/
                                 /**********billing address for customer*************/
                                 $billCusDet = $this->customer_m->user_billing_details($this->session->userdata('userId'));
                                 $this->custom_log->write_log('custom_log', 'customer billing details is ' . print_r($billCusDet, true));
                                 $billCusAddId = 0;
                                 if (!empty($billCusDet)) {
                                     $billCusAddId = $billCusDet->addressId;
                                 } else {
                                     $billCusAddId = $shippCusAddId;
                                 }
                                 $this->order_m->add_billing_order_address($orderID, $billCusAddId);
                                 /********billing address for customer***************/
                                 $payOrderID = $this->order_m->add_order_payment($orderID, $orderArr);
                                 $this->custom_log->write_log('custom_log', 'Payment order id is ' . $payOrderID);
                                 if ($payOrderID) {
                                     $orderTrackId = $this->order_m->add_order_track_details($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order track id is ' . $orderTrackId);
                                     $orderDropshipCenterId = $this->order_m->add_order_dropship_center($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'order dropship center id is ' . $orderDropshipCenterId);
                                     $freeShipOrderId = $this->order_m->add_order_free_shipping($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'free shipping order id is ' . $freeShipOrderId);
                                     if ($this->order_m->reduce_product_quantity($row->organizationProductId, $row->quantity)) {
                                         $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                         $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationProductId);
                                         if ($row->colorId) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_color_quantity_from_marketing($row->marketingProductId, $row->colorId, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->marketingProductId . ' and color id is ' . $row->colorId);
                                             } else {
                                                 /*
                                                 	$this->order_m->reduce_product_color_quantity($row->organizationProductId,$row->colorId,$row->quantity);
                                                 	$this->custom_log->write_log('custom_log','last query is '.$this->db->last_query());
                                                 	$this->custom_log->write_log('custom_log',$row->quantity.' quantity is reduce from '.$row->organizationProductId.' and color id is '.$row->colorId);
                                                 */
                                             }
                                         }
                                         if ($row->size) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_size_quantity_from_marketing($row->marketingProductId, $row->size, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from marketing product id is ' . $row->organizationProductId . ' and size is ' . $row->size);
                                             } else {
                                                 /*
                                                 	$this->order_m->reduce_product_size_quantity($row->organizationProductId,$row->size,$row->quantity);
                                                 	$this->custom_log->write_log('custom_log','last query is '.$this->db->last_query());
                                                 	$this->custom_log->write_log('custom_log',$row->quantity.' quantity is reduce from '.$row->organizationProductId.' and size is '.$row->size);	
                                                 */
                                             }
                                         }
                                         if (!empty($row->marketingProductId) && $row->marketingProductId) {
                                         } elseif (!empty($row->organizationColorSizeId) && $row->organizationColorSizeId) {
                                             $this->order_m->reduce_orgnization_product_color_size_quantity($row->organizationColorSizeId, $row->quantity);
                                             $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                             $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationColorSizeId);
                                         }
                                     }
                                     $this->session->set_flashdata('success', $this->lang->line('success_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('success_add_order'));
                                     /***order History****************/
                                     $orderHistoryId = $this->order_m->add_order_history($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order history id is ' . $orderHistoryId);
                                     /***Order History****************/
                                     /*********add order pointeforce commission***********/
                                     if (!empty($isPointeForce) && $isPointeForce) {
                                         $orderPointeForceId = $this->order_m->add_order_pointe_force_commission($orderID, $orderArr);
                                         $this->custom_log->write_log('custom_log', 'order pointe force id is ' . $orderPointeForceId);
                                     }
                                     /*********add order pointeforce commission***********/
                                 } else {
                                     $this->session->set_flashdata('error', $this->lang->line('error_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('error_add_order'));
                                 }
                             }
                         }
                         foreach ($retailerPrdArr as $retailerKey => $retailerRow) {
                             $mailContent = '<table width="100%" class="order-table" style="border-bottom:2px solid #6d6d6d; padding-bottom:5px;"><tbody>';
                             if (!empty($retailerRow['productDet'])) {
                                 $mailContent .= '<tr><th colspan="2">Item </th><th style="text-align:center;"> Item price </th><th style="text-align:center;"> Qty </th><th style="text-align:right;"> Subtotal </th></tr>';
                                 foreach ($retailerRow['productDet'] as $prodctRow) {
                                     $imagePath = base_url() . 'img/no_image.jpg';
                                     if (!empty($prodctRow['imageName']) && file_exists('uploads/product/thumb500_500/' . $prodctRow['imageName'])) {
                                         $imagePath = base_url() . 'uploads/product/thumb500_500/' . $prodctRow['imageName'];
                                     } elseif (!empty($prodctRow['imageName']) && file_exists('uploads/product/' . $prodctRow['imageName'])) {
                                         $imagePath = base_url() . 'uploads/product/' . $prodctRow['imageName'];
                                     }
                                     $mailContent .= '<tr><td  style="text-align:center;"><img src="' . $imagePath . '" width="45px"></td><td style="text-align:center;">' . $prodctRow['productName'] . '</td><td style="text-align:center;">&#x20A6;' . $prodctRow['productAmt'] . '</td><td style="text-align:center;">' . $prodctRow['productQty'] . '</td><td style="text-align:right;">&#x20A6;' . $prodctRow['productAmt'] * $prodctRow['productQty'] . '</td></tr>';
                                     $message = 'An Order for ' . $prodctRow['productQty'] . substr($prodctRow['productName'], 0, 20) . ' has been placed. Please confirm in the panel.';
                                     $response = $this->twillo_m->send_mobile_message($retailerRow['retailerBsPhoneCode'] . $retailerRow['retailerBsPhone'], $message);
                                     $this->custom_log->write_log('custom_log', 'Message send response is ' . print_r($response, true));
                                     $customer_order_message = substr($prodctRow['productAmt'], 0, 20) . ', order #  ' . $customOrderIdRet[$retailerKey] . ' has been accepted & will be delivered in ' . $retailerRow['shippingEta'] . ' days.';
                                     $response = $this->twillo_m->send_mobile_message('+234' . $customerPhone, $customer_order_message);
                                     $this->custom_log->write_log('custom_log', 'send message response is ' . print_r($response, true));
                                 }
                             }
                             $mailContent .= '</tbody></table>';
                             /*******Customer mail*****************/
                             $mailData = array('email' => $this->session->userdata('userEmail'), 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'economic_order_placed_for_customer', 'customerName' => $customerName, 'customerPhone' => $customerPhone, 'orderId' => $customOrderIdRet[$retailerKey], 'eta' => $retailerRow['shippingEta'], 'shippingVendor' => $retailerRow['shippingOrgName'], 'shippingAddName' => $customerName, 'shippingAddress' => $customerShippAdd, 'sellerName' => $retailerRow['retailerName'], 'mailContent' => $mailContent, 'totalAmount' => number_format($amount, 2), 'subject' => 'Your Order Has Been Placed');
                             if ($this->email_m->send_mail($mailData)) {
                                 $customer_order_message = 'Your order has been recieved for ' . $customOrderIdRet[$retailerKey] . ', will be delivered in ' . $retailerRow['shippingEta'] . ' days';
                                 $response = $this->twillo_m->send_mobile_message('+234' . $customerPhone, $customer_order_message);
                                 $this->custom_log->write_log('custom_log', 'send message response is ' . print_r($response, true));
                                 $this->custom_log->write_log('custom_log', 'Mail send successfully');
                             } else {
                                 $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                             }
                             /*******Customer mail ******/
                             /*******Mail send to neworders@spacepointe.com***********/
                             $mailData = array('email' => '*****@*****.**', 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'economic_order_placed_for_customer', 'customerName' => $customerName, 'customerPhone' => $customerPhone, 'orderId' => $customOrderIdRet[$retailerKey], 'eta' => $retailerRow['shippingEta'], 'shippingVendor' => $retailerRow['shippingOrgName'], 'shippingAddName' => $customerName, 'shippingAddress' => $customerShippAdd, 'sellerName' => $retailerRow['retailerName'], 'mailContent' => $mailContent, 'totalAmount' => number_format($amount, 2), 'subject' => 'Your Order Has Been Placed');
                             if ($this->email_m->send_mail($mailData)) {
                                 $this->custom_log->write_log('custom_log', 'Mail send successfully');
                             } else {
                                 $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                             }
                             /*******Mail send to neworders@spacepointe.com***********/
                             /******mail for retailer*******/
                             if (!empty($retailerRow['retailerEmail'])) {
                                 $mailData = array('email' => $retailerRow['retailerEmail'], 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'economic_order_placed_for_customer', 'customerName' => $customerName, 'customerPhone' => $customerPhone, 'orderId' => $customOrderIdRet[$retailerKey], 'eta' => $retailerRow['shippingEta'], 'shippingVendor' => $retailerRow['shippingOrgName'], 'shippingAddName' => $customerName, 'shippingAddress' => $customerShippAdd, 'sellerName' => $retailerRow['retailerName'], 'mailContent' => $mailContent, 'totalAmount' => number_format($amount, 2), 'subject' => 'An order has been placed');
                                 if ($this->email_m->send_mail($mailData)) {
                                     $this->custom_log->write_log('custom_log', 'Mail send successfully');
                                 } else {
                                     $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                                 }
                             }
                             /******mail for retailer*******/
                         }
                         if (!empty($where)) {
                             $this->cart_m->remove_to_cart($where);
                             $this->cart_m->remove_economical_delivery_from_cart();
                         }
                         $this->cart->destroy();
                         $this->session->unset_userdata('isPickUp');
                         $this->session->unset_userdata('isChkAvl');
                         $this->session->unset_userdata('shippingAddressId');
                         $this->session->set_flashdata('success', 'Order created successfully');
                         $this->custom_log->write_log('custom_log', 'Order created successfully');
                         redirect(base_url() . 'frontend/order/order_complete_success/' . id_encrypt($atATimeProduct));
                     }
                 } else {
                     $this->session->set_flashdata('error', 'Cart Details not found');
                     $this->custom_log->write_log('custom_log', 'Cart Details not found');
                     redirect(base_url());
                 }
             }
         } elseif (!empty($_POST['economicCapcha']) && $_POST['economicCapcha'] == 2) {
             $this->custom_log->write_log('custom_log', 'after submit form is ' . print_r($_POST, true));
             $rules = check_captcha_rules();
             $this->form_validation->set_rules($rules);
             $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
             if ($this->form_validation->run()) {
                 //	Customer Information
                 $customerDetails = $this->customer_m->get_customer_user_detail($userId);
                 $contents = $this->cart->contents();
                 $total_cart = count($contents);
                 if (!$total_cart) {
                     $this->session->set_flashdata('error', 'cart list not found');
                     $this->custom_log->write_log('custom_log', 'cart list not found');
                     redirect(base_url());
                 }
                 if (!empty($contents)) {
                     $customOrderIdCart = array();
                     $customOrderIdRet = array();
                     $mailContaint = '';
                     $amount = 0;
                     $atATimeProduct = 0;
                     if (!empty($cartDetails)) {
                         $atATimeProduct = $this->checkout_lib->cash_on_delivery_add_to_cart_quick_shippment($cartDetails);
                         $this->custom_log->write_log('custom_log', 'at a time product id is ' . $atATimeProduct);
                         foreach ($cartDetails as $row) {
                             $retailerDet = $this->order_m->order_retailer_details($row->organizationProductId);
                             if (!empty($retailerDet)) {
                                 $cusOrderId = $this->config->item('add_orderId');
                                 $cusOrderId = $cusOrderId + $row->cartId;
                                 $customOrderId = $this->config->item('pre_orderId') . $cusOrderId;
                                 $customOrderIdRet[$retailerDet->organizationId] = $customOrderId;
                                 $this->custom_log->write_log('custom_log', 'custom order id is ' . $customOrderId);
                             }
                         }
                         $this->custom_log->write_log('custom_log', 'custom order id array is ' . print_r($customOrderIdRet, true));
                         foreach ($cartDetails as $row) {
                             $retailerDet = $this->order_m->order_retailer_details($row->organizationProductId);
                             if (!empty($retailerDet)) {
                                 $productWeight = $row->productWeight;
                                 $displayPrice = $row->productAmt;
                                 $spacePointePrice = $row->spacePointePrice;
                                 $cashAdminPrice = $row->cashAdminPrice;
                                 $cashAdminFee = $row->cashAdminFee;
                                 $categoryCommission = $row->categoryCommission;
                                 $genuineShippFee = $row->genuineShippFee;
                                 $shipping_rate = 0;
                                 if ($row->freeShipPrdId) {
                                 } elseif ($row->freeShipCatId) {
                                 } elseif ($genuineShippFee) {
                                     $shippingRate = $row->shippingRate;
                                     if ($productWeight > 10) {
                                         $shippingRate = $row->shippingRate * $productWeight;
                                     }
                                     $shipping_rate = $shipping_rate + $row->quantity * $shippingRate;
                                 }
                                 $customOrderIdCart[$row->cartId] = $customOrderIdRet[$retailerDet->organizationId];
                                 $amount = $amount + $displayPrice * $row->quantity + $shipping_rate;
                             }
                         }
                     }
                     $this->custom_log->write_log('custom_log', 'at a time purchase id is ' . $atATimeProduct);
                     $handlingPrice = $amount * $this->config->item('space_point_comission') / 100;
                     $this->custom_log->write_log('custom_log', 'Cash Handling Price is ' . $handlingPrice);
                     $amount = $amount + $handlingPrice;
                     $this->custom_log->write_log('custom_log', 'Total AMount is ' . $amount);
                     $this->custom_log->write_log('custom_log', 'result array is ' . print_r($cartDetails, true));
                     if (!empty($cartDetails)) {
                         foreach ($cartDetails as $row) {
                             $productId = $row->productId;
                             $retailerPrice = $row->retailerPrice;
                             $productWeight = $row->weight + $row->shippingWeight;
                             $spacePointePrice = $row->spacePointePrice;
                             $cashAdminPrice = $row->cashAdminPrice;
                             $cashAdminFee = $row->cashAdminFee;
                             $categoryCommission = $row->categoryCommission;
                             $genuineShippFee = $row->genuineShippFee;
                             $displayPrice = $row->productAmt;
                             $shipping_rate = 0;
                             $cashHandlingPrice = 0;
                             if ($row->freeShipPrdId) {
                             } elseif ($row->freeShipCatId) {
                             } elseif ($row->genuineShippFee) {
                                 $shipping_rate = $row->shippingRate * $row->quantity;
                                 if ($productWeight > 10) {
                                     $shipping_rate = $row->shippingRate * $row->quantity * $productWeight;
                                 }
                             }
                             $this->custom_log->write_log('custom_log', 'Shipping Rate is ' . $shipping_rate);
                             $ttlAmt = $row->quantity * $displayPrice + $shipping_rate;
                             $this->custom_log->write_log('custom_log', 'total amount after calculate shipping rate = ' . $ttlAmt);
                             $cashHandlingPrice = $ttlAmt * $this->config->item('space_point_comission') / 100;
                             $this->custom_log->write_log('custom_log', 'cash Handling amount of total amout is ' . $cashHandlingPrice);
                             $orderArr = array('orderTypeId' => 2, 'totalAmount' => $amount, 'customerId' => $this->session->userdata('userId'), 'quantity' => $row->quantity, 'chargedAmount' => $displayPrice, 'organizationProductId' => $row->organizationProductId, 'orderStatusId' => 1, 'orderEmail' => $this->session->userdata('userEmail'), 'shippingOrgId' => $row->shippingOrgId, 'shippingRateId' => $row->shippingRateId, 'customOrderId' => $customOrderIdCart[$row->cartId], 'atATimeProduct' => $atATimeProduct, 'colorId' => $row->colorId, 'size' => $row->size, 'isPickup' => 0, 'pickupId' => 0, 'payment_reference' => '', 'retrieval_reference' => '', 'transaction_reference' => '', 'merchant_reference' => '', 'transaction_date' => '', 'paymentStatus' => 0, 'toDropshipId' => $row->toDropshipId, 'retailerPrice' => $retailerPrice, 'spacePointePrice' => $spacePointePrice, 'cashAdminPrice' => $cashAdminPrice, 'cashAdminFee' => $cashAdminFee, 'genuineShippFee' => $genuineShippFee, 'categoryCommission' => $categoryCommission, 'marketingProductId' => $row->marketingProductId, 'cashHandlingPrice' => $cashHandlingPrice, 'pickupProccessPrice' => 0, 'productWeight' => $row->productWeight, 'retailerDiscount' => $row->retailerDiscount, 'freeShipCatId' => $row->freeShipCatId, 'freeShipPrdId' => $row->freeShipPrdId, 'productId' => $row->productId, 'productImageId' => $row->productImageId, 'isEconomicDelivery' => 0, 'inventoryHistoryId' => $row->inventoryHistoryId, 'pointeForceVerifiedStatus' => $pointeForceVerifiedStatus, 'spacepointeCommission2' => $row->spacePointePrice2, 'totalCommissionPrice' => $row->quantity * $row->spacePointePrice2);
                             //echo "<pre>"; print_r($orderArr); exit;
                             $orderID = $this->order_m->add_order($orderArr);
                             $this->custom_log->write_log('custom_log', 'order inserted array is ' . print_r($orderArr, true));
                             $this->custom_log->write_log('custom_log', 'Created order id is ' . $orderID);
                             if ($orderID) {
                                 /**********shipping address for customer*************/
                                 $shippCusAddId = $this->session->userdata('shippingAddressId');
                                 $orderaddressId = $this->order_m->add_order_address($orderID, $shippCusAddId);
                                 /********shipping address for customer***************/
                                 /**********billing address for customer*************/
                                 $billCusDet = $this->customer_m->user_billing_details($this->session->userdata('userId'));
                                 $this->custom_log->write_log('custom_log', 'customer billing details is ' . print_r($billCusDet, true));
                                 $billCusAddId = 0;
                                 if (!empty($billCusDet)) {
                                     $billCusAddId = $billCusDet->addressId;
                                 } else {
                                     $billCusAddId = $shippCusAddId;
                                 }
                                 $this->order_m->add_billing_order_address($orderID, $billCusAddId);
                                 /********billing address for customer***************/
                                 $payOrderID = $this->order_m->add_order_payment($orderID, $orderArr);
                                 $this->custom_log->write_log('custom_log', 'Payment order id is ' . $payOrderID);
                                 if ($payOrderID) {
                                     $orderTrackId = $this->order_m->add_order_track_details($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order track id is ' . $orderTrackId);
                                     $orderDropshipCenterId = $this->order_m->add_order_dropship_center($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'order dropship center id is ' . $orderDropshipCenterId);
                                     $freeShipOrderId = $this->order_m->add_order_free_shipping($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'free shipping order id is ' . $freeShipOrderId);
                                     if ($this->order_m->reduce_product_quantity($row->organizationProductId, $row->quantity)) {
                                         $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                         $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationProductId);
                                         if ($row->colorId) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_color_quantity_from_marketing($row->marketingProductId, $row->colorId, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->marketingProductId . ' and color id is ' . $row->colorId);
                                             }
                                         }
                                         if ($row->size) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_size_quantity_from_marketing($row->marketingProductId, $row->size, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from marketing product id is ' . $row->organizationProductId . ' and size is ' . $row->size);
                                             }
                                         }
                                         if (!empty($row->marketingProductId) && $row->marketingProductId) {
                                         } elseif (!empty($row->organizationColorSizeId) && $row->organizationColorSizeId) {
                                             $this->order_m->reduce_orgnization_product_color_size_quantity($row->organizationColorSizeId, $row->quantity);
                                             $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                             $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationColorSizeId);
                                         }
                                     }
                                     $this->session->set_flashdata('success', $this->lang->line('success_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('success_add_order'));
                                     /***order History****************/
                                     $orderHistoryId = $this->order_m->add_order_history($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order history id is ' . $orderHistoryId);
                                     /***Order History****************/
                                     $shippingVendor = '';
                                     $estimateDay = 0;
                                     $rateDetails = $this->shipping_m->shipping_vendor_details($row->shippingRateId);
                                     $estimateDay = $rateDetails->ETA + $this->config->item('estimated_time_increase');
                                     $shippingVendor = $rateDetails->organizationName;
                                     $customerShippDet = $this->customer_m->address_details($shippCusAddId);
                                     $shippingAddName = $customerShippDet->firstName . ' ' . $customerShippDet->lastName;
                                     $shippingAddress = $customerShippDet->addressLine1 . ' ' . $customerShippDet->address_Line2 . ' ' . $customerShippDet->cityName . ',' . $customerShippDet->areaName . ' ' . $customerShippDet->stateName . ' - ' . $customerShippDet->zip;
                                     $retailerDet = $this->order_m->order_retailer_with_product_details($row->organizationProductId);
                                     $imagePath = base_url() . 'img/no_image.jpg';
                                     if (!empty($retailerDet->productImageName) && file_exists('uploads/product/' . $retailerDet->productImageName)) {
                                         $imagePath = base_url() . 'uploads/product/' . $retailerDet->productImageName;
                                     }
                                     $color = '';
                                     $size = '';
                                     $mailData = array('email' => $this->session->userdata('userEmail'), 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerDetails->phone, 'orderId' => $customOrderIdCart[$row->cartId], 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $row->quantity, 'subTotal' => number_format($displayPrice * $row->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $row->quantity, 2), 'subject' => 'Your Order Has Been Placed');
                                     if ($this->email_m->send_mail($mailData)) {
                                         $customer_order_message = 'Your order has been recieved for ' . substr($retailerDet->code, 0, 15) . ', will be delivered in ' . $estimateDay . ' days';
                                         $response = $this->twillo_m->send_mobile_message('+234' . $customerDetails->phone, $customer_order_message);
                                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                                     } else {
                                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                                     }
                                     $mailData = array('email' => '*****@*****.**', 'cc' => '', 'bcc' => '', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerDetails->phone, 'orderId' => $customOrderIdCart[$row->cartId], 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $row->quantity, 'subTotal' => number_format($displayPrice * $row->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $row->quantity, 2), 'subject' => 'Your Order Has Been Placed');
                                     if ($this->email_m->send_mail($mailData)) {
                                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                                     } else {
                                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                                     }
                                     /*********add order pointeforce commission***********/
                                     if (!empty($isPointeForce) && $isPointeForce) {
                                         $orderPointeForceId = $this->order_m->add_order_pointe_force_commission($orderID, $orderArr);
                                         $this->custom_log->write_log('custom_log', 'order pointe force id is ' . $orderPointeForceId);
                                     }
                                     /*********add order pointeforce commission***********/
                                 } else {
                                     $this->session->set_flashdata('error', $this->lang->line('error_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('error_add_order'));
                                 }
                             }
                         }
                         if (!empty($where)) {
                             $this->cart_m->remove_to_cart($where);
                         }
                         $this->cart->destroy();
                         $this->session->unset_userdata('isPickUp');
                         $this->session->unset_userdata('isChkAvl');
                         $this->session->unset_userdata('shippingAddressId');
                         $this->session->set_flashdata('success', 'Order created successfully');
                         $this->custom_log->write_log('custom_log', 'Order created successfully');
                         redirect(base_url() . 'frontend/order/order_complete_success/' . id_encrypt($atATimeProduct));
                     } else {
                         $this->session->set_flashdata('error', 'Cart Details not found');
                         $this->custom_log->write_log('custom_log', 'Cart Details not found');
                     }
                 } else {
                     redirect(base_url());
                 }
             }
         } elseif (!empty($_POST['economicCapcha']) && $_POST['economicCapcha'] == 3) {
             $this->custom_log->write_log('custom_log', 'after submit form is ' . print_r($_POST, true));
             $rules = check_captcha_rules();
             $this->form_validation->set_rules($rules);
             $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
             if ($this->form_validation->run()) {
                 //	Customer Information
                 $customerDetails = $this->customer_m->get_customer_user_detail($userId);
                 $contents = $this->cart->contents();
                 $total_cart = count($contents);
                 if (!$total_cart) {
                     $this->session->set_flashdata('error', 'cart list not found');
                     $this->custom_log->write_log('custom_log', 'cart list not found');
                     redirect(base_url());
                 }
                 if (!empty($contents)) {
                     $customOrderIdCart = array();
                     $customOrderIdRet = array();
                     $mailContaint = '';
                     $amount = 0;
                     $atATimeProduct = 0;
                     if (!empty($cartDetails)) {
                         $atATimeProduct = $this->checkout_lib->cash_on_delivery_add_to_cart_same_day_delivery($cartDetails);
                         $this->custom_log->write_log('custom_log', 'at a time product id is ' . $atATimeProduct);
                         foreach ($cartDetails as $row) {
                             $retailerDet = $this->order_m->order_retailer_details($row->organizationProductId);
                             if (!empty($retailerDet)) {
                                 $cusOrderId = $this->config->item('add_orderId');
                                 $cusOrderId = $cusOrderId + $row->cartId;
                                 $customOrderId = $this->config->item('pre_orderId') . $cusOrderId;
                                 $customOrderIdRet[$retailerDet->organizationId] = $customOrderId;
                                 $this->custom_log->write_log('custom_log', 'custom order id is ' . $customOrderId);
                             }
                         }
                         $this->custom_log->write_log('custom_log', 'custom order id array is ' . print_r($customOrderIdRet, true));
                         foreach ($cartDetails as $row) {
                             $retailerDet = $this->order_m->order_retailer_details($row->organizationProductId);
                             if (!empty($retailerDet)) {
                                 $productWeight = $row->productWeight;
                                 $displayPrice = $row->productAmt;
                                 $spacePointePrice = $row->spacePointePrice;
                                 $cashAdminPrice = $row->cashAdminPrice;
                                 $cashAdminFee = $row->cashAdminFee;
                                 $categoryCommission = $row->categoryCommission;
                                 $genuineShippFee = $row->genuineShippFee;
                                 $shipping_rate = 0;
                                 if ($row->freeShipPrdId) {
                                 } elseif ($row->freeShipCatId) {
                                 } elseif ($genuineShippFee) {
                                     $shippingRate = $row->shippingRate;
                                     if ($productWeight > 10) {
                                         $shippingRate = $row->shippingRate * $productWeight;
                                     }
                                     $shipping_rate = $shipping_rate + $row->quantity * $shippingRate;
                                 }
                                 $customOrderIdCart[$row->cartId] = $customOrderIdRet[$retailerDet->organizationId];
                                 $amount = $amount + $displayPrice * $row->quantity + $shipping_rate;
                             }
                         }
                     }
                     $this->custom_log->write_log('custom_log', 'at a time purchase id is ' . $atATimeProduct);
                     $handlingPrice = $amount * $this->config->item('space_point_comission') / 100;
                     $this->custom_log->write_log('custom_log', 'Cash Handling Price is ' . $handlingPrice);
                     $amount = $amount + $handlingPrice;
                     $this->custom_log->write_log('custom_log', 'Total AMount is ' . $amount);
                     $this->custom_log->write_log('custom_log', 'result array is ' . print_r($cartDetails, true));
                     if (!empty($cartDetails)) {
                         foreach ($cartDetails as $row) {
                             $productId = $row->productId;
                             $retailerPrice = $row->retailerPrice;
                             $productWeight = $row->weight + $row->shippingWeight;
                             $spacePointePrice = $row->spacePointePrice;
                             $cashAdminPrice = $row->cashAdminPrice;
                             $cashAdminFee = $row->cashAdminFee;
                             $categoryCommission = $row->categoryCommission;
                             $genuineShippFee = $row->genuineShippFee;
                             $displayPrice = $row->productAmt;
                             $shipping_rate = 0;
                             $cashHandlingPrice = 0;
                             if ($row->freeShipPrdId) {
                             } elseif ($row->freeShipCatId) {
                             } elseif ($row->genuineShippFee) {
                                 $shipping_rate = $row->shippingRate * $row->quantity;
                                 if ($productWeight > 10) {
                                     $shipping_rate = $row->shippingRate * $row->quantity * $productWeight;
                                 }
                             }
                             $this->custom_log->write_log('custom_log', 'Shipping Rate is ' . $shipping_rate);
                             $ttlAmt = $row->quantity * $displayPrice + $shipping_rate;
                             $this->custom_log->write_log('custom_log', 'total amount after calculate shipping rate = ' . $ttlAmt);
                             $cashHandlingPrice = $ttlAmt * $this->config->item('space_point_comission') / 100;
                             $this->custom_log->write_log('custom_log', 'cash Handling amount of total amout is ' . $cashHandlingPrice);
                             $orderArr = array('orderTypeId' => 2, 'totalAmount' => $amount, 'customerId' => $this->session->userdata('userId'), 'quantity' => $row->quantity, 'chargedAmount' => $displayPrice, 'organizationProductId' => $row->organizationProductId, 'orderStatusId' => 1, 'orderEmail' => $this->session->userdata('userEmail'), 'shippingOrgId' => $row->shippingOrgId, 'shippingRateId' => $row->shippingRateId, 'customOrderId' => $customOrderIdCart[$row->cartId], 'atATimeProduct' => $atATimeProduct, 'colorId' => $row->colorId, 'size' => $row->size, 'isPickup' => 0, 'pickupId' => 0, 'payment_reference' => '', 'retrieval_reference' => '', 'transaction_reference' => '', 'merchant_reference' => '', 'transaction_date' => '', 'paymentStatus' => 0, 'toDropshipId' => $row->toDropshipId, 'retailerPrice' => $retailerPrice, 'spacePointePrice' => $spacePointePrice, 'cashAdminPrice' => $cashAdminPrice, 'cashAdminFee' => $cashAdminFee, 'genuineShippFee' => $genuineShippFee, 'categoryCommission' => $categoryCommission, 'marketingProductId' => $row->marketingProductId, 'cashHandlingPrice' => $cashHandlingPrice, 'pickupProccessPrice' => 0, 'productWeight' => $row->productWeight, 'retailerDiscount' => $row->retailerDiscount, 'freeShipCatId' => $row->freeShipCatId, 'freeShipPrdId' => $row->freeShipPrdId, 'productId' => $row->productId, 'productImageId' => $row->productImageId, 'isEconomicDelivery' => 0, 'inventoryHistoryId' => $row->inventoryHistoryId, 'pointeForceVerifiedStatus' => $pointeForceVerifiedStatus, 'spacepointeCommission2' => $row->spacePointePrice2, 'totalCommissionPrice' => $row->quantity * $row->spacePointePrice2);
                             //echo "<pre>"; print_r($orderArr); exit;
                             $orderID = $this->order_m->add_order($orderArr);
                             $this->custom_log->write_log('custom_log', 'order inserted array is ' . print_r($orderArr, true));
                             $this->custom_log->write_log('custom_log', 'Created order id is ' . $orderID);
                             if ($orderID) {
                                 /**********shipping address for customer*************/
                                 $shippCusAddId = $this->session->userdata('shippingAddressId');
                                 $orderaddressId = $this->order_m->add_order_address($orderID, $shippCusAddId);
                                 /********shipping address for customer***************/
                                 /**********billing address for customer*************/
                                 $billCusDet = $this->customer_m->user_billing_details($this->session->userdata('userId'));
                                 $this->custom_log->write_log('custom_log', 'customer billing details is ' . print_r($billCusDet, true));
                                 $billCusAddId = 0;
                                 if (!empty($billCusDet)) {
                                     $billCusAddId = $billCusDet->addressId;
                                 } else {
                                     $billCusAddId = $shippCusAddId;
                                 }
                                 $this->order_m->add_billing_order_address($orderID, $billCusAddId);
                                 /********billing address for customer***************/
                                 $payOrderID = $this->order_m->add_order_payment($orderID, $orderArr);
                                 $this->custom_log->write_log('custom_log', 'Payment order id is ' . $payOrderID);
                                 if ($payOrderID) {
                                     $orderTrackId = $this->order_m->add_order_track_details($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order track id is ' . $orderTrackId);
                                     $orderDropshipCenterId = $this->order_m->add_order_dropship_center($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'order dropship center id is ' . $orderDropshipCenterId);
                                     $freeShipOrderId = $this->order_m->add_order_free_shipping($orderID, $orderArr);
                                     $this->custom_log->write_log('custom_log', 'free shipping order id is ' . $freeShipOrderId);
                                     if ($this->order_m->reduce_product_quantity($row->organizationProductId, $row->quantity)) {
                                         $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                         $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationProductId);
                                         if ($row->colorId) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_color_quantity_from_marketing($row->marketingProductId, $row->colorId, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->marketingProductId . ' and color id is ' . $row->colorId);
                                             }
                                         }
                                         if ($row->size) {
                                             if ($row->marketingProductId) {
                                                 $this->order_m->reduce_product_size_quantity_from_marketing($row->marketingProductId, $row->size, $row->quantity);
                                                 $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                                 $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from marketing product id is ' . $row->organizationProductId . ' and size is ' . $row->size);
                                             }
                                         }
                                         if (!empty($row->marketingProductId) && $row->marketingProductId) {
                                         } elseif (!empty($row->organizationColorSizeId) && $row->organizationColorSizeId) {
                                             $this->order_m->reduce_orgnization_product_color_size_quantity($row->organizationColorSizeId, $row->quantity);
                                             $this->custom_log->write_log('custom_log', 'last query is ' . $this->db->last_query());
                                             $this->custom_log->write_log('custom_log', $row->quantity . ' quantity is reduce from ' . $row->organizationColorSizeId);
                                         }
                                     }
                                     $this->session->set_flashdata('success', $this->lang->line('success_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('success_add_order'));
                                     /***order History****************/
                                     $orderHistoryId = $this->order_m->add_order_history($orderID, 1);
                                     $this->custom_log->write_log('custom_log', 'order history id is ' . $orderHistoryId);
                                     /***Order History****************/
                                     $shippingVendor = '';
                                     $estimateDay = 0;
                                     $rateDetails = $this->shipping_m->shipping_vendor_details($row->shippingRateId);
                                     $estimateDay = $rateDetails->ETA + $this->config->item('estimated_time_increase');
                                     $shippingVendor = $rateDetails->organizationName;
                                     $customerShippDet = $this->customer_m->address_details($shippCusAddId);
                                     $shippingAddName = $customerShippDet->firstName . ' ' . $customerShippDet->lastName;
                                     $shippingAddress = $customerShippDet->addressLine1 . ' ' . $customerShippDet->address_Line2 . ' ' . $customerShippDet->cityName . ',' . $customerShippDet->areaName . ' ' . $customerShippDet->stateName . ' - ' . $customerShippDet->zip;
                                     $retailerDet = $this->order_m->order_retailer_with_product_details($row->organizationProductId);
                                     $imagePath = base_url() . 'img/no_image.jpg';
                                     if (!empty($retailerDet->productImageName) && file_exists('uploads/product/' . $retailerDet->productImageName)) {
                                         $imagePath = base_url() . 'uploads/product/' . $retailerDet->productImageName;
                                     }
                                     $color = '';
                                     $size = '';
                                     $mailData = array('email' => $this->session->userdata('userEmail'), 'cc' => '', 'bcc' => '*****@*****.**', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerDetails->phone, 'orderId' => $customOrderIdCart[$row->cartId], 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $row->quantity, 'subTotal' => number_format($displayPrice * $row->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $row->quantity, 2), 'subject' => 'Your Order Has Been Placed');
                                     if ($this->email_m->send_mail($mailData)) {
                                         $customer_order_message = 'Your order has been recieved for ' . substr($retailerDet->code, 0, 15) . ', will be delivered in ' . $estimateDay . ' days';
                                         $response = $this->twillo_m->send_mobile_message('+234' . $customerDetails->phone, $customer_order_message);
                                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                                     } else {
                                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                                     }
                                     $mailData = array('email' => '*****@*****.**', 'cc' => '', 'bcc' => '', 'slug' => 'order_placed_for_customer', 'customerName' => $this->session->userdata('userName'), 'customerPhone' => $customerDetails->phone, 'orderId' => $customOrderIdCart[$row->cartId], 'eta' => $estimateDay, 'shippingVendor' => $shippingVendor, 'shippingAddName' => $shippingAddName, 'shippingAddress' => $shippingAddress, 'sellerName' => $retailerDet->organizationName, 'imagePath' => $imagePath, 'productName' => $retailerDet->code, 'currentPrice' => number_format($displayPrice, 2), 'quantity' => $row->quantity, 'subTotal' => number_format($displayPrice * $row->quantity, 2), 'color' => $color, 'size' => $size, 'totalAmount' => number_format($displayPrice * $row->quantity, 2), 'subject' => 'Your Order Has Been Placed');
                                     if ($this->email_m->send_mail($mailData)) {
                                         $this->custom_log->write_log('custom_log', 'send mail data is ' . print_r($mailData, true));
                                         $this->custom_log->write_log('custom_log', 'Mail send successfully');
                                     } else {
                                         $this->custom_log->write_log('custom_log', $this->lang->line('error_mail_not_send'));
                                     }
                                     /*********add order pointeforce commission***********/
                                     if (!empty($isPointeForce) && $isPointeForce) {
                                         $orderPointeForceId = $this->order_m->add_order_pointe_force_commission($orderID, $orderArr);
                                         $this->custom_log->write_log('custom_log', 'order pointe force id is ' . $orderPointeForceId);
                                     }
                                     /*********add order pointeforce commission***********/
                                 } else {
                                     $this->session->set_flashdata('error', $this->lang->line('error_add_order'));
                                     $this->custom_log->write_log('custom_log', 'message is ' . $this->lang->line('error_add_order'));
                                 }
                             }
                         }
                         if (!empty($where)) {
                             $this->cart_m->remove_to_cart($where);
                         }
                         $this->cart->destroy();
                         $this->session->unset_userdata('isPickUp');
                         $this->session->unset_userdata('isChkAvl');
                         $this->session->unset_userdata('shippingAddressId');
                         $this->session->set_flashdata('success', 'Order created successfully');
                         $this->custom_log->write_log('custom_log', 'Order created successfully');
                         redirect(base_url() . 'frontend/order/order_complete_success/' . id_encrypt($atATimeProduct));
                     } else {
                         $this->session->set_flashdata('error', 'Cart Details not found');
                         $this->custom_log->write_log('custom_log', 'Cart Details not found');
                     }
                 } else {
                     redirect(base_url());
                 }
             }
         } else {
             $this->custom_log->write_log('custom_log', 'shipping address After Form Submit ' . print_r($_POST, true));
             $rules = shipping_rules();
             $this->form_validation->set_rules($rules);
             $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
             if ($this->form_validation->run()) {
                 $result['firstName'] = $this->input->post('firstName');
                 $result['lastName'] = $this->input->post('lastName');
                 $result['address1'] = $this->input->post('address1');
                 $result['address2'] = $this->input->post('address2');
                 $result['phoneNo'] = $this->input->post('phoneNo');
                 $result['zipcode'] = 0;
                 $result['stateId'] = $this->input->post('stateId');
                 $result['areaId'] = $this->input->post('areaId');
                 $result['cityId'] = $this->input->post('cityId');
                 $result['countryId'] = 154;
                 $showEconomicDel = 0;
                 $sameRetailer = array();
                 foreach ($cartDetails as $row) {
                     if (!empty($sameRetailer[$row->organizationId]['totalPrd'])) {
                         $sameRetailer[$row->organizationId]['totalPrd'] = $sameRetailer[$row->organizationId]['totalPrd'] + 1;
                     } else {
                         $sameRetailer[$row->organizationId]['totalPrd'] = 1;
                     }
                     if (!empty($sameRetailer[$row->organizationId]['totalPrd']) && $sameRetailer[$row->organizationId]['totalPrd'] > 1) {
                         $showEconomicDel = 1;
                     }
                     if ($row->quantity > 1) {
                         $showEconomicDel = 1;
                     }
                     $dropshipId = $row->toDropshipId;
                     $totalWeight = $row->productWeight;
                     $stateId = $result['stateId'];
                     $areaId = $result['areaId'];
                     $cityId = $result['cityId'];
                     $shipRateDet = $this->shipping_m->check_avaibility($dropshipId, $stateId, $areaId, $cityId, $totalWeight);
                     $this->custom_log->write_log('custom_log', 'Shipping rate details is ' . print_r($shipRateDet, true));
                     if (!empty($shipRateDet)) {
                         if ($this->cart_m->update_shipping_address_buy_now_delivery($row->cartId, $shipRateDet->shippingOrgId, $shipRateDet->shippingRateId)) {
                             $this->cart_m->update_buy_now_delivery($row->cartId);
                             $this->custom_log->write_log('custom_log', 'updated cart as buy now delivery');
                         } else {
                             $this->session->set_flashdata('error', 'Shipping details not update in buy now cart');
                             $this->custom_log->write_log('custom_log', 'Shipping details not update in buy now cart');
                             redirect(base_url() . 'frontend/product_cart/shipping_address');
                         }
                     } else {
                         $this->session->set_flashdata('error', 'Shipping vendor not available in your city');
                         $this->custom_log->write_log('custom_log', 'Shipping vendor not available in your city');
                         redirect(base_url() . 'frontend/product_cart/shipping_address');
                     }
                 }
                 $this->customer_m->delete_old_shipping_address($userId);
                 $addressId = $this->customer_m->add_shippBill_address($result);
                 $this->custom_log->write_log('custom_log', 'address id is ' . $addressId);
                 $this->session->set_userdata('shippingAddressId', $addressId);
                 $this->custom_log->write_log('custom_log', 'set session shipping address id is ' . $addressId);
                 if ($addressId) {
                     $this->customer_m->add_shipping_address_type($userId, $addressId);
                     $this->session->set_flashdata('success', 'Shipping infomation added successfully');
                     $this->custom_log->write_log('custom_log', 'Shipping infomation added successfully');
                 } else {
                     $this->session->set_flashdata('error', 'Shipping information not add');
                     $this->custom_log->write_log('custom_log', 'Shipping information not add');
                 }
                 redirect(base_url() . 'frontend/product_cart/shipping_address');
             }
         }
     }
     $shippCusAddId = $this->session->userdata('shippingAddressId');
     $shippCusDet = $this->customer_m->address_details($shippCusAddId);
     $allShippCusAdd = $this->customer_m->all_shipping_details($userId);
     $this->data['stateList'] = $this->location_m->nigeria_state_list();
     $this->data['cartDetails'] = $cartDetails;
     $this->data['shippCusDet'] = $shippCusDet;
     $this->data['allShippCusAdd'] = $allShippCusAdd;
     $this->data['shippCusAddId'] = $shippCusAddId;
     $this->frontendCustomView('product_cart/shipping_address', $this->data);
 }