Esempio n. 1
0
 /**
  * This is a proxy function to return an order safely, we may set the getOrder function to private
  * Maybe the right place would be the controller, cause there are JRequests in it. But for a fast solution,
  * still better than to have it 3-4 times in the view.html.php of the views.
  * @author Max Milbers
  *
  * @return array
  */
 public function getMyOrderDetails($orderID = 0, $orderNumber = false, $orderPass = false)
 {
     $_currentUser = JFactory::getUser();
     $cuid = $_currentUser->get('id');
     $orderDetails = false;
     // If the user is not logged in, we will check the order number and order pass
     if (empty($cuid)) {
         $sess = JFactory::getSession();
         $orderNumber = vRequest::getString('order_number', $orderNumber);
         $tries = $sess->get('getOrderDetails.' . $orderNumber, 0);
         if ($tries > 5) {
             vmDebug('Too many tries, Invalid order_number/password ' . tsmText::_('com_tsmart_RESTRICTED_ACCESS'));
             return false;
         }
         // If the user is not logged in, we will check the order number and order pass
         if ($orderPass = vRequest::getString('order_pass', $orderPass)) {
             $orderId = $this->getOrderIdByOrderPass($orderNumber, $orderPass);
             if (empty($orderId)) {
                 echo tsmText::_('com_tsmart_RESTRICTED_ACCESS');
                 vmdebug('getMyOrderDetails com_tsmart_RESTRICTED_ACCESS', $orderNumber, $orderPass, $tries);
                 $tries++;
                 $sess->set('getOrderDetails.' . $orderNumber, $tries);
                 return false;
             }
             $orderDetails = $this->getOrder($orderId);
         }
     } else {
         // If the user is logged in, we will check if the order belongs to him
         $tsmart_order_id = vRequest::getInt('tsmart_order_id', $orderID);
         if (!$tsmart_order_id) {
             $tsmart_order_id = tsmartModelOrders::getOrderIdByOrderNumber(vRequest::getString('order_number'));
         }
         $orderDetails = $this->getOrder($tsmart_order_id);
         $user = JFactory::getUser();
         if (!vmAccess::manager('orders')) {
             if (!isset($orderDetails['details']['BT']->tsmart_user_id)) {
                 $orderDetails['details']['BT']->tsmart_user_id = 0;
             }
             if ($orderDetails['details']['BT']->tsmart_user_id != $cuid) {
                 echo tsmText::_('com_tsmart_RESTRICTED_ACCESS');
                 return false;
             }
         }
     }
     return $orderDetails;
 }
Esempio n. 2
0
 /**
  * Extends the standard function in vmplugin. Extendst the input data by tsmart_order_id
  * Calls the parent to execute the write operation
  *
  * @author Max Milbers
  * @param array  $_values
  * @param string $_table
  */
 protected function storePSPluginInternalData($values, $primaryKey = 0, $preload = FALSE)
 {
     if (!class_exists('tsmartModelOrders')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php';
     }
     if (!isset($values['tsmart_order_id'])) {
         $values['tsmart_order_id'] = tsmartModelOrders::getOrderIdByOrderNumber($values['order_number']);
     }
     return $this->storePluginInternalData($values, $primaryKey, 0, $preload);
 }
Esempio n. 3
0
 function check()
 {
     if (empty($this->order_number)) {
         if (!class_exists('tsmartModelOrders')) {
             tmsModel::getModel('orders');
         }
         $this->order_number = tsmartModelOrders::genStdOrderNumber($this->tsmart_vendor_id);
     }
     if (empty($this->order_pass)) {
         if (!class_exists('tsmartModelOrders')) {
             tmsModel::getModel('orders');
         }
         $this->order_pass = tsmartModelOrders::genStdOrderPass();
     }
     if ($adminID = vmAccess::getBgManagerId()) {
         $this->created_by = $adminID;
     }
     return parent::check();
 }
Esempio n. 4
0
    function portOrders()
    {
        if (microtime(true) - $this->starttime >= $this->maxScriptTime) {
            return;
        }
        if (!class_exists('tsmartModelOrderstatus')) {
            require VMPATH_ADMIN . DS . 'models' . DS . 'orderstatus.php';
        }
        if (!class_exists('ShopFunctions')) {
            require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php';
        }
        $this->_db->setQuery('select `order_status_code` FROM `#__tsmart_orderstates` ');
        $vm2Fields = $this->_db->loadColumn();
        $this->_db->setQuery('select * FROM `#__vm_order_status`');
        $oldfields = $this->_db->loadObjectList();
        $migratedfields = '';
        foreach ($oldfields as $field) {
            if (!in_array($field->order_status_code, $vm2Fields)) {
                $q = 'INSERT INTO `#__tsmart_orderstates` ( `tsmart_vendor_id`, `order_status_code`, `order_status_name`, `order_status_description`, `order_stock_handle`, `ordering`, `published`)
					VALUES ( "' . $field->vendor_id . '","' . $field->order_status_code . '","' . $field->order_status_name . '","' . $field->order_status_description . '","A","' . $field->list_order . '", 1 )';
                $this->_db->setQuery($q);
                $this->_db->execute();
                if ($this->_db->getErrorNum()) {
                    vmError($this->_db->getErrorMsg());
                }
                $migratedfields .= '[' . $field->order_status_code . '-' . $field->order_status_name . '] ';
            }
        }
        if ($migratedfields) {
            vminfo('order states declaration ' . $migratedfields . ' Migrated');
        }
        $oldtonewOrders = array();
        //Looks like there is a problem, when the data gets tooo big,
        //solved now with query directly ignoring already ported orders.
        $alreadyKnownIds = $this->getMigrationProgress('orders');
        $newproductIds = $this->getMigrationProgress('products');
        $orderCodeToId = $this->createOrderStatusAssoc();
        //approximatly 100 products take a 1 MB
        $maxItems = $this->_getMaxItems('Orders');
        $startLimit = $this->_getStartLimit('orders_start');
        vmdebug('portOrders $startLimit ' . $startLimit);
        $i = 0;
        if (count($alreadyKnownIds) == $startLimit + $maxItems) {
            $continue = false;
        } else {
            $continue = true;
        }
        $reWriteOrderNumber = vRequest::getInt('reWriteOrderNumber', 0);
        $userOrderId = vRequest::getInt('userOrderId', 0);
        if (!class_exists('tsmartModelOrders')) {
            tmsModel::getModel('orders');
        }
        while ($continue) {
            $q = 'SELECT `o`.*, `op`.*, `o`.`order_number` as `vm1_order_number`, `o2`.`order_number` as `nr2`,`o`.order_id FROM `#__vm_orders` as `o`
				LEFT OUTER JOIN `#__vm_order_payment` as `op` ON `op`.`order_id` = `o`.`order_id`
				LEFT JOIN `#__tsmart_orders` as `o2` ON `o2`.`order_number` = `o`.`order_number`
				WHERE (o2.order_number) IS NULL ORDER BY o.order_id LIMIT ' . $startLimit . ',' . $maxItems;
            $doneStart = $startLimit;
            $res = self::loadCountListContinue($q, $startLimit, $maxItems, 'port Orders');
            $oldOrders = $res[0];
            $startLimit = $res[1];
            $continue = $res[2];
            foreach ($oldOrders as $order) {
                if (!array_key_exists($order['order_id'], $alreadyKnownIds)) {
                    $orderData = new stdClass();
                    $orderData->tsmart_order_id = null;
                    $orderData->tsmart_user_id = $order['user_id'];
                    $orderData->tsmart_vendor_id = $order['vendor_id'];
                    if ($reWriteOrderNumber == 0) {
                        if ($userOrderId == 1) {
                            $orderData->order_number = $order['order_id'];
                        } else {
                            $orderData->order_number = $order['vm1_order_number'];
                        }
                    }
                    $orderData->order_pass = tsmartModelOrders::genStdOrderPass();
                    //Note as long we do not have an extra table only storing addresses, the tsmart_userinfo_id is not needed.
                    //The tsmart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses.
                    //the saved order should be an snapshot with plain data written in it.
                    //		$orderData->tsmart_userinfo_id = 'TODO'; // $_cart['BT']['tsmart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
                    $orderData->order_total = $order['order_total'];
                    $orderData->order_subtotal = $order['order_subtotal'];
                    $orderData->order_tax = empty($order['order_tax']) ? 0 : $order['order_tax'];
                    $orderData->order_shipment = empty($order['order_shipping']) ? 0 : $order['order_shipping'];
                    $orderData->order_shipment_tax = empty($order['order_shipping_tax']) ? 0 : $order['order_shipping_tax'];
                    if (!empty($order['coupon_code'])) {
                        $orderData->coupon_code = $order['coupon_code'];
                        $orderData->coupon_discount = $order['coupon_discount'];
                    }
                    $orderData->order_discount = $order['order_discount'];
                    $orderData->order_status = $order['order_status'];
                    if (isset($order['order_currency'])) {
                        $orderData->user_currency_id = $this->getCurrencyIdByCode($order['order_currency']);
                        //$orderData->user_currency_rate = $order['order_status'];
                    }
                    $orderData->tsmart_paymentmethod_id = $order['payment_method_id'];
                    $orderData->tsmart_shipmentmethod_id = $order['ship_method_id'];
                    //$orderData->order_status_id = $oldToNewOrderstates[$order['order_status']]
                    $_filter = JFilterInput::getInstance(array('br', 'i', 'em', 'b', 'strong'), array(), 0, 0, 1);
                    $orderData->customer_note = $_filter->clean($order['customer_note']);
                    $orderData->ip_address = $order['ip_address'];
                    $orderData->created_on = $this->_changeToStamp($order['cdate']);
                    $orderData->modified_on = $this->_changeToStamp($order['mdate']);
                    //we could remove this to set modified_on today
                    $orderTable = $this->getTable('orders');
                    $continue = $orderTable->bindChecknStore($orderData);
                    if (empty($continue)) {
                        break;
                    }
                    $i++;
                    $newId = $alreadyKnownIds[$order['order_id']] = $orderTable->tsmart_order_id;
                    $q = 'SELECT * FROM `#__vm_order_item` WHERE `order_id` = "' . $order['order_id'] . '" ';
                    $this->_db->setQuery($q);
                    $oldItems = $this->_db->loadAssocList();
                    //$this->_app->enqueueMessage('Migration orderhistories: ' . $newId);
                    foreach ($oldItems as $item) {
                        $item['tsmart_order_id'] = $newId;
                        if (!empty($newproductIds[$item['product_id']])) {
                            $item['tsmart_product_id'] = $newproductIds[$item['product_id']];
                        } else {
                            vmWarn('Attention, order is pointing to deleted product (not found in the array of old products)');
                        }
                        //$item['order_status'] = $orderCodeToId[$item['order_status']];
                        $item['created_on'] = $this->_changeToStamp($item['cdate']);
                        $item['modified_on'] = $this->_changeToStamp($item['mdate']);
                        //we could remove this to set modified_on today
                        $item['product_attribute'] = $this->_attributesToJson($item['product_attribute']);
                        //we could remove this to set modified_on today
                        $item['product_discountedPriceWithoutTax'] = $item['product_final_price'] - $item['product_tax'];
                        $item['product_subtotal_with_tax'] = $item['product_final_price'] * $item['product_quantity'];
                        $orderItemsTable = $this->getTable('order_items');
                        $continue = $orderItemsTable->bindChecknStore($item);
                        if (empty($continue)) {
                            $continue = false;
                            break;
                        }
                    }
                    $q = 'SELECT * FROM `#__vm_order_history` WHERE `order_id` = "' . $order['order_id'] . '" ';
                    $this->_db->setQuery($q);
                    $oldItems = $this->_db->loadAssocList();
                    foreach ($oldItems as $item) {
                        $item['tsmart_order_id'] = $newId;
                        //$item['order_status_code'] = $orderCodeToId[$item['order_status_code']];
                        $orderHistoriesTable = $this->getTable('order_histories');
                        $orderHistoriesTable->bindChecknStore($item);
                    }
                    $q = 'SELECT * FROM `#__vm_order_user_info` WHERE `order_id` = "' . $order['order_id'] . '" ';
                    $this->_db->setQuery($q);
                    $oldItems = $this->_db->loadAssocList();
                    if ($oldItems) {
                        foreach ($oldItems as $item) {
                            $item['tsmart_order_id'] = $newId;
                            $item['tsmart_user_id'] = $item['user_id'];
                            $item['tsmart_country_id'] = $this->getCountryIDByName($item['country']);
                            $item['tsmart_state_id'] = $this->getStateIDByName($item['state']);
                            $item['email'] = $item['user_email'];
                            $orderUserinfoTable = $this->getTable('order_userinfos');
                            $orderUserinfoTable->bindChecknStore($item);
                        }
                    }
                    //$this->_app->enqueueMessage('Migration: '.$i.' order processed new id '.$newId);
                }
                // 				$this->storeMigrationProgress('orders',$alreadyKnownIds);
                // 				 else {
                // 					$oldtonewOrders[$order['order_id']] = $alreadyKnownIds[$order['order_id']];
                // 				}
                if (microtime(true) - $this->starttime >= $this->maxScriptTime) {
                    $continue = false;
                    break;
                }
            }
        }
        $limitStartToStore = ', orders_start = "' . ($doneStart + $i) . '" ';
        $this->storeMigrationProgress('orders', $alreadyKnownIds, $limitStartToStore);
        vmInfo('Migration: ' . $i . ' orders processed ' . ($doneStart + $i) . ' done.');
        return true;
    }