Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento以编程方式创建的订单在编辑时不保留旧信息_Magento_Magento 1.9 - Fatal编程技术网

Magento以编程方式创建的订单在编辑时不保留旧信息

Magento以编程方式创建的订单在编辑时不保留旧信息,magento,magento-1.9,Magento,Magento 1.9,我在Magento admin中通过编程方式创建订单,方法是将订单从引号中转换,并通过编程方式设置所有数据。但是,这类订单的问题是,当我尝试编辑它们时,新订单无法获取旧订单中的信息,例如产品、付款方式等。我是否需要为订单设置特殊标志或其他内容,以便能够以编辑标准Magento订单的方式对其进行编辑?请导游 这是我用来创建订单的代码 require_once 'app/Mage.php'; Mage::app(); $quoteId = $this->getRequ

我在Magento admin中通过编程方式创建订单,方法是将订单从引号中转换,并通过编程方式设置所有数据。但是,这类订单的问题是,当我尝试编辑它们时,新订单无法获取旧订单中的信息,例如产品、付款方式等。我是否需要为订单设置特殊标志或其他内容,以便能够以编辑标准Magento订单的方式对其进行编辑?请导游

这是我用来创建订单的代码

    require_once 'app/Mage.php';
    Mage::app();

    $quoteId = $this->getRequest()->getParam('quote_id');

    $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

    $id = $quote->customer_id;
    $itemsCount = $quote->items_count;

    $customer = Mage::getModel('customer/customer')->load($id);
    $userEmail = $customer->getEmail();

    $transaction = Mage::getModel('core/resource_transaction');
    $storeId = $customer->getStoreId();
    $reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
    $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();

    $order = Mage::getModel('sales/order')
            ->setIncrementId($reservedOrderId)
            ->setStoreId($storeId)
            ->setQuoteId($quoteId)
            ->setGlobal_currency_code($currencyCode)
            ->setBase_currency_code($currencyCode)
            ->setStore_currency_code($currencyCode)
            ->setOrder_currency_code($currencyCode);


    $order->setCustomer_email($customer->getEmail())
            ->setCustomerFirstname($customer->getFirstname())
            ->setCustomerLastname($customer->getLastname())
            ->setCustomerGroupId($customer->getGroupId())
            ->setCustomer_is_guest(0)
            ->setCustomer($customer);
    $billing = $customer->getDefaultBillingAddress();


    if ($billing == "") {
        $billing = $quote->getBillingAddress()->exportCustomerAddress();
    }

    $shipping = $customer->getDefaultShippingAddress();


    if ($shpping == "") {
        $shpping = $quote->getShippingAddress()->exportCustomerAddress();
    }

    $billingAddress = Mage::getModel('sales/order_address')
            ->setStoreId($storeId)
            ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
            ->setCustomerId($customer->getId())
            ->setCustomerAddressId($customer->getDefaultBilling())
            ->setCustomer_address_id($billing->getEntityId())
            ->setPrefix($billing->getPrefix())
            ->setFirstname($billing->getFirstname())
            ->setMiddlename($billing->getMiddlename())
            ->setLastname($billing->getLastname())
            ->setSuffix($billing->getSuffix())
            ->setCompany($billing->getCompany())
            ->setStreet($billing->getStreet())
            ->setCity($billing->getCity())
            ->setCountry_id($billing->getCountryId())
            ->setRegion($billing->getRegion())
            ->setRegion_id($billing->getRegionId())
            ->setPostcode($billing->getPostcode())
            ->setTelephone($billing->getTelephone())
            ->setFax($billing->getFax());
    $order->setBillingAddress($billingAddress);


    if ($shipping == "") {
        $shippingAddress = Mage::getModel('sales/order_address')
                ->setStoreId($storeId)
                ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
                ->setCustomerId($customer->getId())
                ->setCustomerAddressId($customer->getDefaultShipping())
                ->setCustomer_address_id($billing->getEntityId())
                ->setPrefix($billing->getPrefix())
                ->setFirstname($billing->getFirstname())
                ->setMiddlename($billing->getMiddlename())
                ->setLastname($billing->getLastname())
                ->setSuffix($billing->getSuffix())
                ->setCompany($billing->getCompany())
                ->setStreet($billing->getStreet())
                ->setCity($billing->getCity())
                ->setCountry_id($billing->getCountryId())
                ->setRegion($billing->getRegion())
                ->setRegion_id($billing->getRegionId())
                ->setPostcode($billing->getPostcode())
                ->setTelephone($billing->getTelephone())
                ->setFax($billing->getFax());
    } else {
        $shippingAddress = Mage::getModel('sales/order_address')
                ->setStoreId($storeId)
                ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
                ->setCustomerId($customer->getId())
                ->setCustomerAddressId($customer->getDefaultShipping())
                ->setCustomer_address_id($shipping->getEntityId())
                ->setPrefix($shipping->getPrefix())
                ->setFirstname($shipping->getFirstname())
                ->setMiddlename($shipping->getMiddlename())
                ->setLastname($shipping->getLastname())
                ->setSuffix($shipping->getSuffix())
                ->setCompany($shipping->getCompany())
                ->setStreet($shipping->getStreet())
                ->setCity($shipping->getCity())
                ->setCountry_id($shipping->getCountryId())
                ->setRegion($shipping->getRegion())
                ->setRegion_id($shipping->getRegionId())
                ->setPostcode($shipping->getPostcode())
                ->setTelephone($shipping->getTelephone())
                ->setFax($shipping->getFax());
    }

    $shippingMethode = $quote->getShippingAddress()->getShippingMethod();

    $shippingDescription = $quote->getShippingAddress()->getShippingDescription();
    $order->setShippingAddress($shippingAddress)
            ->setShipping_method($shippingMethode)
            ->setShippingDescription($shippingDescription);


    $paymentcode = $quote->getPayment()->getMethodInstance()->getCode();

    $payData = $quote->getPayment()->getData();

    $orderPayment = Mage::getModel('sales/order_payment')
                    ->setStoreId($storeId)
                    ->setCustomerPaymentId(0)
                    ->setMethod($paymentcode)->addData($payData);

    $order->setPayment($orderPayment);


    $subTotal = 0;
    $orderData = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);


    $itemsData = $orderData->getAllItems();


    foreach ($itemsData as $itemIds => $itemValue) {
        $products[$itemValue->getProductId()] = array('qty' => $itemValue->getQty());
        $rowTotal = $itemValue->getPrice() * $itemValue->getQty();


        $orderItem = Mage::getModel('sales/order_item')
                ->setStoreId($storeId)
                ->setQuoteItemId(0)
                ->setQuoteParentItemId(NULL)
                ->setProductId($itemValue->getProductId())
                ->setProductType($itemValue->getTypeId())
                ->setQtyBackordered(NULL)
                ->setTotalQtyOrdered($itemValue->getRqty())
                ->setQtyOrdered($itemValue->getQty())
                ->setName($itemValue->getName())
                ->setSku($itemValue->getSku())
                ->setPrice($itemValue->getPrice())
                ->setBasePrice($itemValue->getPrice())
                ->setOriginalPrice($itemValue->getPrice())
                ->setRowTotal($rowTotal)
                ->setBaseRowTotal($rowTotal);

        $subTotal += $rowTotal;
        $order->addItem($orderItem);
    }

    $shippingAmount = $quote->getShippingAddress()->getShippingAmount();
    $subTotal = $quote->getSubtotal();
    $baseTotal = $quote->getBaseSubtotal();
    $grandTotal = $quote->getGrandTotal();
    $baseGrandTotal = $quote->getBaseGrandTotal();
    $order->setSubtotal($subTotal)
            ->setBaseSubtotal($baseTotal)
            ->setGrandTotal($grandTotal)
            ->setBaseGrandTotal($baseGrandTotal);

    $order->setShippingAmount($shippingAmount);
    $transaction->addObject($order);
    $transaction->addCommitCallback(array($order, 'place'));
    $transaction->addCommitCallback(array($order, 'save'));
    $transaction->save();
    $quote = $this->_initQuote();

    $orderId = $order->getEntityId();


    $requestModel = Mage::getModel('quote2sales/request');
    $requestIdArray = $requestModel->getQuoteData($quoteId);
    $requestId = $requestIdArray[0]['request_id'];


    if ($requestId != NULL) {
        $requestModel->updateRequestStatus("Converted To Order", $requestId);
        $requestModel->addOrderId("Converted To Order", $quoteId, $orderId);
    }

    $mailer = Mage::getModel('core/email_template_mailer');
    $emailInfo = Mage::getModel('core/email_info');

    $emailInfo->addTo($userEmail);
    $mailer->addEmailInfo($emailInfo);
    $templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_TEMPLATE, $storeId);

    $mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
    $mailer->setStoreId($storeId);
    $mailer->setTemplateId($templateId);

    $mailer->setTemplateParams(
            array(
                'order' => $order,
                'billing' => $order->getBillingAddress(),
                'payment_html' => ""
            )
    );

    $mailer->send();

    if ($quote) {
        try {
            $quote->delete()
                    ->save();
        } catch (Mage_Core_Exception $e) {

        } catch (Exception $e) {
            Mage::logException($e);
        }
        Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The Order has been created.'));
        $this->_redirect('*/adminhtml_quote/index');
    } else {
        Mage::log("Can't get quote");
    }

请出示您的密码!编辑问题并添加代码。