If you follow your written procedure as a human using the interface. Does the rate show up with the correct information? Is that user able to use that rate? Are the rate settings correct?
To me it looks like your trying to replicate the checkout process which might not be your way to go. Can you tell me some more about where and how you try to run this code? Custom module, template file, php file in root etc. Be as specific as possible when asking questions here. I ran your code and it doesn't work at all on my end as i expected. There are some odd things going on. I suggest you take a good look at a working example. I found this article, now the article itself doesn't have the example. i'm talking about but one of the commentors who posted a really nice example which you can run from your root directory. I tested it on magento 1.9.1 with sample data and it works like a charm.
The developers at Inchoo write really good articles like this one:
http://inchoo.net/magento/programmatically-create-order-in-magento/
Following the code which works in my demo shop. I'm sure if you look closely at this you'll solve your problem. Just let me know if you get stuck again. Good luck ;)
//these lines are required to run this php file from root. If you include it somewhere within magento you won't need it.
require_once 'app/Mage.php';
Mage::app();
//set the store
$quote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore('default')->getId());
//load a customer or go for guest, known or unknown customer it works
if ('do customer orders') {
// for customer orders:
$customer = Mage::getModel('customer/customer')
->setWebsiteId(1)
->loadByEmail('customerrr@example.com');
$quote->assignCustomer($customer);
} else {
// for guesr orders only:
$quote->setCustomerEmail('customerrr@example.com');
}
// add product(s)
$product = Mage::getModel('catalog/product')->load(231);
$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 1000',
'city' => 'Somewhere',
'postcode' => '123456789',
'telephone' => '123456789',
'country_id' => 'US',
'region_id' => 12, // id from directory_country_region table
);
//set shipping and billing address
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
//get and set methods
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('checkmo');
$quote->getPayment()->importData(array('method' => 'checkmo'));
$quote->collectTotals()->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
//these lines are required to run this php file from root. If you include it somewhere within magento you won't need it.
require_once 'app/Mage.php';
Mage::app();
//set the store
$quote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore('default')->getId());
//load a customer or go for guest, known or unknown customer it works
if ('do customer orders') {
// for customer orders:
$customer = Mage::getModel('customer/customer')
->setWebsiteId(1)
->loadByEmail('customerrr@example.com');
$quote->assignCustomer($customer);
} else {
// for guesr orders only:
$quote->setCustomerEmail('customerrr@example.com');
}
// add product(s)
$product = Mage::getModel('catalog/product')->load(231);
$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 1000',
'city' => 'Somewhere',
'postcode' => '123456789',
'telephone' => '123456789',
'country_id' => 'US',
'region_id' => 12, // id from directory_country_region table
);
//set shipping and billing address
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
//get and set methods
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('checkmo');
$quote->getPayment()->importData(array('method' => 'checkmo'));
$quote->collectTotals()->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
printf("Created order %s\n", $order->getIncrementId());
Add this code in the checkout_index_index.xml
for remove the require entry at the respective item name. For example, i have removed required for firstname.
<item name="firstname" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">false</item>
</item>
</item>
Best Answer
Remove Postcode from Checkout
First create the
di.xml
inisde you extension directly in folder etcYourVendor/YourExtName/etc/di.xml
and fill :Now create the class Address inside
YourVendor/YourExtName/Model/Qoute/Adress
,php and push :Update :-
And Check
is_requred
is 0 or 1If 1 Than Change And Try