首页>Magento>source

我使用以下代码创建订单,但获取异常为"请指定送货方式".还有付款方式,代码说无效.请告诉我在哪里可以查看这些运费和付款方式.请详细解释. magento初学者

<?php
include 'connect.php';
$db=mysqli_select_db($conn,'onceaga9_aw');
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
extract($_POST);
$productids = array(983);
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
// Start New Sales Order Quote
$quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
// Set Sales Order Quote Currency
$quote->setCurrency($order->AdjustmentAmount->currencyID);
$customer = Mage::getModel('customer/customer')
    ->setWebsiteId($websiteId)
    ->loadByEmail($email);
if ($customer->getId() == "") {
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($websiteId)
        ->setStore($store)
        ->setFirstname('Jhon')
        ->setLastname('Deo')
        ->setEmail($email)
        ->setPassword("password");
$customer->save();
}
// Assign Customer To Sales Order Quote
$quote->assignCustomer($customer);
// Configure Notification
$quote->setSendCconfirmation(1);
foreach ($productids as $id)
{
$product = Mage::getModel('catalog/product')->load($id);
$quote->addProduct($product, new Varien_Object(array('qty' => 1)));
}
// Set Sales Order Billing Address
$billingAddress = $quote->getBillingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'john',
'middlename' => '',
'lastname' => 'Deo',
'suffix' => '',
'company' => '',
'street' => array(
    '0' => 'Noida',
    '1' => 'Sector 64'
),
'city' => 'Noida',
'country_id' => 'IN',
'region' => 'UP',
'postcode' => '201301',
'telephone' => '78676789',
'fax' => 'gghlhu',
'vat_id' => '',
'save_in_address_book' => 1
    ));
// Set Sales Order Shipping Address
$shippingAddress = $quote->getShippingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'john',
'middlename' => '',
'lastname' => 'Deo',
'suffix' => '',
'company' => '',
'street' => array(
    '0' => 'Noida',
    '1' => 'Sector 64'
),
'city' => 'Noida',
'country_id' => 'IN',
'region' => 'UP',
'postcode' => '201301',
'telephone' => '78676789',
'fax' => 'gghlhu',
'vat_id' => '',
'save_in_address_book' => 1
    ));
if ($shipprice == 0) {
$shipmethod = 'freeshipping_freeshipping';
}
// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
    ->collectShippingRates()
    ->setShippingMethod('flatrate_flatrate')
    ->setPaymentMethod('checkmo');
// Set Sales Order Payment
//$quote->getPayment()->importData(array('method' => 'checkmo'));
$quote->setShippingMethod('flatrate_flatrate');
// Collect Totals & Save Quote
$quote->collectTotals()->save();
try {
// Create Order From Quote
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$increment_id = $service->getOrder()->getRealOrderId();
}
catch (Exception $ex) {
echo $ex->getMessage();
}
catch (Mage_Core_Exception $e) {
echo $e->getMessage();
}

// Resource Clean-Up
$quote = $customer = $service = null;
// Finished
return $increment_id;
?>
最新回答
  • 2019-12-5
    1 #

    更改以下代码:

    // Collect Rates and Set Shipping & Payment Method
    $shippingAddress->setCollectShippingRates(true)
        ->collectShippingRates()
        ->setShippingMethod('flatrate_flatrate')
        ->setPaymentMethod('checkmo');
    // Set Sales Order Payment
    //$quote->getPayment()->importData(array('method' => 'checkmo'));
    $quote->setShippingMethod('flatrate_flatrate');
    

    为:

    // Collect Rates and Set Shipping & Payment Method
    $shippingAddress->setCollectShippingRates(true)
        ->collectShippingRates()
        ->setShippingMethod('flatrate_flatrate') 
        ->setPaymentMethod('checkmo');
    // Set Sales Order Payment
    $quote->getPayment()->importData(array('method' => 'checkmo'));
    //$quote->setShippingMethod('flatrate_flatrate');
    

    在上面的代码中,您使用送货方式统一费率,确保启用统一费率。

    setShippingMethod('flatrate_flatrate')
    

    使用以下代码的付款方式相同,您使用支票汇票,确保启用

    ->setPaymentMethod('checkmo');
    

  • 2019-12-5
    2 #

    代表不会让我发表评论.但是在尝试这个时我收到了一个错误.在1.9

    无效方法Mage_Customer_Model_Address :: collectShippingRates(Array())

  • magento 2.1:使用不是来自图库的样本更改类别缩略图
  • magento2:如何将块添加到Magento 2 Luma Theme标题?