forked from pardahlman/docker-akeneo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductModificationListener.php
39 lines (33 loc) · 1.06 KB
/
ProductModificationListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Acme\Bundle\AppBundle\EventListener;
use Symfony\Component\EventDispatcher\GenericEvent;
use Pim\Bundle\CatalogBundle\Model\ProductInterface;
class ProductModificationListener
{
public function __construct()
{
}
public function onPostSave(GenericEvent $event)
{
// Check if this is a product call
$subject = $event->getSubject();
$isProductModificationCall = is_subclass_of(
$subject,
'Pim\Component\Catalog\Model\ProductInterface'
);
// Notify server upon request
if ($isProductModificationCall) {
$url = 'http://server.com/path';
$data = json_encode($subject);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $data
)
);
$context = stream_context_create($options);
$result = file_get_contents('http://url-to-server/?productId=' . $subject, false, $context);
}
}
}