自定义将报价转换为订单-“无法检索付款方式实例”


10

我偶尔看到下订单的情况,在客户卡上进行了付款授权,客户收到了订单确认电子邮件 -但Magento 或中没有订单sales_flat_ordersales_flat_order_grid

这里选择的武器是要求管理员在网关中使付款无效,要求客户重新放置。

但是,我们拥有所有报价,报价项目,报价付款,报价地址。从理论上讲,该订单是有效的,毕竟,我们拥有授权,并且客户拥有订单电子邮件。错误发生在订单电子邮件生成导致回滚(当前工作原理)之后的某个时间。

我创建了一个测试一次性脚本,以使用沙箱网关转换此报价。但是,我在产生付款方面遇到了麻烦。我试着使用checkmofreeauthorizenet,都返回相同的异常:

PHP Fatal error:  Uncaught exception 'Mage_Core_Exception' with message 'Cannot retrieve payment method instance.' in /var/www/vhosts/magento/app/Mage.php:563
Stack trace:
#0 /var/www/vhosts/magento/app/code/core/Mage/Payment/Model/Info.php(83): Mage::throwException('Cannot retrieve...')

请参阅下面的代码。欢迎反馈。

<?php
//.... stuff

$quote = Mage::getModel('sales/quote')->load(745);

$convert = Mage::getModel('sales/convert_quote');

$order = $convert->toOrder($quote);
$order->addressToOrder($quote->getAddress(),$order);

foreach($quote->getAllItems() as $item){
    $orderItem = $convert->itemToOrderItem($item);
    if ($item->getParentItem()) {
       $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
    }
    $order->addItem($orderItem);
}

$data = array(
        'method' => 'authorizenet',
        'cc_type' => 'VI',
        'cc_number' => '4111111111111111',
        'cc_exp_month' => '1',
        'cc_exp_year' => (date('Y') + 6),
        'cc_cid' => '444'
);

$quote->getShippingAddress()->setPaymentMethod('authorizenet');
$quote->getShippingAddress()->setCollectShippingRates(true);

$payment = $quote->getPayment();
$payment->importData($data);
$quote->save();

$payment = $convert->paymentToOrderPayment($quote->getPayment());

$order->setPayment($quote->getPayment());

$message = '[Notice] - Order converted from quote manually';
$order->addStatusToHistory($order->getStatus(), $message);
$order->place();
$order->save();

$quote->setIsActive(false)->save();

Answers:


7

您正在发送订单

 $quote->getPayment()

您的代码应如下所示

...

$payment = $convert->paymentToOrderPayment($quote->getPayment());

$order->setPayment($payment);

...

您说得对-就是这样。好决定。
philwinkle

我收到错误消息,PHP Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'The requested Payment Method is not available.' in /var/www/html/app/Mage.php:594我已将付款方式启用为“采购订单”,并想以零成本创建新订单而不使用付款方式。
拉胡尔
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.