1

I have form:

<form action="" class="ui-form">
    <h3>Быстрый заказ</h3>
    <div class="form-row">
        <input type="text" id="fastname" required autocomplete="off"><label for="fastname">Ваше имя</label>
    </div>
    <div class="form-row">
        <input type="text" id="fastphone" required autocomplete="off"><label for="fastphone">Телефон</label>
    </div>
    <div class="form-row">
        <input type="text" id="fastaddr" required autocomplete="off"><label for="fastaddr">Адрес доставки</label>
    </div>
    <p><input type="button" value="Заказать" onclick="fastorder(<?php echo  $this->getProduct()->getId()?>, <?php echo  $this->getProduct()->getPrice()?>)"></p>
</form>

And I have JavaScript that is called after I click a button on the form:

function fastorder(pr_id, pr_price){
    var pr_name = document.getElementById("fastname").value;
    var pr_phone = document.getElementById("fastphone").value;
    var pr_addr = document.getElementById("fastaddr").value;
    alert('ProductID:'+pr_id+'  Price:'+pr_price+'  Name:'+pr_name+'  Phone:'+pr_phone+'  Adress:'+pr_addr);
}

In the alert I get all the necessary information to create an order.

How to create an order help please?

I'm using (Magento 1.9.2.4)

0

You can add below code to order programatically you just need to replace product Ids from my code.

$productids=array(1,2,4,3);
 $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($productsids 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' => 'Street Address',
             '1' => 'Street Address 2'
         ),
     'city' => 'Your city',
     'country_id' => 'Your Country',
     'region' => 'Your Region',
     'postcode' => '123456',
     'telephone' => '78676789',
     'fax' => 'XXXXXX',
     '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' => 'Street Address',
             '1' => 'Street Address 2'
         ),
     'city' => 'Your City',
     'country_id' => 'Your Country',
     'region' => 'Your Region',
     'postcode' => '123456',
     'telephone' => '78676789',
     'fax' => 'XXXXXX',
     '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'));

 // Collect Totals & Save Quote
 $quote->collectTotals()->save();

 // Create Order From Quote
 $service = Mage::getModel('sales/service_quote', $quote);
 $service->submitAll();
 $increment_id = $service->getOrder()->getRealOrderId();

 // Resource Clean-Up
 $quote = $customer = $service = null;

 // Finished
 return $increment_id;
  • Its are a php code. How i can run php in my java function fastorder? I try ajax but its didnt work. – John Konor Aug 9 '18 at 8:54
  • Why are you using javascript? please use post method for form if ajax not required. – Aasim Goriya Aug 9 '18 at 10:23
  • I try, but in that page alredy have submit form. When i press submit on my form i place product in cart... – John Konor Aug 9 '18 at 23:21
  • you can use separate form with different controller in your action. – Aasim Goriya Aug 10 '18 at 4:14
  • Can you give me a little example code? – John Konor Aug 10 '18 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.