Skip to main content
edited body
Source Link
Aasim Goriya
  • 5.5k
  • 2
  • 28
  • 53

@Idham choudryChoudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;
use Magento\Sales\Model\Order;

class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;

public function __construct(
     Session $customerSession,
    CustomerRepositoryInterface $customerrepository,
    Order $order
 )
{
    $this->customerSession = $customerSession;
    $this->customerrepository = $customerrepository; 
    $this->order = $order;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $orderIds = $event->getOrderIds();

    $order = $observer->getEvent()->getOrder();

    $ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);

    $shippingdetails = $ordercoll->getShippingAddress()->getData();
    $magento_address_id = $ordercoll->getShippingAddress()->getId();
    $billingdetails = $ordercoll->getBillingAddress()->getData();
    $paymentdetails = $ordercoll->getPayment()->getData();
    $shipmentdetails = $ordercoll->getShippingmethod();
    $customerinfo = $this->customerSession->getData();
    $shipping_amount = $ordercoll->getShippingAmount();
    $discount_amount = $ordercoll->getDiscountAmount();
    $discount_description = $ordercoll->getDiscountDescription();
    $applied_rule_ids = $ordercoll->getAppliedRuleIds();

}

}

@Idham choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;
use Magento\Sales\Model\Order;

class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;

public function __construct(
     Session $customerSession,
    CustomerRepositoryInterface $customerrepository,
    Order $order
 )
{
    $this->customerSession = $customerSession;
    $this->customerrepository = $customerrepository; 
    $this->order = $order;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $orderIds = $event->getOrderIds();

    $order = $observer->getEvent()->getOrder();

    $ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);

    $shippingdetails = $ordercoll->getShippingAddress()->getData();
    $magento_address_id = $ordercoll->getShippingAddress()->getId();
    $billingdetails = $ordercoll->getBillingAddress()->getData();
    $paymentdetails = $ordercoll->getPayment()->getData();
    $shipmentdetails = $ordercoll->getShippingmethod();
    $customerinfo = $this->customerSession->getData();
    $shipping_amount = $ordercoll->getShippingAmount();
    $discount_amount = $ordercoll->getDiscountAmount();
    $discount_description = $ordercoll->getDiscountDescription();
    $applied_rule_ids = $ordercoll->getAppliedRuleIds();

}

}

@Idham Choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;
use Magento\Sales\Model\Order;

class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;

public function __construct(
     Session $customerSession,
    CustomerRepositoryInterface $customerrepository,
    Order $order
 )
{
    $this->customerSession = $customerSession;
    $this->customerrepository = $customerrepository; 
    $this->order = $order;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $orderIds = $event->getOrderIds();

    $order = $observer->getEvent()->getOrder();

    $ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);

    $shippingdetails = $ordercoll->getShippingAddress()->getData();
    $magento_address_id = $ordercoll->getShippingAddress()->getId();
    $billingdetails = $ordercoll->getBillingAddress()->getData();
    $paymentdetails = $ordercoll->getPayment()->getData();
    $shipmentdetails = $ordercoll->getShippingmethod();
    $customerinfo = $this->customerSession->getData();
    $shipping_amount = $ordercoll->getShippingAmount();
    $discount_amount = $ordercoll->getDiscountAmount();
    $discount_description = $ordercoll->getDiscountDescription();
    $applied_rule_ids = $ordercoll->getAppliedRuleIds();

}

}
added 1237 characters in body
Source Link

@Idham choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;
use Magento\Sales\Model\Order;

class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;

public function __construct(
     Session $customerSession,
    CustomerRepositoryInterface $customerrepository,
    Order $order
 )
{
    $this->customerSession = $customerSession;
    $this->customerrepository = $customerrepository; 
    $this->customerSession>order = $customerSession;$order;
}
$customerid
public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $orderIds = $event->getOrderIds();

    $order = $observer->getEvent()->getOrder();

    $ordercoll = $this->customerSession>order->getCustomerId>loadByAttribute("entity_id",$orderIds[0]);

    $shippingdetails = $ordercoll->getShippingAddress()->getData();
$customer    $magento_address_id = $ordercoll->getShippingAddress()->getId();
    $billingdetails = $ordercoll->getBillingAddress()->getData();
    $paymentdetails = $ordercoll->getPayment()->getData();
    $shipmentdetails = $ordercoll->getShippingmethod();
    $customerinfo = $this->customerrepository>customerSession->getById>getData($customerid);
    $shipping_amount = $ordercoll->getShippingAmount();
$customer    $discount_amount = $ordercoll->getFirstName>getDiscountAmount();
    $discount_description = $ordercoll->getDiscountDescription();
    $applied_rule_ids = $ordercoll->getAppliedRuleIds();

}

}

@Idham choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;


$this->customerrepository = $customerrepository;
$this->customerSession = $customerSession;

$customerid = $this->customerSession->getCustomerId();
$customer = $this->customerrepository->getById($customerid);

$customer->getFirstName();

@Idham choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;
use Magento\Sales\Model\Order;

class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;

public function __construct(
     Session $customerSession,
    CustomerRepositoryInterface $customerrepository,
    Order $order
 )
{
    $this->customerSession = $customerSession;
    $this->customerrepository = $customerrepository; 
    $this->order = $order;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $orderIds = $event->getOrderIds();

    $order = $observer->getEvent()->getOrder();

    $ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);

    $shippingdetails = $ordercoll->getShippingAddress()->getData();
    $magento_address_id = $ordercoll->getShippingAddress()->getId();
    $billingdetails = $ordercoll->getBillingAddress()->getData();
    $paymentdetails = $ordercoll->getPayment()->getData();
    $shipmentdetails = $ordercoll->getShippingmethod();
    $customerinfo = $this->customerSession->getData();
    $shipping_amount = $ordercoll->getShippingAmount();
    $discount_amount = $ordercoll->getDiscountAmount();
    $discount_description = $ordercoll->getDiscountDescription();
    $applied_rule_ids = $ordercoll->getAppliedRuleIds();

}

}
Source Link

@Idham choudry,

you can add below code in to your observer to get customer information.

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session;


$this->customerrepository = $customerrepository;
$this->customerSession = $customerSession;

$customerid = $this->customerSession->getCustomerId();
$customer = $this->customerrepository->getById($customerid);

$customer->getFirstName();