Example #1
0
 function getOrder($vars = array())
 {
     $this->onExecuteBefore('getOrder', array(&$value));
     $id = JRequest::getInt('id');
     $order = KSSystem::loadDbItem($id, 'orders');
     if (isset($vars['user_id'])) {
         $order->user_id = $vars['user_id'];
     }
     if (isset($vars['region_id'])) {
         $order->region_id = $vars['region_id'];
     }
     if (isset($vars['shipping_id'])) {
         $order->shipping_id = $vars['shipping_id'];
     }
     if (isset($vars['payment_id'])) {
         $order->payment_id = $vars['payment_id'];
     }
     $order->cost = 0;
     $order->discounts = property_exists($order, 'discounts') ? $order->discounts : '[]';
     $order->customer_fields = json_decode($order->customer_fields, true);
     $order->address_fields = json_decode($order->address_fields, true);
     if (!isset($vars['items'])) {
         $query = $this->_db->getQuery(true);
         $query->select('*')->from('#__ksenmart_order_items')->where('order_id=' . $id);
         $this->_db->setQuery($query);
         $order->items = $this->_db->loadObjectList();
     } else {
         $items = array();
         if (count($vars['items']) == 1 && !is_array($vars['items'][0])) {
             $vars['items'] = array();
         }
         foreach ($vars['items'] as $item) {
             $item['properties'] = isset($item['properties']) ? $item['properties'] : array();
             $item = (object) $item;
             $item->price = KSMProducts::getPriceWithProperties($item->product_id, $item->properties, $item->basic_price);
             $item->properties = json_encode($item->properties);
             $items[] = $item;
         }
         $order->items = $items;
     }
     foreach ($order->items as &$item) {
         $query = $this->_db->getQuery(true);
         $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id=' . $item->product_id);
         $query = KSMedia::setItemMainImageToQuery($query);
         $this->_db->setQuery($query);
         $product = $this->_db->loadObject();
         if (count($product)) {
             $item->title = $product->title;
             $item->alias = $product->alias;
             $item->product_code = $product->product_code;
             $item->product_packaging = $product->product_packaging;
             $item->properties = json_decode($item->properties, true);
             $query = $this->_db->getQuery(true);
             $query->select('kp.*')->from('#__ksenmart_properties as kp')->innerjoin('#__ksenmart_product_properties_values as kppv on kp.id=kppv.property_id')->where('kppv.product_id=' . $item->product_id)->where('kp.type=' . $this->_db->quote('select'))->order('kp.ordering')->group('kp.id');
             $this->_db->setQuery($query);
             $properties = $this->_db->loadObjectList('id');
             foreach ($properties as &$property) {
                 $query = $this->_db->getQuery(true);
                 $query->select('kpv.*')->from('#__ksenmart_property_values as kpv')->innerjoin('#__ksenmart_product_properties_values as kppv on kpv.id=kppv.value_id')->where('kppv.product_id=' . $item->product_id)->where('kpv.property_id=' . $property->id)->order('kpv.ordering')->group('kpv.id');
                 $this->_db->setQuery($query);
                 $property->values = $this->_db->loadObjectList('id');
                 foreach ($property->values as $value) {
                     if (isset($item->properties[$property->id]) && is_array($item->properties[$property->id]) && in_array($value->id, $item->properties[$property->id])) {
                         $value->selected = true;
                     } else {
                         $value->selected = false;
                     }
                 }
             }
             $item->properties = $properties;
             $item->small_img = KSMedia::resizeImage($product->filename, 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36), json_decode($product->params, true));
         } else {
             $item->title = JText::_('ksm_orders_order_deleteditem_title');
             $item->alias = '';
             $item->product_code = '';
             $item->product_packaging = 1;
             $item->properties = array();
             $item->small_img = KSMedia::resizeImage('', 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36));
         }
         $item->val_price = KSMPrice::showPriceWithTransform($item->price);
         $item->val_total_price = KSMPrice::showPriceWithTransform($item->price * $item->count);
         $order->cost += $item->price * $item->count;
     }
     $order->costs = array('cost' => $order->cost, 'cost_val' => KSMPrice::showPriceWithTransform($order->cost), 'discount_cost' => 0, 'discount_cost_val' => KSMPrice::showPriceWithTransform(0), 'shipping_cost' => 0, 'shipping_cost_val' => KSMPrice::showPriceWithTransform(0), 'total_cost' => $order->cost, 'total_cost_val' => KSMPrice::showPriceWithTransform($order->cost));
     $this->onExecuteAfter('getOrder', array(&$order));
     return $order;
 }