<commit_before><?php
/**
 * catalog_BlockProductlistAction
 * @package modules.catalog.lib.blocks
 */
class catalog_BlockProductlistAction extends catalog_BlockProductlistBaseAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		// Handle quanities field.
		$quantities = array();
		if ($request->hasParameter('quantities'))
		{
			foreach ($request->getParameter('quantities') as $id => $quantity)
			{
				$quantities[$id] =  intval($quantity);
			}
		}
		$request->setAttribute('quantities', $quantities);
		
		// Handle "Add to favorite".
		if ($request->hasParameter('addToFavorite'))
		{
			foreach ($request->getParameter('selected_product') as $id)
			{
				$this->addToFavorite(DocumentHelper::getDocumentInstance($id));
			}
			$this->addMessagesToBlock('add-to-favorite');
		}
		// Handle "Add to cart".
		else if ($request->hasParameter('addToCart'))
		{
			$productsToAdd = array();
			
			// List all products to add.		
			$addToCart = $request->getParameter('addToCart');
			if (is_array($addToCart))
			{
				foreach (array_keys($addToCart) as $id)
				{
					$quantity = max(intval($quantities[$id]), 1);
					$productsToAdd[$id] = array('product' => DocumentHelper::getDocumentInstance($id), 'quantity' => $quantity);
				}
			}
			else if ($request->hasParameter('selected_product'))
			{	
				$addToCart = $request->getParameter('selected_product');
				if (is_array($addToCart))
				{			
					// Add each product with no quantity but the checkbox checked (with quantity of 1).
					foreach ($addToCart as $id)
					{
						if (!array_key_exists($id, $productsToAdd))
						{
							$productsToAdd[$id] = array('product' => DocumentHelper::getDocumentInstance($id), 'quantity' => max(intval($quantities[$id]), 1));
						}
					}
				}
			}
			
			// Really add the products to the cart.
			$cs = order_CartService::getInstance();
			foreach ($productsToAdd as $item)
			{
				try
				{
					$cs->addProduct($item['product'], $item['quantity']);
					$this->addedProductLabels[] = $item['product']->getLabel();
				}
				catch(order_Exception $e)
				{
					$this->notAddedProductLabels[] = $item['product']->getLabel();
					if (Framework::isDebugEnabled())
					{
						Framework::debug($e->getMessage());
					}
				}
			}
			
			// Referesh the cart.
			$cart = $cs->getDocumentInstanceFromSession();
			$cart->refresh();						
			
			// Set the messages.
			$this->addMessagesToBlock('add-to-cart');
		}
		
		$request->setAttribute('shop', catalog_ShopService::getInstance()->getCurrentShop());
		
		$customer = null;
		if (catalog_ModuleService::areCustomersEnabled())
		{
			$customer = customer_CustomerService::getInstance()->getCurrentCustomer();
		}
		$request->setAttribute('customer', $customer);
		
		return ucfirst($request->getAttribute('blockView'));
	}
	
	/**
	 * @param catalog_persistentdocument_product $product
	 */
	private function addToFavorite($product)
	{
		try
		{
			if (catalog_ModuleService::getInstance()->addFavoriteProduct($product))
			{
				$this->addedProductLabels[] = $product->getLabel();
			}
		}
		catch (Exception $e)
		{
			$this->notAddedProductLabels[] = $product->getLabel();
			if (Framework::isDebugEnabled())
			{
				Framework::debug($e->getMessage());
			}
		}
	}
}<commit_msg>hotfixes merge<commit_after><?php
/**
 * catalog_BlockProductlistAction
 * @package modules.catalog.lib.blocks
 */
class catalog_BlockProductlistAction extends catalog_BlockProductlistBaseAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		// Handle quanities field.
		$quantities = array();
		if ($request->hasParameter('quantities'))
		{
			foreach ($request->getParameter('quantities') as $id => $quantity)
			{
				$quantities[$id] =  intval($quantity);
			}
		}
		$request->setAttribute('quantities', $quantities);
		
		// Handle "Add to favorite".
		if ($request->hasParameter('addToFavorite'))
		{
			foreach ($request->getParameter('selected_product') as $id)
			{
				$this->addToFavorite(DocumentHelper::getDocumentInstance($id));
			}
			$this->addMessagesToBlock('add-to-favorite');
		}
		// Handle "Add to cart".
		else if ($request->hasParameter('addToCart'))
		{
			$productsToAdd = array();
			
			// List all products to add.		
			$addToCart = $request->getParameter('addToCart');
			if (is_array($addToCart))
			{
				foreach (array_keys($addToCart) as $id)
				{
					$quantity = max(intval($quantities[$id]), 1);
					$productsToAdd[$id] = array('product' => DocumentHelper::getDocumentInstance($id), 'quantity' => $quantity);
				}
			}
			else if ($request->hasParameter('selected_product'))
			{	
				$addToCart = $request->getParameter('selected_product');
				if (is_array($addToCart))
				{			
					// Add each product with no quantity but the checkbox checked (with quantity of 1).
					foreach ($addToCart as $id)
					{
						if (!array_key_exists($id, $productsToAdd))
						{
							$productsToAdd[$id] = array('product' => DocumentHelper::getDocumentInstance($id), 'quantity' => max(intval($quantities[$id]), 1));
						}
					}
				}
			}
			
			// Really add the products to the cart.
			$cs = order_CartService::getInstance();
			$cart = null;
			foreach ($productsToAdd as $item)
			{
				try
				{
					$cart = $cs->addProduct($item['product'], $item['quantity']);
					$this->addedProductLabels[] = $item['product']->getLabel();
				}
				catch(order_Exception $e)
				{
					$this->notAddedProductLabels[] = $item['product']->getLabel();
					if (Framework::isDebugEnabled())
					{
						Framework::debug($e->getMessage());
					}
				}
			}
			
			// Refresh the cart.
			if ($cart !== null)
			{
				$cart->refresh();
				$this->addMessagesToBlock('add-to-cart');
			}
		}
		
		$request->setAttribute('shop', catalog_ShopService::getInstance()->getCurrentShop());
		
		$customer = null;
		if (catalog_ModuleService::areCustomersEnabled())
		{
			$customer = customer_CustomerService::getInstance()->getCurrentCustomer();
		}
		$request->setAttribute('customer', $customer);
		
		return ucfirst($request->getAttribute('blockView'));
	}
	
	/**
	 * @param catalog_persistentdocument_product $product
	 */
	private function addToFavorite($product)
	{
		try
		{
			if (catalog_ModuleService::getInstance()->addFavoriteProduct($product))
			{
				$this->addedProductLabels[] = $product->getLabel();
			}
		}
		catch (Exception $e)
		{
			$this->notAddedProductLabels[] = $product->getLabel();
			if (Framework::isDebugEnabled())
			{
				Framework::debug($e->getMessage());
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.16750517904705534, 'fraction_numerical': 0.0008878366380585972, 'mean_word_length': 3.69375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, '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': '1679793', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2086, 'n_words': 360}