0

I have a requirement that is collect customers data like wishlist, address and send them to another server using SFTP. These all should be programmatically.

Could anyone please guide me on this?

Your help will be greatly appreciated!

1 Answer 1

0
class WishlistLoadItems extends \Magento\Framework\App\Action\Action
{


    public function __construct(
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Wishlist\Model\Wishlist $wishlist,
        \Magento\Customer\Api\Data\AddressInterface $adrs,
        \Magento\Framework\App\Action\Context $context
    ) {
        $this->customerSession = $customerSession;
        $this->wishlist = $wishlist;
        $this->adrs = $adrs;
        parent::__construct($context);
    }

    public function execute()
    {
        if ($this->customerSession->isLoggedIn()) {

            $customer_id = $this->customerSession->getCustomer()->getId();
            $wishlist_collection = $this->wishlist->loadByCustomerId($customer_id, true)->getItemCollection();

            wishlist_data=[];
            // get whishlist pdt name

            foreach ($wishlist_collection as $item) {
               // $wishlist_data[] = $item->getProduct()->getData(); // to get product datas
                $wishlist_data[] = $item->getProduct()->getName(); // to get whishlist product name
            }

            // to get user adrs
            $customer = $this->adrs->getById($customer_id);
            //$addresses = $customer->getAddresses(); // to get address array
            $billingAddress = $customer->getDefaultBilling();  // to get biling adrs


            if(wishlist_data) 
            {

                  // do your logic  if customer whishlist not empty
            }else
            {
                // do your logic  if customer whishlist is empty
            }


        } 
    }
}

It helps to load logged customer whishlist product datas and adrs

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.