Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Supplier.php #245

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 57 additions & 28 deletions lib/mshoplib/src/MShop/Service/Provider/Decorator/Supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ class Supplier
extends \Aimeos\MShop\Service\Provider\Decorator\Base
implements \Aimeos\MShop\Service\Provider\Decorator\Iface
{
private $beConfig = array(
'supplier.addressformat' => array(
'code' => 'supplier.addressformat',
'internalcode' => 'supplier.addressformat',
'label' => 'Change supplier address format.',
'type' => 'text',
'internaltype' => 'text',
'default' => '%1$s
%2$s
%3$s %4$s
%5$s
%6$s %7$s
%8$s %9$s
%10$s
%11$s
%12$s
%13$s',
'required' => false,
),
);

private $feConfig = array(
'supplier.code' => array(
'code' => 'supplier.code',
Expand Down Expand Up @@ -64,12 +85,11 @@ public function __construct( \Aimeos\MShop\Service\Provider\Iface $provider,
{
$addrId = ( count( $addresses ) > 1 ) ? $item->getCode() . '-' . $id : $item->getCode();

$this->feConfig['supplier.code']['default'][$addrId] = trim( preg_replace( "/\n+/m", "\n", sprintf(
/// Supplier address format with label (%1$s), company (%2$s),
/// address part one (%3$s, e.g street), address part two (%4$s, e.g house number), address part three (%5$s, e.g additional information),
/// postal/zip code (%6$s), city (%7$s), state (%8$s), country ID (%9$s),
/// e-mail (%10$s), phone (%11$s), facsimile/telefax (%12$s), web site (%13$s)
$context->getI18n()->dt( 'mshop', '%1$s
/// Supplier address format with label (%1$s), company (%2$s),
/// address part one (%3$s, e.g street), address part two (%4$s, e.g house number), address part three (%5$s, e.g additional information),
/// postal/zip code (%6$s), city (%7$s), state (%8$s), country ID (%9$s),
/// e-mail (%10$s), phone (%11$s), facsimile/telefax (%12$s), web site (%13$s)
$format = $this->getConfigValue( 'supplier.addressformat', '%1$s
%2$s
%3$s %4$s
%5$s
Expand All @@ -79,28 +99,10 @@ public function __construct( \Aimeos\MShop\Service\Provider\Iface $provider,
%11$s
%12$s
%13$s'
),
$item->getLabel(),
$addr->getCompany(),
$addr->getAddress1(),
$addr->getAddress2(),
$addr->getAddress3(),
$addr->getPostal(),
$addr->getCity(),
$addr->getState(),
$addr->getCountryId(),
$addr->getEmail(),
$addr->getTelephone(),
$addr->getTelefax(),
$addr->getWebsite()
) ) );
);

$this->feConfig['supplier.code']['short'][$addrId] = trim( preg_replace( "/\n+/m", "\n", sprintf(
/// Supplier address format with label (%1$s), company (%2$s),
/// address part one (%3$s, e.g street), address part two (%4$s, e.g house number), address part three (%5$s, e.g additional information),
/// postal/zip code (%6$s), city (%7$s), state (%8$s), country ID (%9$s),
/// e-mail (%10$s), phone (%11$s), facsimile/telefax (%12$s), web site (%13$s)
$context->getI18n()->dt( 'mshop', '%1$s, %2$s, %3$s %4$s, %6$s %7$s' ),
$this->feConfig['supplier.code']['default'][$addrId] = trim( preg_replace( "/\n+/m", "\n", sprintf(
$context->getI18n()->dt( 'mshop', $format ),
$item->getLabel(),
$addr->getCompany(),
$addr->getAddress1(),
Expand All @@ -115,10 +117,37 @@ public function __construct( \Aimeos\MShop\Service\Provider\Iface $provider,
$addr->getTelefax(),
$addr->getWebsite()
) ) );

}
}
}

/**
* Checks the backend configuration attributes for validity.
*
* @param array $attributes Attributes added by the shop owner in the administraton interface
* @return array An array with the attribute keys as key and an error message as values for all attributes that are
* known by the provider but aren't valid
*/
public function checkConfigBE( array $attributes ) : array
{
$error = $this->getProvider()->checkConfigBE( $attributes );
$error += $this->checkConfig( $this->beConfig, $attributes );

return $error;
}


/**
* Returns the configuration attribute definitions of the provider to generate a list of available fields and
* rules for the value of each field in the administration interface.
*
* @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface
*/
public function getConfigBE() : array
{
return array_merge( $this->getProvider()->getConfigBE(), $this->getConfigItems( $this->beConfig ) );
}

/**
* Checks the frontend configuration attributes for validity.
Expand Down Expand Up @@ -179,7 +208,7 @@ public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderS
if( ( $code = $attributes['supplier.code'] ) != '' )
{
// add short address as attribute for summary page / customer email
$attributes['supplier.address'] = $this->feConfig['supplier.code']['short'][$code];
$attributes['supplier.address'] = $this->feConfig['supplier.code']['default'][$code];

// remove code attribute for summary page / customer email
$this->setAttributes( $orderServiceItem, ['supplier.code' => $attributes['supplier.code']], 'hidden' );
Expand Down