cancel
Showing results for 
Search instead for 
Did you mean: 

Create Order Programmatically. cant use variables in function

Create Order Programmatically. cant use variables in function

Hello!

I´ve got the plessure to take over the magento shop from some one else Smiley Very Happy:/

And i have a problem. 

the guy before my have made a form for on every produkt and when the costumer use this. we get an mail with the information, and the costumer get sendt to an success page. NOTE! No order in magento order page, only on emal

The problem is. Sometimes the emails doesent get sendt, and we dont get an order. 

SO, i want to program a order creat function when the costumer get to the success page. 

I can get the function to work when I use plan text in the function, but when i want to use my variables i get from the from, i get blank in the order! 

<?php 


$details = $this->getDetails();
$conferance_name = $details['product_name'];
$hotel = $details['hotelval'];
$date = $details['dateval'];
$ogtitel = $details['navn_title'];
$virksomhed = $details['virksomhed'];
$adresse = $details['adresse'];
$postnr = $details['postnr'];
$by = $details['by'];
$telefon = $details['telefon'];
$email = $details['email'];
$kommentarer = $details['kommentarer'];



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('DKK')
              ->setBase_currency_code('DKK')
              ->setStore_currency_code('DKK')
              ->setOrder_currency_code('DKK')
              ->setStatus($orderData['status']);

              // set Customer data
              $order->setCustomer_email($email)
              ->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;
}






?>

<?php /*?><p> Conference Name : <?php echo $this->__($conferance_name) ?></p>
<p> Name : <?php echo $this->__($ogtitel) ?></p>
<p> Email : <?php echo $this->__($email) ?></p>
<p> Hotel : <?php echo $this->__($hotel) ?></p>
<p> Date : <?php echo $this->__($date) ?></p>
<p> adresse : <?php echo $this->__($adresse) ?></p>
<p> postnr : <?php echo $this->__($postnr) ?></p>
<p> by : <?php echo $this->__($by) ?></p>
<p> telefon : <?php echo $this->__($telefon) ?></p>
<p> Kommentarer : <?php echo $this->__($kommentarer) ?></p><?php */?>


<h1>Tak for din tilmelding</h1>
<p>Du er nu tilmeldt konferencen <strong><?php echo $this->__($conferance_name) ?></strong> d. <?php echo $this->__($date) ?> i <?php echo $this->__($hotel) ?></p>
<br />
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('form-success')->toHtml(); ?>



NOTE i can use the variable to echo on the success page.


Hope you can help! Smiley Very Happy