php - Magento Submit an order based on all items in cart -


ive tried next can find, , nothing create order me. im wanting transfer cart quote order , sort of custom checkout , heres class:

<?php     ini_set("display_errors", 1);     error_reporting(e_all);     class mycompany_finance_indexcontroller extends mage_core_controller_front_action{         public function indexaction(){              $conn = mage::getsingleton('core/resource')->getconnection('core_read');              $conn->query("create table if not exists `v12_finance_sales`             (                 `sales_id` int(11) not null auto_increment,                  `sales_reference` varchar(50) not null unique,                  `customer_id` int(11) not null ,                  `products` text not null ,                  `total_price` varchar(255) not null ,                  `status` varchar(4) not null ,                  primary key(`sales_id`)             )");                $this->loadlayout();               $block = $this->getlayout()->createblock(                                                 'mage_core_block_template',                                                 'v12content'                                                 )                                    ->settemplate('v12_finance/index.phtml');             $this->getlayout()->getblock('content')->append($block);              $this->renderlayout();          }         private function _getcustomersession() {             mage::getsingleton('core/session', array('name' => 'frontend'));             return mage::getsingleton('customer/session');         }         function successaction()         {              $reference = $_get['ref'];             $sales_reference = $_get['sr'];             $status = $_get['status'];             $auth = $_get['auth'];              $conn = mage::getsingleton('core/resource')->getconnection('core/read');              $confirmed = 0;              if($status == 'a' || $status == 's')             {                 $confirmed = 1;             }             try{                  $conn->query("update `v12_finance_sales` set `confirmed` = '$confirmed' , `status` = '$status' `sales_reference` = '$sales_reference'");                  $this->loadlayout();                  $this->renderlayout();              }catch(exception $e)             {                 $fh = fopen("finance_log.log" , "a+");                 fwrite($fh , "error[" . date('h:i:s d-m-y') . ']:exception:' . $e->getmessage());                 fclose($fh);                  $conn->query("create table if not exists `v12_finance_errors`                 (                     `error_id` int(11) not null auto_increment,                      `sales_reference` varchar(200) not null ,                      `status` varchar(4) not null ,                      primary key(`error_id`)                 )");                  $conn->query("insert `v12_finance_errors`                     (                         `sales_reference` ,                          `status`                     ) values (                         '" . $sales_reference . "' ,                          '$status'                     )");                  die("there error processing request, please contact <a href='mailto:support@jejamescycles.co.uk'>support</a> url");             }          }         function erroraction()         {             $message = $_get['error'];              $this->loadlayout();               $block = $this->getlayout()->createblock(                                                     'mage_core_block_template',                                                     'v12content'                                                     )                                        ->settemplate('v12_finance/finance_error.phtml');             $this->getlayout()->getblock('content')->append($block);              $this->renderlayout();         }         function basic_infoaction()         {               $conn = mage::getsingleton('core/resource')->getconnection('core/read');              if(!mage::getsingleton('customer/session')->isloggedin()){                // not logged in                  header("location: http:" . $_server['server_name'] . "/customer/account");              }else{                  $customer = mage::getmodel('customer/customer')                 ->setwebsiteid(mage::app()->getwebsite()->getid())                 ->loadbyemail(mage::getsingleton('customer/session')->getcustomer()->getemail());                  $quote = mage::getmodel('sales/quote')->setstoreid(mage::app()->getstore()->getid());                 $quote->assigncustomer($customer);                 $quote->setsendconfirmation(1);                  $items = mage::getmodel('checkout/cart')->getquote();                  foreach($items $item)                 {                     $quote->addproduct(mage::getmodel('catalog/product')->load($item->getid()) , 1);                 }                  // collect rates , set shipping & payment method                 $shippingaddress = $quote->getshippingaddress();                 $shippingaddress->setcollectshippingrates(true)                         ->collectshippingrates()                         ->setshippingmethod('flatrate_flatrate');                   // set sales order payment                  $quote_id = $this->createorder(array(                     'quoteid' => $quote->getid() ,                      'paymentmethod' => 'banktransfer' ,                      'paymentdata' => array()                 ) , $quote);                  echo '<pre>';                 var_dump($quote_id);                 var_dump($quote->getid());                 die();                  //$this->loadlayout();                   //$block = $this->getlayout()->createblock(                                                  //   'mage_core_block_template',                                                   //  'v12content'                                         //            )                                       // ->settemplate('v12_finance/finance_setup.phtml');                 //$this->getlayout()->getblock('content')->append($block);                 // $this->renderlayout();              }          }         public function createorder(array $orderdata , $quoteobj)          {            $quoteid = $orderdata['quoteid'];            $paymentmethod = $orderdata['paymentmethod'];            $paymentdata = $orderdata['paymentdata'];                   $items = $quoteobj->getallitems();                    $quoteobj->reserveorderid();              $quotepaymentobj = $quoteobj->getpayment();              $quotepaymentobj->setmethod($paymentmethod);             $quoteobj->setpayment($quotepaymentobj);               $convertquoteobj = mage::getsingleton('sales/convert_quote');             $orderobj = $convertquoteobj->addresstoorder($quoteobj->getshippingaddress());             $orderpaymentobj = $convertquoteobj->paymenttoorderpayment($quotepaymentobj);              $orderobj->setbillingaddress($convertquoteobj->addresstoorderaddress($quoteobj->getbillingaddress()));             $orderobj->setshippingaddress($convertquoteobj->addresstoorderaddress($quoteobj->getshippingaddress()));             $orderobj->setpayment($convertquoteobj->paymenttoorderpayment($quoteobj->getpayment()));              foreach ($items $item)              {                 $orderitem = $convertquoteobj->itemtoorderitem($item);                         $options = array();                if ($productoptions = $item->getproduct()->gettypeinstance(true)->getorderoptions($item->getproduct()))                 {                  $options = $productoptions;                }                if ($addoptions = $item->getoptionbycode('additional_options'))                 {                 $options['additional_options'] = unserialize($addoptions->getvalue());                }                if ($options)                 {                   $orderitem->setproductoptions($options);                }                if ($item->getparentitem())                {                     $orderitem->setparentitem($orderobj->getitembyquoteitemid($item->getparentitem()->getid()));                }                $orderobj->additem($orderitem);             }              $quoteobj->collecttotals();              $service = mage::getmodel('sales/service_quote', $quoteobj);              if(is_string($service->submitall()))              {                 echo $service->submitall();              }             try              {                   $last_order_increment_id = mage::getmodel("sales/order")->getcollection()->getlastitem()->getincrementid();                  return $last_order_increment_id;                         }              catch (exception $e)             {                      mage::log($e->getmessage());                 mage::log($e->gettraceasstring());                 return "exception:".$e;             }          }  } 

and every time come submit order, never submit, returns last inserted order , not script. offer help, i'm pulling hair out here,


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -