<?php

namespace Magetop\Agency\Plugin\Checkout\CustomerData;

class AbstractItem
{
    /**
     * @var \Magetop\Agency\Helper\Data
     */
    private $_helper;

    /**
     * Initialize dependencies.
     *
     * @param \Magetop\Agency\Helper\Data $helper
     */
    public function __construct(
        \Magetop\Agency\Helper\Data $helper
    ) {
        $this->_helper = $helper;
    }

    public function afterGetItemData(
        \Magento\Checkout\CustomerData\AbstractItem $subject,
        $result
    ) {
        if (isset($result['item_id'])) {
            $item_id = $result['item_id'];
            $assignData = $this->_helper->getAssignDataByItemId($item_id);
            if ($assignData['assign_id'] > 0) {
                $result['is_visible_in_site_visibility']=false;
            }
        }
        return $result;
    }
}
