0

I want to send info to third party services about the views on pages like cart, products, checkout, etc. This info is sent whenever someone visits the respective page or view. For example, when a client sees a product on my store, I want to send the info about the product, time, etc. Does anynone have a clue of how to do this?

2
  • How did you want to send the info? You want to display the info or something else? Oct 10 '18 at 9:57
  • No, just create a json message with the info within.
    – dirac
    Oct 10 '18 at 20:38
0

You can do it by event observer, here and here for how to create custom observer. And you want to send data to your services (for example if you want to send about checked out item, you can use sales_model_service_quote_submit_success event), and then just create the json and send it with file_get_contents function like below :

$order = $observer->getOrder(); //get the order details
$quoteRepository = $this->_objectManager->create('Magento\Quote\Model\QuoteRepository'); //create repository
$quote = $quoteRepository->get($order->getQuoteId()); //get cart information by quote ID

$cartId = $order->getQuoteId(); //get cart ID
$allItems = $quote->getItemsCollection(); //get all checked out items

foreach ($allItems as $item) {
   $data[] = array (
      "itemSKU" => $item->getSku(), //save item SKU
      "itemQuantity" => $item->getQty() //save item Quantity 
   )
}

$json = json_encode($data); //save the arrays to json
$serviceUrl = //your service URL;
$service = json_decode(file_get_contents($serviceUrl.$json)); //send the json to your service and get the feed back

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.