예제 #1
0
파일: order.php 프로젝트: JexyRu/Ksenmart
 public function createOrder($flag = 2)
 {
     $this->onExecuteBefore('createOrder', array($flag));
     $params = JComponentHelper::getParams('com_ksenmart');
     $session = JFactory::getSession();
     $jinput = JFactory::getApplication()->input;
     $user = JFactory::getUser();
     $user_id = $user->id;
     $order_id = $session->get('shop_order_id', null);
     $name = $jinput->get('name', null, 'string');
     $email = $jinput->get('email', null, 'string');
     $sendEmail = $jinput->get('sendEmail', null, 'string');
     $address = $jinput->get('address', null, 'string');
     $deliverycost = $jinput->get('deliverycost', 0, 'int');
     $phone = $jinput->get('phone', null, 'string');
     $region_id = $jinput->get('region', 0, 'int');
     $shipping_id = $jinput->get('shipping_type', 0, 'int');
     $payment_id = $jinput->get('payment_type', 0, 'int');
     $ymaphtml = $jinput->get('ymaphtml', null, 'string');
     $note = $jinput->get('note', null, 'string');
     $prd_id = $jinput->get('id', 0, 'int');
     $count = $jinput->get('count', 1, 'int');
     $roistat = $jinput->get('roistat_visit', 0, 'int');
     if (!empty($prd_id)) {
         $prd = KSMProducts::getProduct($prd_id);
     }
     $shipping_coords = $jinput->get('shipping_coords', 0, 'int');
     $address_fields = $jinput->get('address_fields', 0, 'int');
     $customer_fields = $jinput->get('customer_fields', 0, 'int');
     $status = 2;
     if ($flag == 1) {
         $status = 1;
     }
     if (empty($order_id)) {
         $orders = new stdClass();
         $orders->user_id = $user->id;
         $orders->region_id = $this->_db->Quote($region_id);
         $orders->status_id = 2;
         try {
             $this->_db->insertObject('#__ksenmart_orders', $orders);
             $order_id = $this->_db->insertid();
         } catch (Exception $e) {
         }
     } else {
         $orders = new stdClass();
         $orders->id = $this->_db->Quote($order_id);
         $orders->user_id = $user->id;
         $orders->region_id = $this->_db->Quote($region_id);
         $orders->shipping_id = $this->_db->Quote($shipping_id);
         $orders->payment_id = $this->_db->Quote($payment_id);
         $orders->shipping_coords = $this->_db->Quote($shipping_coords);
         $orders->customer_fields = json_encode($customer_fields);
         $orders->address_fields = json_encode($address_fields);
         $orders->note = $this->_db->Quote($note);
         $orders->status_id = $this->_db->Quote($status);
         $orders->roistat = $this->_db->q($roistat);
         try {
             $result = $this->_db->updateObject('#__ksenmart_orders', $orders, 'id');
         } catch (Exception $e) {
         }
     }
     if ($prd->type == 'set') {
         $properties = $this->getPropertiesVByIds(KSMProducts::getSetRelatedIds($prd_id));
         $item_properties = array();
         foreach ($properties as $property) {
             $value = $jinput->get('property_' . $prd_id . '_' . $property->property_id, null, 'string');
             if (!empty($value)) {
                 $item_properties[$property->property_id] = array('value_id' => $value);
             }
         }
     } else {
         $properties = $this->getPropertiesVByIds(array($prd->id));
         $item_properties = array();
         foreach ($properties as $property) {
             $value = $jinput->get('property_' . $property->property_id, null, 'string');
             if (!empty($value)) {
                 $item_properties[$property->property_id] = array('value_id' => $value);
             }
         }
     }
     $order_item = new stdClass();
     $order_item->order_id = $order_id;
     $order_item->product_id = $prd->id;
     $order_item->price = $prd->price;
     $order_item->count = $count;
     $order_item->properties = json_encode($item_properties);
     try {
         $this->_db->insertObject('#__ksenmart_order_items', $order_item);
     } catch (Exception $e) {
     }
     if ($params->get('use_stock', 1) == 1) {
         $prop_values = new stdClass();
         $prop_values->id = $prd->id;
         $prop_values->in_stock = $prd->in_stock - $count;
         try {
             $result = $this->_db->updateObject('#__ksenmart_product_properties_values', $orders, 'id');
         } catch (Exception $e) {
         }
     }
     if ($flag == 1) {
         if (!empty($email)) {
             KSMOrders::sendOrderMail($order_id);
         }
         KSMOrders::sendOrderMail($order_id, true);
         $session->set('shopcart_discount', '');
         $session->set('shop_order_id', null);
     } else {
         $session->set('shop_order_id', $order_id);
     }
     $cost = $prd->price * $count;
     $order_object = new stdClass();
     $order_object->id = $order_id;
     $order_object->cost = $cost;
     try {
         $result = $this->_db->updateObject('#__ksenmart_orders', $order_object, 'id');
     } catch (Exception $e) {
     }
     $this->onExecuteAfter('createOrder', array(&$order_id));
     return $order_id;
 }