<commit_before><?php
namespace Rbs\Catalog\Blocks;

use Change\Documents\Property;
use Change\Presentation\Blocks\Event;
use Change\Presentation\Blocks\Parameters;
use Change\Presentation\Blocks\Standard\Block;

/**
 * @name \Rbs\Catalog\Blocks\Category
 */
class Category extends Block
{
	/**
	 * Event Params 'website', 'document', 'page'
	 * @api
	 * Set Block Parameters on $event
	 * @param Event $event
	 * @return Parameters
	 */
	protected function parameterize($event)
	{
		$parameters = parent::parameterize($event);
		$parameters->addParameterMeta('categoryId', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('sectionId', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('conditionId', Property::TYPE_INTEGER, false);
		$parameters->addParameterMeta('itemsPerLine', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('itemsPerPage', Property::TYPE_INTEGER, true);

		$parameters->setLayoutParameters($event->getBlockLayout());
		if ($parameters->getParameter('categoryId') === null)
		{
			$document = $event->getParam('document');
			if ($document instanceof \Rbs\Catalog\Documents\Category)
			{
				$parameters->setParameterValue('categoryId', $document->getId());
			}
			else
			{
				/* @var $page \Change\Presentation\Interfaces\Page */
				$page = $event->getParam('page');
				$section = $page->getSection();
				$parameters->setParameterValue('sectionId', $section->getId());
				$query = new \Change\Documents\Query\Query($event->getDocumentServices(), 'Rbs_Catalog_Category');
				$query->andPredicates($query->eq('section', $section->getId()));
				$document = $query->getFirstDocument();
				if ($document)
				{
					$parameters->setParameterValue('categoryId', $document->getId());
				}
			}
		}
		return $parameters;
	}

	/**
	 * Set $attributes and return a twig template file name OR set HtmlCallback on result
	 * @param Event $event
	 * @param \ArrayObject $attributes
	 * @return string|null
	 */
	protected function execute($event, $attributes)
	{
		$parameters = $event->getBlockParameters();
		$categoryId = $parameters->getParameter('categoryId');
		if ($categoryId)
		{
			/* @var $commerceServices \Rbs\Commerce\Services\CommerceServices */
			$commerceServices = $event->getParam('commerceServices');
			$documentManager = $event->getDocumentServices()->getDocumentManager();

			/* @var $category \Rbs\Catalog\Documents\Category */
			$category = $documentManager->getDocumentInstance($categoryId);
			$attributes['title'] = $category->getTitle();

			//TODO: for development only
			$commerceServices->setBillingArea($category->getWebStore()->getBillingAreas()[0]);
			$commerceServices->setZone('FRC');

			//TODO: handle pagination
			$conditionId = $parameters->getParameter('conditionId');
			$query = new \Change\Documents\Query\Query($event->getDocumentServices(), 'Rbs_Catalog_Product');
			$subQuery = $query->getModelBuilder('Rbs_Catalog_ProductCategorization', 'product');
			$subQuery->andPredicates(
				$subQuery->eq('category', $categoryId), $conditionId ? $subQuery->eq('condition', $conditionId) : $subQuery->isNull('condition'));
			$subQuery->addOrder('position', true);

			$priceManager = $taxManager = null;
			if ($commerceServices->getBillingArea())
			{
				$priceManager = $commerceServices->getPriceManager();
				if ($commerceServices->getZone())
				{
					$taxManager = $commerceServices->getTaxManager();
				}
			}

			$rows = array();
			$webStore = $category->getWebStore();
			foreach ($query->getDocuments() as $product)
			{
				/* @var $product \Rbs\Catalog\Documents\AbstractProduct */
				$url = $event->getUrlManager()->getCanonicalByDocument($product)->toString();
				$row = array('id' => $product->getId(), 'url' => $url, 'price' => null,'priceTTC' => null );
				$price = $priceManager ? $priceManager->getPriceByProduct($product, $webStore) : null;
				if ($price)
				{
					$row['price'] = $price->getValue();<commit_msg>Remove development initialization in Rbs_Catalog_Category block<commit_after><?php
namespace Rbs\Catalog\Blocks;

use Change\Documents\Property;
use Change\Presentation\Blocks\Event;
use Change\Presentation\Blocks\Parameters;
use Change\Presentation\Blocks\Standard\Block;

/**
 * @name \Rbs\Catalog\Blocks\Category
 */
class Category extends Block
{
	/**
	 * Event Params 'website', 'document', 'page'
	 * @api
	 * Set Block Parameters on $event
	 * @param Event $event
	 * @return Parameters
	 */
	protected function parameterize($event)
	{
		$parameters = parent::parameterize($event);
		$parameters->addParameterMeta('categoryId', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('sectionId', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('conditionId', Property::TYPE_INTEGER, false);
		$parameters->addParameterMeta('itemsPerLine', Property::TYPE_INTEGER, true);
		$parameters->addParameterMeta('itemsPerPage', Property::TYPE_INTEGER, true);

		$parameters->setLayoutParameters($event->getBlockLayout());
		if ($parameters->getParameter('categoryId') === null)
		{
			$document = $event->getParam('document');
			if ($document instanceof \Rbs\Catalog\Documents\Category)
			{
				$parameters->setParameterValue('categoryId', $document->getId());
			}
			else
			{
				/* @var $page \Change\Presentation\Interfaces\Page */
				$page = $event->getParam('page');
				$section = $page->getSection();
				$parameters->setParameterValue('sectionId', $section->getId());
				$query = new \Change\Documents\Query\Query($event->getDocumentServices(), 'Rbs_Catalog_Category');
				$query->andPredicates($query->eq('section', $section->getId()));
				$document = $query->getFirstDocument();
				if ($document)
				{
					$parameters->setParameterValue('categoryId', $document->getId());
				}
			}
		}
		return $parameters;
	}

	/**
	 * Set $attributes and return a twig template file name OR set HtmlCallback on result
	 * @param Event $event
	 * @param \ArrayObject $attributes
	 * @return string|null
	 */
	protected function execute($event, $attributes)
	{
		$parameters = $event->getBlockParameters();
		$categoryId = $parameters->getParameter('categoryId');
		if ($categoryId)
		{
			/* @var $commerceServices \Rbs\Commerce\Services\CommerceServices */
			$commerceServices = $event->getParam('commerceServices');
			$documentManager = $event->getDocumentServices()->getDocumentManager();

			/* @var $category \Rbs\Catalog\Documents\Category */
			$category = $documentManager->getDocumentInstance($categoryId);
			$attributes['title'] = $category->getTitle();

			//TODO: handle pagination
			$conditionId = $parameters->getParameter('conditionId');
			$query = new \Change\Documents\Query\Query($event->getDocumentServices(), 'Rbs_Catalog_Product');
			$subQuery = $query->getModelBuilder('Rbs_Catalog_ProductCategorization', 'product');
			$subQuery->andPredicates(
				$subQuery->eq('category', $categoryId), $conditionId ? $subQuery->eq('condition', $conditionId) : $subQuery->isNull('condition'));
			$subQuery->addOrder('position', true);

			$priceManager = $taxManager = null;
			if ($commerceServices->getBillingArea())
			{
				$priceManager = $commerceServices->getPriceManager();
				if ($commerceServices->getZone())
				{
					$taxManager = $commerceServices->getTaxManager();
				}
			}

			$rows = array();
			$webStore = $category->getWebStore();
			foreach ($query->getDocuments() as $product)
			{
				/* @var $product \Rbs\Catalog\Documents\AbstractProduct */
				$url = $event->getUrlManager()->getCanonicalByDocument($product)->toString();
				$row = array('id' => $product->getId(), 'url' => $url, 'price' => null,'priceTTC' => null );
				$price = $priceManager ? $priceManager->getPriceByProduct($product, $webStore) : null;
				if ($price)
				{
					$row['price'] = $price->getValue();
{'fraction_non_alphanumeric': 0.16822669573022184, 'fraction_numerical': 0.00012822156686754713, 'mean_word_length': 4.972434915773354, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '126393', 'n_tokens_mistral': 2590, 'n_tokens_neox': 2269, 'n_words': 404}