2022-07-04 13:28:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Linkmobility4OXID\Application\Model;
|
|
|
|
|
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
|
|
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Country;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
|
|
|
|
class OrderRecipients
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Order
|
|
|
|
*/
|
|
|
|
private $order;
|
|
|
|
|
|
|
|
public function __construct(Order $order)
|
|
|
|
{
|
|
|
|
$this->order = $order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Recipient
|
|
|
|
* @throws noRecipientFoundException
|
|
|
|
*/
|
|
|
|
public function getSmsRecipient(): Recipient
|
|
|
|
{
|
2022-07-08 09:49:39 +02:00
|
|
|
foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName)
|
2022-07-04 13:28:58 +02:00
|
|
|
{
|
2022-07-08 09:49:39 +02:00
|
|
|
$content = trim($this->order->getFieldData($phoneFieldName));
|
2022-07-04 13:28:58 +02:00
|
|
|
|
2022-07-08 09:49:39 +02:00
|
|
|
if (strlen($content)) {
|
2022-07-04 13:28:58 +02:00
|
|
|
$country = oxNew(Country::class);
|
2022-07-08 09:49:39 +02:00
|
|
|
$country->load($this->order->getFieldData($countryIdFieldName));
|
2022-07-04 13:28:58 +02:00
|
|
|
|
|
|
|
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw oxNew(noRecipientFoundException::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getSmsRecipientFields(): array
|
|
|
|
{
|
|
|
|
return [
|
2022-07-08 09:49:39 +02:00
|
|
|
'oxdelfon' => 'oxdelcountryid',
|
|
|
|
'oxbillfon' => 'oxbillcountryid'
|
2022-07-04 13:28:58 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|