0

I have created a plugin that allows customers to buy downloadable products as a customer and creates a user for them. It assigns the order to the customer, they receive an invoice. On the admin side I can see the order assigned to them ( it has a status of complete ) and on their account, they can see the order. When they check their account under my products it is not there. This is in Magento 2. How do I assign the product to the customer so they can download it?

  • So I am creating the order, then creating the customer and assigning the order to the customer. I believe assigning the order after creation is causing the issue. – user2938331 Nov 19 '17 at 22:36
  • I have found that the downloadable link is not having it's customer Id set any help with this would be appreciated – user2938331 Nov 19 '17 at 23:05
0

Upon creation of the order, the links are given the customer id of the order. Since, I created the order with no customer id and then assigned only the order a customer id, the link was always missing the customer id.

/*
 * @var $this->downloadLink = \Magento\Downloadable\Model\Link\PurchasedFactory;
 */
 $items = $order->getAllItems();
foreach($items as $item){
    //look for downloadable products
    if($item->getProductType() === 'downloadable'){
        // create link from repository
        $link = $this->downloadLink->create()->load($item->getId(), 'order_item_id');
        $link->setCustomerId($customer->getId());
        $link->save();
    }
}
| improve this answer | |

Your Answer

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

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