2017-03-08 8 views
0

Magentoの中に新しいIAMが、私が注文 を作成するためのスクリプトを作成したい、私はたくさんのスクリプトで検索しましたし、私はこれを取得:Magento1.8 - 注文を作成するのに最適なスクリプトは何ですか?

<?php 

require_once 'app/Mage.php'; 

Mage::app(); 

$quote = Mage::getModel('sales/quote') 
    ->setStoreId(Mage::app()->getStore('default')->getId()); 

    // for guesr orders only: 
    $quote->setCustomerEmail('[email protected]'); 

// add product(s) 
$product = Mage::getModel('catalog/product')->load(431); 
$buyInfo = array(
    'qty' => 1, 
    // custom option id => value id 
    // or 
    // configurable attribute id => value id 
); 
$quote->addProduct($product, new Varien_Object($buyInfo)); 

$addressData = array(
    'firstname' => 'Test', 
    'lastname' => 'Test', 
    'street' => 'Sample Street 10', 
    'city' => 'Somewhere', 
    'postcode' => '123456', 
    'telephone' => '123456', 
    'country_id' => 'SA', 

); 

$billingAddress = $quote->getBillingAddress()->addData($addressData); 
$shippingAddress = $quote->getShippingAddress()->addData($addressData); 

$shippingAddress->setCollectShippingRates(true)->collectShippingRates() 
      ->setShippingMethod('freeshipping_freeshipping') 
      ->setPaymentMethod('cashondelivery'); 

$quote->getPayment()->importData(array('method' => 'cashondelivery')); 

$quote->collectTotals()->save(); 

$service = Mage::getModel('sales/service_quote', $quote); 
$service->submitAll(); 
$order = $service->getOrder(); 

printf("Created order %s\n", $order->getIncrementId()); 
?> 

をしかし、私はこのスクリプトを実行すると、それは私にエラーを与える「ページが動作していません"

これを修正したり、注文を作成するスクリプトを教えてもらえますか?

注私はかつてこれを試してみましたが、それは動作します "www.site.com/createorder.php

おかげ

+0

エラーの添付ファイル – bxN5

答えて

0

「を私はしてこのスクリプトを実行する":

<?php 
include '../app/Mage.php'; 
Mage::app(); 
// Need for start the session 
Mage::getSingleton('core/session', array('name' => 'frontend')); 
try { 

    $product_ids = array(
     $_GET['product_id_1'], 
     $_GET['product_id_2'], 
     $_GET['product_id_3'], 
     $_GET['product_id_4'] 
     ); 
    for($i=0;$i<4;$i++) 
    { 
     addToCart($product_ids[$i]); 
    } 
    /*addToCart($product_id_1); */ 

    Mage::getSingleton('checkout/session')->setCartWasUpdated(true); 
    Mage::getSingleton('core/session')->addSuccess('Product added successfully'); 
    header('Location: ' .Mage::getBaseURl(). 'checkout/cart/'); 
} catch (Exception $e) { 
    echo $e->getMessage(); 
} 
function addToCart($product_id) 
{ 
    $qty = '1'; 
    $product = Mage::getModel('catalog/product')->load($product_id); 
    $cart = Mage::getModel('checkout/cart'); 
    $cart->init(); 
    $cart->addProduct($product, array('qty' => $qty)); 
    $cart->save(); 
    return true; 
} 
?> 

リンクがあるべきproduct_id_1などの4つのパラメータが指定されていますので、それに応じて変更することができます。

+0

ありがとうございました を使用してコードを実行したときに問題が発生しました。 https://uae.arabianoud.com/create/doorder.php 「この製品は見つかりませんでした」 でも製品IDが正しいです 試み{ $ product_ids =配列( $ _GET [ 'product_id_122']、 $ _GET [ 'product_id_48']、 $ _GET [ 'product_id_50']、 $ _GET [ 'product_id_49':私はこのような製品IDを追加しました] ); for($ i = 0; $ i <4; $ i ++) { addToCart($ product_ids [$ i]); } また、お客様の詳細と配送の詳細を更新するにはどうすればいいですか –

+0

これは明らかに機能しません。コードは次のようになります:$ _GET ['122']の代わりに$ _GET ['product_id_122' ]など、これがあなたのために働くかどうか私に教えてください –

関連する問題