1

When i go through cash on delivery process then success page get all order details on success page But when i go through paytm or other payment getway through its show error

Is there any solution for this type of issue in Magento 2?

enter image description here

succss.phtml

    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    $orderData = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId());
    $ProductRepository = $objectManager->create('Magento\Catalog\Model\ProductRepository');
    $timefc = $objectManager->create('\Magento\Framework\Stdlib\DateTime\TimezoneInterface');
    
    $categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
    
    $paymentdetails = $orderData->getPayment()->getData();
    $orderItems = $orderData->getAllVisibleItems();
    
    $order2 = $orderData->getData();
    $orderbilling2 = $orderData->getBillingAddress()->getData(); 
    $ordershipping2 = $orderData->getShippingAddress()->getData(); 

$mainarray['order_data']['order_id'] = $order2['increment_id'];
$mainarray['order_data']['purchase_date'] = $dateAsString;
$mainarray['order_data']['status'] = $order2['status'];
$mainarray['order_data']['grand_total'] = $order2['grand_total'];
$mainarray['order_data']['sub_total'] = $order2['base_subtotal'];
$mainarray['order_data']['payment_method'] = $paymentdetails['additional_information']['method_title'];

$mainarray['order_data']['delivery_charges'] = 0;
if ($paymentdetails['method']=='phoenix_cashondelivery') {
    $mainarray['order_data']['delivery_charges'] = $order2['cod_fee'];    
}

$mainarray['order_data']['coupon_code']= $order2['coupon_code'] ? $order2['coupon_code'] : "";
if ($order2['discount_amount']){
 $mainarray['order_data']['coupon_discount'] = abs($order2['discount_amount']);
}

$userType = $order2['customer_is_guest'];
if ($userType!=1) 
{
  $customer_id  = $order2['customer_id'];        
  $mainarray['customer_data']['customer_id'] = $customer_id;
  $mainarray['customer_data']['customer_type'] = "Customer";
}
else
{
  $mainarray['customer_data']['customer_type'] = "Guest Customer";
  $mainarray['customer_data']['customer_id'] = 0;
}
//address

$mainarray['customer_data']['customer_groupid'] = $order2['customer_group_id'];

$mainarray['customer_data']['billing_firstname'] = $orderbilling2['firstname'];
$mainarray['customer_data']['billing_lastname'] = $orderbilling2['lastname'];
$mainarray['customer_data']['billing_email'] = $orderbilling2['email'];
$mainarray['customer_data']['billing_mobile'] = $orderbilling2['telephone'];
$mainarray['customer_data']['billing_city'] = $orderbilling2['city'];
$mainarray['customer_data']['billing_state'] = $orderbilling2['region'];
$mainarray['customer_data']['billing_pincode'] = $orderbilling2['postcode'];
$mainarray['customer_data']['billing_address'] = $orderbilling2['street'];
 //shipping

$mainarray['customer_data']['shipping_name'] = $ordershipping2['firstname']." ".$ordershipping2['lastname'];
// $mainarray['customer_data']['shipping_lastname'] = ;
$mainarray['customer_data']['shipping_email'] = $ordershipping2['email'];
$mainarray['customer_data']['shipping_mobile'] = $ordershipping2['telephone'];
$mainarray['customer_data']['shipping_city'] = $ordershipping2['city'];
$mainarray['customer_data']['shipping_state'] = $ordershipping2['region'];
$mainarray['customer_data']['shipping_pincode'] = $ordershipping2['postcode'];
$mainarray['customer_data']['shipping_address'] = $ordershipping2['street'];


$productArr = [];
$result = [];

$type = array();

$mainarray['product_data'][] = array();


foreach ($orderItems as $key => $item1) {
    if ($item1) 
    {
        $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($item1->getProductId());
        $categoryIds = $_product->getCategoryIds();
        //echo '<pre>'; print_r($categoryIds); die();
        if ($categoryIds) 
        {
            $category_name="";
            foreach ($categoryIds as $category) {
                $category = $categoryFactory->create()->load($category);
                $category_name = $category->getName();
                if($category_name){
                    break;
                }
            }
            //$categoryall = implode(',', $category_name);
        }

        $options = $item1->getProductOptions();
        $optionsData = array();
        if (isset($options['options']) && !empty($options['options'])) {        
            foreach ($options['options'] as $option) {
                $optionsData[$option['label']] =  $option['value'];
            }
        }
        $additionaloptionsData = '';
        $additional_option_array=[];
        if (isset($options['attributes_info']) && !empty($options['attributes_info'])) {        
            foreach ($options['attributes_info'] as $option) {
                $additional_option_array[$option['label']]= $option['value'];
            }
        } 


        if(isset($options['additional_options'])){
            foreach($options['additional_options'] as $customoption){
                if($customoption['label']=='Women Size'){
                    $additional_option_array['Women Size']=$customoption['value'];
                }
                if($customoption['label']=='Custom Mask'){
                    $additional_option_array['Add Mask']=$customoption['value'];
                }
            }
        }
        $mainarray['product_data'][] = array(
            'name'  =>  $item1->getName(),
            'sku'   =>  $item1->getSku(),       
            'qty'   =>  (int)$item1->getQtyOrdered(),
            'price'   =>  $item1->getPrice(),
            'category_name'   =>  $category_name,
            'options'   => $optionsData,
            'additional_options'    => $additional_option_array
        );
    }
}
  • 1
    this is full code of success.phtml file ??? – Rk Rathod Nov 23 '20 at 5:27
  • no i will update wait – Jitendra prajapat Nov 23 '20 at 5:29
  • 1
    This is working with COD. But online payment get way to retrieve on success page show error – Jitendra prajapat Nov 23 '20 at 5:32
  • 1
    I don't see your getTelephone() in the success.phtml file. – Adarsh Khatri Nov 23 '20 at 5:57
  • I have taken telephone number – Jitendra prajapat Nov 23 '20 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.