<commit_before><?php
/**
 * @package modules.order.lib.blocks
 */
class order_BlockShippingStepAction extends order_BlockAbstractProcessStepAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		if ($this->isInBackoffice())
		{
			return website_BlockView::NONE;
		}
		if (!$this->checkCurrentCustomer())
		{
			$this->redirectToFirstStep();
		}
		
		$this->setCurrentStep('Shipping');
		$cartInfo = $this->getCurrentCart();
		if ($cartInfo->isEmpty())
		{
			$this->redirectToEmptyCart();
		}

		// The order process is started, so init lastAbandonedOrderDate.
		$customer = $cartInfo->getCustomer();
		$customer->setLastAbandonedOrderDate(date_Calendar::getInstance()->toString());
		$customer->save();

		$shippingStep = $cartInfo->getAddressInfo();
		if (!$shippingStep instanceof order_ShippingStepBean)
		{
			$shippingStep = new order_ShippingStepBean();
			if ($customer->getDefaultAddress())
			{
				$shippingStep->importShippingAddress($customer->getDefaultAddress());
			}
			else
			{
				$user = $customer->getUser();
				$shippingStep->shippingAddress->Email = $user->getEmail();
				$shippingStep->shippingAddress->FirstName = $user->getFirstname();
				$shippingStep->shippingAddress->LastName = $user->getLastname();
				$shippingStep->shippingAddress->Title = $user->getTitle();
			}
			$shippingStep->billingAddress->Email = $customer->getUser()->getEmail();
			$cartInfo->setAddressInfo($shippingStep);
			$cartInfo->save();
		}
		$request->setAttribute('shippingStep', $shippingStep);		
		return $this->getInputViewName();
	}
	
	/**
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @param order_ShippingStepBean $shippingStep
	 * @return String
	 */
	function executeUseRegisteredShippingAddress($request, $response, order_ShippingStepBean $shippingStep)
	{
		$addressId = intval($request->getParameter('registeredShippingAddress'));
		if ($addressId > 0)
		{<commit_msg>[FIX] Add missing transaction on order process<commit_after><?php
/**
 * @package modules.order.lib.blocks
 */
class order_BlockShippingStepAction extends order_BlockAbstractProcessStepAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		if ($this->isInBackoffice())
		{
			return website_BlockView::NONE;
		}
		if (!$this->checkCurrentCustomer())
		{
			$this->redirectToFirstStep();
		}
		
		$this->setCurrentStep('Shipping');
		$cartInfo = $this->getCurrentCart();
		if ($cartInfo->isEmpty())
		{
			$this->redirectToEmptyCart();
		}

		$tm = f_persistentdocument_TransactionManager::getInstance();
		try 
		{
			$tm->beginTransaction();
			// The order process is started, so init lastAbandonedOrderDate.
			$customer = $cartInfo->getCustomer();
			$lastAbandonedOrderDate = date_Calendar::getInstance()->toString();
			$customer->setLastAbandonedOrderDate($lastAbandonedOrderDate);
	
			$shippingStep = $cartInfo->getAddressInfo();
			if (!$shippingStep instanceof order_ShippingStepBean)
			{
				$shippingStep = new order_ShippingStepBean();
				if ($customer->getDefaultAddress())
				{
					$shippingStep->importShippingAddress($customer->getDefaultAddress());
				}
				else
				{
					$user = $customer->getUser();
					$shippingStep->shippingAddress->Email = $user->getEmail();
					$shippingStep->shippingAddress->FirstName = $user->getFirstname();
					$shippingStep->shippingAddress->LastName = $user->getLastname();
					$shippingStep->shippingAddress->Title = $user->getTitle();
				}
				$shippingStep->billingAddress->Email = $customer->getUser()->getEmail();
				$cartInfo->setAddressInfo($shippingStep);			
				$cartInfo->save();
			}
			
			if ($customer->isModified())
			{
				$customer->save();
			}
						
			$tm->commit();
		} 
		catch (Exception $e)
		{
			$tm->rollBack($e);
		}
		$request->setAttribute('shippingStep', $shippingStep);		
		return $this->getInputViewName();
	}
	
	/**
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @param order_ShippingStepBean $shippingStep
	 * @return String
	 */
	function executeUseRegisteredShippingAddress($request, $response, order_ShippingStepBean $shippingStep)
	{
		$addressId = intval($request->getParameter('registeredShippingAddress'));
		if ($addressId > 0)
		{
{'fraction_non_alphanumeric': 0.15270935960591134, 'fraction_numerical': 0.0004478280340349306, 'mean_word_length': 4.633039092055485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '4616822', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1381, 'n_words': 213}