私はプログラムでmagentoでオーダーを作成したいが、以下はスクリプトですがエラーになります。デモ用マゼンタにサンプルデータをインストールしました。Magento:Magentoオーダーをプログラムで作成する
致命的なエラー:F内の非オブジェクトのメンバ関数getRealOrderId()の呼び出しは:\ WAMP \ WWW \ magento1910sampledata \ createorder.php行に108
<?php
ini_set("display_errors","1");
include 'app/Mage.php';
Mage::app();
echo "1-";
$email = "[email protected]";
$productids = array(448, 450);
//$websiteId = Mage::app()->getWebsite()->getId();
$websiteId = 1;
$store = Mage::app()->getStore();
// Start New Sales Order Quote
$quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
echo "2-";
// 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('Test')
->setLastname('Order')
->setEmail($email)
->setPassword("password");
$customer->save();
}
echo "3-";
// Assign Customer To Sales Order Quote
$quote->assignCustomer($customer);
$quote->setIsSuperMode(true);
// Configure Notification
$quote->setSendCconfirmation(1);
echo "4-";
foreach ($productsids as $id) {
$product = Mage::getModel('catalog/product')->load($id);
$quote->addProduct($product, new Varien_Object(array('qty' => 1)));
}
echo "5-";
// Set Sales Order Billing Address
$billingAddress = $quote->getBillingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'Test',
'middlename' => '',
'lastname' => 'Order',
'suffix' => '',
'company' => '',
'street' => array(
'0' => '601 Blackburn Road',
'1' => 'Blackburn'
),
'city' => 'Notting Hill',
'country_id' => 'AU',
'region' => '491',
'postcode' => '3168',
'telephone' => '123456',
'fax' => '123456',
'vat_id' => '',
'save_in_address_book' => 1
));
echo "6-";
// Set Sales Order Shipping Address
$shippingAddress = $quote->getShippingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'Test',
'middlename' => '',
'lastname' => 'Order',
'suffix' => '',
'company' => '',
'street' => array(
'0' => '601 Blackburn Road',
'1' => 'Blackburn'
),
'city' => 'Notting Hill',
'country_id' => 'AU',
'region' => '491',
'postcode' => '3168',
'telephone' => '123456',
'fax' => '123456',
'vat_id' => '',
'save_in_address_book' => 1
));
if ($shipprice == 0) {
$shipmethod = 'freeshipping_freeshipping';
}
echo "7-";
// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('checkmo');
echo "7.1-";
// Set Sales Order Payment
$quote->getPayment()->importData(array('method' => 'checkmo'));
echo "8-";
// Collect Totals & Save Quote
$quote->collectTotals()->save();
echo "8.1-";
// Create Order From Quote
$service = Mage::getModel('sales/service_quote', $quote);
echo "8.2-";
$service->submitAll();
echo "8.3-";
$increment_id = $service->getOrder()->getRealOrderId();
echo "9-";
// Resource Clean-Up
$quote = $customer = $service = null;
echo "10-";
// Finished
echo $increment_id;
?>
こんにちはロビン、お返事に感謝。これは理解するのが少し難しいです。手動で小計をしなければならないのですか? –
@Robinはpaypalと同じ支払方法で同じコードを使用しています。これに関する助け。私たちがpaypalで試したところ、無効なトークンとしてエラーが発生しました。トランザクションを承認できません。 -paypalの成功応答を持つ注文imを作成する前に。どのように私はこれらの詳細を注文することができます。あなたはこれを助けてくれますか? – venkatesh
@Robin上記のコーディング - > setSku( 'product_sku')では、注文ごとに1つの商品のみを追加します。しかし、注文ごとに複数の製品(3種類の製品)が必要です。このケースを処理する方法 –