Beispiel #1
0
    function portOrders()
    {
        if (microtime(true) - $this->starttime >= $this->maxScriptTime) {
            return;
        }
        if (!class_exists('VirtueMartModelOrderstatus')) {
            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 `#__virtuemart_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 `#__virtuemart_orderstates` ( `virtuemart_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('VirtueMartModelOrders')) {
            VmModel::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 `#__virtuemart_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->virtuemart_order_id = null;
                    $orderData->virtuemart_user_id = $order['user_id'];
                    $orderData->virtuemart_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 = VirtueMartModelOrders::genStdOrderPass();
                    //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed.
                    //The virtuemart_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->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_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->virtuemart_paymentmethod_id = $order['payment_method_id'];
                    $orderData->virtuemart_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->virtuemart_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['virtuemart_order_id'] = $newId;
                        if (!empty($newproductIds[$item['product_id']])) {
                            $item['virtuemart_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['virtuemart_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['virtuemart_order_id'] = $newId;
                            $item['virtuemart_user_id'] = $item['user_id'];
                            $item['virtuemart_country_id'] = $this->getCountryIDByName($item['country']);
                            $item['virtuemart_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;
    }
Beispiel #2
0
 function check()
 {
     if (empty($this->order_number)) {
         if (!class_exists('VirtueMartModelOrders')) {
             VmModel::getModel('orders');
         }
         $this->order_number = VirtueMartModelOrders::genStdOrderNumber($this->virtuemart_vendor_id);
     }
     if (empty($this->order_pass)) {
         if (!class_exists('VirtueMartModelOrders')) {
             VmModel::getModel('orders');
         }
         $this->order_pass = VirtueMartModelOrders::genStdOrderPass();
     }
     if ($adminID = vmAccess::getBgManagerId()) {
         $this->created_by = $adminID;
     }
     return parent::check();
 }