<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Product
 *
 * @author LENGY
 */

namespace ArtabanMarketplace\Actions;

use ArtabanMarketplace\Service\ProductLinkService;
use ArtabanMarketplace\Model\AmpSellerQuery;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;

class Product implements EventSubscriberInterface {

    private $productLinkService;

    public function __construct(ProductLinkService $productLinkService) {
        $this->productLinkService = $productLinkService;
    }

    public function associateProductSeller(ActionEvent $event) {
        $amp_seller_id = AmpSellerQuery::getSellerIdFromSession();
        $data = array();
        $data["product_id"] = $event->product->getId();
        $data["amp_seller_id"] = $amp_seller_id;

        $this->productLinkService->createFromArray($data);

    }

    public static function getSubscribedEvents() {
        return array(
            "action.after_createproduct" => array("associateProductSeller"),
        );
    }

}
