Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

ccsave order created successfully but credit card number missing in order detail page. 
 
katherinbridges
Jr. Member
 
Total Posts:  29
Joined:  2009-08-27
 

Hi,
I am using magento 1.6.1 and have got a code snippet to create order programmatically. The order is created successfully but credit card number is empty when you go in order detail in admin panel. My code is like this.

$customer_id 2
        
$shopping_cart=array();
        
$part=array("PartId"=>17"Quantity"=>5);
        
$shopping_cart[]=$part//repeat as necessary
        
$params=array("AccountNo"=>$customer_id"PartCart"=>$shopping_cart);
        
$qoteid $this->PrepareOrder($params);
        
$this->createOrder($qoteid,'ccsave',true);

        function 
PrepareOrder($params{
            
//require_once '../app/Mage.php';
            
require_once 'app/Mage.php';
            
$app Mage::app();
            
Mage::register('isSecureArea'true); //no output before here, will get a session header error
            
foreach($params as $k=>$v
                
$$k=$v
            
}
            $customerObj
=Mage::getModel('customer/customer')->load($AccountNo);
            
$storeId=$customerObj->getStoreId();
            
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
            
$storeObj=$quoteObj->getStore()->load($storeId);
            
$quoteObj->setStore($storeObj);
            
$productModel=Mage::getModel('catalog/product');            
            foreach(
$PartCart as $part{
                
foreach($part as $k=>$v
                    
$$k=$v
                
}
                $productObj
=$productModel->load($PartId);
                
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);
                
$quoteItem->setQuote($quoteObj);
                
$quoteItem->setQty($Quantity);
                
$quoteObj->addItem($quoteItem);
            
}
            $quoteObj 
-> addMessage('Auto Order Code');   //after separately
            
$quoteObj->collectTotals();
            
$quoteObj->save();
            
$quoteId=$quoteObj->getId();
            return 
$quoteId;
        
}

        
public function createOrder($quoteId$paymentMethod$paymentData
        
{
            $quoteObj 
Mage::getModel('sales/quote')->load($quoteId); // Mage_Sales_Model_Quote
            
$items $quoteObj->getAllItems();
            
$quoteObj->reserveOrderId();
              
// set payment method 
            
$quotePaymentObj $quoteObj->getPayment(); // Mage_Sales_Model_Quote_Payment
            
$quotePaymentObj->setMethod($paymentMethod);
            
$quoteObj->setPayment($quotePaymentObj);              
            
// convert quote to order
            
$convertQuoteObj Mage::getSingleton('sales/convert_quote');
            
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
            
$orderPaymentObj $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);            
            
// convert quote addresses
            
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));            $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));            
            
// set payment options
            
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
            if (
$paymentData{                
                $orderObj
->getPayment()->setCcNumber('6011111111111117');
                
$orderObj->getPayment()->setCcOwner('ooooo');
                
$orderObj->getPayment()->setCcType('Discover');
                
$orderObj->getPayment()->setCcExpMonth('9');
                
$orderObj->getPayment()->setCcExpYear('2014');
                
$orderObj->getPayment()->setCcLast4(substr('6011111111111117',-4));
            
}
            
// convert quote items
            
foreach ($items as $item{
                
// @var $item Mage_Sales_Model_Quote_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);
            
}            
            $orderObj
->setCanShipPartiallyItem(false);          
            try 
{
                $orderObj
->place();
            
catch (Exception $e){        
                Mage
::log($e->getMessage());
                
Mage::log($e->getTraceAsString());
            
}            
            $orderObj
->save(); 
            
//$orderObj->sendNewOrderEmail(); 
            
return $orderObj->getId();            
        
}
I did not know the value of parameter $paymentData therefore I passed true to call this function.
Please help is required to resolve this issue because I am working on this is
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top