Standard   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A body() 0 3 1
A init() 0 30 6
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2025
7
 * @package Client
8
 * @subpackage Html
9
 */
10
11
12
namespace Aimeos\Client\Html\Checkout\Standard\Process\Address;
13
14
15
/**
16
 * Default implementation of checkout address process HTML client.
17
 *
18
 * @package Client
19
 * @subpackage Html
20
 */
21
class Standard
22
	extends \Aimeos\Client\Html\Common\Client\Factory\Base
23
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
24
{
25
	/**
26
	 * Returns the HTML code for insertion into the body.
27
	 *
28
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
29
	 * @return string HTML code
30
	 */
31
	public function body( string $uid = '' ) : string
32
	{
33
		return '';
34
	}
35
36
37
	/**
38
	 * Processes the input, e.g. provides the address form.
39
	 *
40
	 * A view must be available and this method doesn't generate any output
41
	 * besides setting view variables.
42
	 */
43
	public function init()
44
	{
45
		$context = $this->context();
46
47
		try
48
		{
49
			if( $context->user() !== null )
50
			{
51
				$basket = \Aimeos\Controller\Frontend::create( $context, 'basket' )->get();
52
				$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' );
53
				$item = $cntl->uses( ['customer/address'] )->get();
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
54
55
				foreach( $basket->getAddress( 'delivery' ) as $address )
56
				{
57
					if( $address->getAddressId() == '' && $address->get( 'nostore', false ) == false )
58
					{
59
						$addrItem = $cntl->createAddressItem()->copyFrom( $address );
60
						$cntl->addAddressItem( $addrItem )->store();
61
						$address->setAddressId( (string) $addrItem->getId() );
62
					}
63
				}
64
			}
65
		}
66
		catch( \Exception $e )
67
		{
68
			$msg = sprintf( 'Unable to save address for customer "%1$s": %2$s', $context->user(), $e->getMessage() );
69
			$context->logger()->info( $msg, 'client/html' );
70
		}
71
72
		parent::init();
73
	}
74
}
75