Reputation: 1458
Is there a way that an order can be created within Magento with a "custom" product which would be defined within the order. The order wouldn't require the custom products to be created. These custom products would have custom prices and a custom product title determined when creating the order.
So when creating order, I would just simply specify some custom products with the prices then add them to the order.
Again, the products will not be defined anywhere within Magento, so I would just say, I want to add xyz at 9.99 and zxy at 1.99 and maybe I want to add another xyz at 3.99.
The order would show as,
xyz | 9.99
zxy | 1.99
xyz | 3.99
TOTAL | 15.97
Upvotes: 1
Views: 1564
Reputation: 1111
Programatically create an order with custom product is possible, here is an example code:
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');
$order = create();
echo $order;
function create()
{
$storeId = 1;
if (!$storeId) {
$storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
reset($storeIds);
$storeId = current($storeIds);
}
$order = Mage::getModel('sales/order')
->setState('new');
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($storeId)
->setCustomerPaymentId(0)
->setMethod('checkmo')
->setPo_number(' - ');
$order->setPayment($orderPayment);
$billingAddress = Mage::getModel('sales/order_address');
$shippingAddress = Mage::getModel('sales/order_address');
$order->setStoreId($storeId)
->setQuoteId(0)
->setGlobal_currency_code('EUR')
->setBase_currency_code('EUR')
->setStore_currency_code('EUR')
->setOrder_currency_code('EUR')
->setStatus($orderData['status']);
// set Customer data
$order->setCustomer_email('[email protected]')
->setCustomerFirstname('firstname')
->setCustomerLastname('lastname')
->setCustomer_is_guest(1);
// set Billing Address
$billingAddress
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setPrefix('mr')
->setFirstname('firstname')
->setLastname('lastname')
->setCompany('company')
->setStreet('street')
->setCity('city')
->setCountry_id('US')
->setPostcode('12345');
$order->setBillingAddress($billingAddress);
$shippingAddress
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setPrefix('mr')
->setFirstname('firstname')
->setLastname('lastname')
->setCompany('company')
->setStreet('street')
->setCity('city')
->setCountry_id('US')
->setPostcode('12345');
$order->setShippingAddress($shippingAddress)
->setShipping_method('freeshipping_freeshipping')
->setShippingDescription('Free Shipping - Free');
$orderItem = Mage::getModel('sales/order_item')
->setStoreId(1)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setQtyBackordered(NULL)
->setTotalQtyOrdered(10)
->setQtyOrdered(10)
->setName('custom product name')
->setPrice(100)
->setBasePrice(10)
->setOriginalPrice(10)
->setRowTotal(1000)
->setBaseRowTotal(1000);
$order->addItem($orderItem);
$order->setSubtotal(2000)
->setSubtotalIncludingTax(2000)
->setBaseSubtotal(2000)
->setGrandTotal(2000)
->setBaseGrandTotal(2000)
->setTaxAmount(0)
->setTotalQtyOrdered(10);
$order->save();
return $order;
}
?>
Upvotes: 3