<?php

namespace KupShop\ElninoBundle\GoogleTagManager\Page;

class Category extends AbstractPage
{
    protected function setBaseData($context)
    {
        $data = $this->dataLayer->getGtp();

        $this->addUri();

        $c = new \stdClass();
        if (!empty($context['body']['category']->id)) {
            $c->categoryID = $context['body']['category']->id ?? 0;
            $c->categoryName = $context['body']['category']->name;
        }

        //        if ($context['body']['producer']->producerId) {
        //            $c->producerName = $context->producer['name'] ?? '';
        //            $c->producerId = $context->producerId;
        //        }

        $data->category = $c;
    }

    protected function setEccomData($context)
    {
        parent::setEccomData($context);

        $data = $this->dataLayer->getGtp();

        $data->ecomm_pagetype = 'category';
    }

    protected function setDynxData($context)
    {
        parent::setDynxData($context);

        $data = $this->dataLayer->getGtp();

        $data->dynx_pagetype = 'searchresults';
    }

    protected function setPageData($context)
    {
        $data = $this->dataLayer->getGtp();

        if (empty($data->pageData)) {
            $data->pageData = new \stdClass();
        }

        if (!empty($context['body']['producer']['id'])) {
            $data->pageData->productData = [
                'RTB_list_id' => $this->getSeriesByProducer($context['body']['producer']['id']),
            ];
        }
    }
}
