|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / app / code / Mrgig / MV / Model / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/code/Mrgig/MV/Model/Customer.php |
Size | 7.21 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 02-Apr-2022 12:20 |
Last accessed | 23-Aug-2025 04:50 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace Mrgig\MV\Model;
use Mrgig\MV\Helper\Data as DataHelper;
use Mrgig\MV\Helper\Api as ApiHelper;
use Mrgig\MV\Logger\Logger;
class Customer
{
protected $listInvalidProperties;
protected $container;
public function __construct(
DataHelper $dataHelper,
ApiHelper $apiHelper,
Logger $logger
) {
$this->dataHelper = $dataHelper;
$this->apiHelper = $apiHelper;
$this->logger = $logger;
}
public function createCustomer($order, $invoiceId)
{
$customerGroupIds = $this->dataHelper->getCustomerGroupId();
$customerId = $order->getCustomerId();
$customerGroupId = $order->getCustomerGroupId();
$shippingAddress = $order->getShippingAddress();
if(empty($shippingAddress)) {
$shippingAddress = $order->getBillingAddress();
}
$countryId = $shippingAddress->getCountryId();
if($countryId == 'NL') {
$countryId = null;
}
if($order->getCustomerIsGuest() == 1) {
$customerId = $order->getIncrementId();
}
if(!empty($customerGroupIds) && in_array($customerGroupId, $customerGroupIds)) {
$vatScenarioId = 7;
} else {
$taxId = $this->dataHelper->getTaxIdArrayMapping($shippingAddress->getCountryId());
$vatScenarioId = $this->getVatScenarioId($taxId);
}
$name = $shippingAddress->getFirstname().' '.$shippingAddress->getLastname();
$street = $shippingAddress->getStreet();
$this->container['city'] = $shippingAddress->getCity();
$this->container['countryId'] = $countryId;
$this->container['customerId'] = $customerId;
$this->container['email'] = $order->getCustomerEmail();
$this->container['fax'] = $shippingAddress->getFax();
$this->container['name'] = $this->getName($name);
$this->container['shortName'] = $this->getShortName($shippingAddress);
$this->container['street1'] = isset($street['0']) ? $street['0'] : null;
$this->container['street2'] = isset($street['1']) ? $street['1'] : null;
$this->container['telephone'] = $shippingAddress->getTelephone();
$this->container['zipCode'] = $shippingAddress->getPostcode();
$this->container['vatNumber'] = $shippingAddress->getVatId();
$this->container['vatScenarioId'] = $vatScenarioId;
$valid = $this->listInvalidProperties();
if(!empty($valid) && count($valid) > 0) {
$message = sprintf(
'Invalid the required parameter when calling createCustomer:%s. %s',
$order->getCustomerId(),
implode(', ', $valid)
);
$this->logger->addError($message);
$this->dataHelper->addComment($message, $invoiceId);
return null;
}
return $this->container;
}
public function getShortName($order)
{
$shortName = $order->getFirstname();
return (strlen($shortName) > 8) ? substr($shortName,0,8) : $shortName;
}
public function getName($name)
{
return (strlen($name) > 40) ? substr($name,0,40) : $name;
}
public function getVatScenarioId($vatCodeId)
{
$vatScenarioRuleInfoList = $this->apiHelper->getVatScenarioRuleInfoList();
if(!empty($vatScenarioRuleInfoList)) {
foreach($vatScenarioRuleInfoList as $vatScenarioRule) {
if(isset($vatScenarioRule['vatCodeId']) && $vatScenarioRule['vatCodeId'] == $vatCodeId) {
if(isset($vatScenarioRule['vatScenarioId']) && !empty($vatScenarioRule['vatScenarioId'])){
return $vatScenarioRule['vatScenarioId'];
}
}
}
}
}
public function listInvalidProperties()
{
$invalidProperties = [];
if (!is_null($this->container['city']) && (mb_strlen($this->container['city']) > 30)) {
$city = $this->container['city'];
$this->container['city'] = substr($city, 0, 30);
//$invalidProperties[] = "invalid value for 'city', the character length must be smaller than or equal to 30.";
}
if (!is_null($this->container['countryId']) && (mb_strlen($this->container['countryId']) > 3)) {
$invalidProperties[] = "invalid value for 'countryId', the character length must be smaller than or equal to 3.";
}
if (!is_null($this->container['customerId']) && (mb_strlen($this->container['customerId']) > 8)) {
$customerId = $this->container['customerId'];
$this->container['customerId'] = substr($customerId, 3, 10);
//$invalidProperties[] = "invalid value for 'customerId', the character length must be smaller than or equal to 8.";
}
if (!is_null($this->container['email']) && (mb_strlen($this->container['email']) > 60)) {
$invalidProperties[] = "invalid value for 'email', the character length must be smaller than or equal to 60.";
}
if (!is_null($this->container['fax']) && (mb_strlen($this->container['fax']) > 25)) {
$invalidProperties[] = "invalid value for 'fax', the character length must be smaller than or equal to 25.";
}
if (!is_null($this->container['name']) && (mb_strlen($this->container['name']) > 40)) {
$invalidProperties[] = "invalid value for 'name', the character length must be smaller than or equal to 40.";
}
if ($this->container['shortName'] === null) {
$invalidProperties[] = "'shortName' can't be null";
}
if ((mb_strlen($this->container['shortName']) > 8)) {
$invalidProperties[] = "invalid value for 'shortName', the character length must be smaller than or equal to 8.";
}
if (!is_null($this->container['street1']) && (mb_strlen($this->container['street1']) > 40)) {
$street1 = $this->container['street1'];
$this->container['street1'] = substr($street1, 0, 40);
//$invalidProperties[] = "invalid value for 'street1', the character length must be smaller than or equal to 40.";
}
if (!is_null($this->container['street2']) && (mb_strlen($this->container['street2']) > 40)) {
$street2 = $this->container['street2'];
$this->container['street2'] = substr($street2, 0, 40);
//$invalidProperties[] = "invalid value for 'street2', the character length must be smaller than or equal to 40.";
}
if (!is_null($this->container['telephone']) && (mb_strlen($this->container['telephone']) > 25)) {
$invalidProperties[] = "invalid value for 'telephone', the character length must be smaller than or equal to 25.";
}
if (!is_null($this->container['zipCode']) && (mb_strlen($this->container['zipCode']) > 10)) {
$zipCode = $this->container['zipCode'];
$this->container['zipCode'] = substr($zipCode, 0, 10);
//$invalidProperties[] = "invalid value for 'zipCode', the character length must be smaller than or equal to 10.";
}
if (!is_null($this->container['vatNumber']) && (mb_strlen($this->container['vatNumber']) > 30)) {
$invalidProperties[] = "invalid value for 'vatNumber', the character length must be smaller than or equal to 30.";
}
return $invalidProperties;
}
}
namespace Mrgig\MV\Model;
use Mrgig\MV\Helper\Data as DataHelper;
use Mrgig\MV\Helper\Api as ApiHelper;
use Mrgig\MV\Logger\Logger;
class Customer
{
protected $listInvalidProperties;
protected $container;
public function __construct(
DataHelper $dataHelper,
ApiHelper $apiHelper,
Logger $logger
) {
$this->dataHelper = $dataHelper;
$this->apiHelper = $apiHelper;
$this->logger = $logger;
}
public function createCustomer($order, $invoiceId)
{
$customerGroupIds = $this->dataHelper->getCustomerGroupId();
$customerId = $order->getCustomerId();
$customerGroupId = $order->getCustomerGroupId();
$shippingAddress = $order->getShippingAddress();
if(empty($shippingAddress)) {
$shippingAddress = $order->getBillingAddress();
}
$countryId = $shippingAddress->getCountryId();
if($countryId == 'NL') {
$countryId = null;
}
if($order->getCustomerIsGuest() == 1) {
$customerId = $order->getIncrementId();
}
if(!empty($customerGroupIds) && in_array($customerGroupId, $customerGroupIds)) {
$vatScenarioId = 7;
} else {
$taxId = $this->dataHelper->getTaxIdArrayMapping($shippingAddress->getCountryId());
$vatScenarioId = $this->getVatScenarioId($taxId);
}
$name = $shippingAddress->getFirstname().' '.$shippingAddress->getLastname();
$street = $shippingAddress->getStreet();
$this->container['city'] = $shippingAddress->getCity();
$this->container['countryId'] = $countryId;
$this->container['customerId'] = $customerId;
$this->container['email'] = $order->getCustomerEmail();
$this->container['fax'] = $shippingAddress->getFax();
$this->container['name'] = $this->getName($name);
$this->container['shortName'] = $this->getShortName($shippingAddress);
$this->container['street1'] = isset($street['0']) ? $street['0'] : null;
$this->container['street2'] = isset($street['1']) ? $street['1'] : null;
$this->container['telephone'] = $shippingAddress->getTelephone();
$this->container['zipCode'] = $shippingAddress->getPostcode();
$this->container['vatNumber'] = $shippingAddress->getVatId();
$this->container['vatScenarioId'] = $vatScenarioId;
$valid = $this->listInvalidProperties();
if(!empty($valid) && count($valid) > 0) {
$message = sprintf(
'Invalid the required parameter when calling createCustomer:%s. %s',
$order->getCustomerId(),
implode(', ', $valid)
);
$this->logger->addError($message);
$this->dataHelper->addComment($message, $invoiceId);
return null;
}
return $this->container;
}
public function getShortName($order)
{
$shortName = $order->getFirstname();
return (strlen($shortName) > 8) ? substr($shortName,0,8) : $shortName;
}
public function getName($name)
{
return (strlen($name) > 40) ? substr($name,0,40) : $name;
}
public function getVatScenarioId($vatCodeId)
{
$vatScenarioRuleInfoList = $this->apiHelper->getVatScenarioRuleInfoList();
if(!empty($vatScenarioRuleInfoList)) {
foreach($vatScenarioRuleInfoList as $vatScenarioRule) {
if(isset($vatScenarioRule['vatCodeId']) && $vatScenarioRule['vatCodeId'] == $vatCodeId) {
if(isset($vatScenarioRule['vatScenarioId']) && !empty($vatScenarioRule['vatScenarioId'])){
return $vatScenarioRule['vatScenarioId'];
}
}
}
}
}
public function listInvalidProperties()
{
$invalidProperties = [];
if (!is_null($this->container['city']) && (mb_strlen($this->container['city']) > 30)) {
$city = $this->container['city'];
$this->container['city'] = substr($city, 0, 30);
//$invalidProperties[] = "invalid value for 'city', the character length must be smaller than or equal to 30.";
}
if (!is_null($this->container['countryId']) && (mb_strlen($this->container['countryId']) > 3)) {
$invalidProperties[] = "invalid value for 'countryId', the character length must be smaller than or equal to 3.";
}
if (!is_null($this->container['customerId']) && (mb_strlen($this->container['customerId']) > 8)) {
$customerId = $this->container['customerId'];
$this->container['customerId'] = substr($customerId, 3, 10);
//$invalidProperties[] = "invalid value for 'customerId', the character length must be smaller than or equal to 8.";
}
if (!is_null($this->container['email']) && (mb_strlen($this->container['email']) > 60)) {
$invalidProperties[] = "invalid value for 'email', the character length must be smaller than or equal to 60.";
}
if (!is_null($this->container['fax']) && (mb_strlen($this->container['fax']) > 25)) {
$invalidProperties[] = "invalid value for 'fax', the character length must be smaller than or equal to 25.";
}
if (!is_null($this->container['name']) && (mb_strlen($this->container['name']) > 40)) {
$invalidProperties[] = "invalid value for 'name', the character length must be smaller than or equal to 40.";
}
if ($this->container['shortName'] === null) {
$invalidProperties[] = "'shortName' can't be null";
}
if ((mb_strlen($this->container['shortName']) > 8)) {
$invalidProperties[] = "invalid value for 'shortName', the character length must be smaller than or equal to 8.";
}
if (!is_null($this->container['street1']) && (mb_strlen($this->container['street1']) > 40)) {
$street1 = $this->container['street1'];
$this->container['street1'] = substr($street1, 0, 40);
//$invalidProperties[] = "invalid value for 'street1', the character length must be smaller than or equal to 40.";
}
if (!is_null($this->container['street2']) && (mb_strlen($this->container['street2']) > 40)) {
$street2 = $this->container['street2'];
$this->container['street2'] = substr($street2, 0, 40);
//$invalidProperties[] = "invalid value for 'street2', the character length must be smaller than or equal to 40.";
}
if (!is_null($this->container['telephone']) && (mb_strlen($this->container['telephone']) > 25)) {
$invalidProperties[] = "invalid value for 'telephone', the character length must be smaller than or equal to 25.";
}
if (!is_null($this->container['zipCode']) && (mb_strlen($this->container['zipCode']) > 10)) {
$zipCode = $this->container['zipCode'];
$this->container['zipCode'] = substr($zipCode, 0, 10);
//$invalidProperties[] = "invalid value for 'zipCode', the character length must be smaller than or equal to 10.";
}
if (!is_null($this->container['vatNumber']) && (mb_strlen($this->container['vatNumber']) > 30)) {
$invalidProperties[] = "invalid value for 'vatNumber', the character length must be smaller than or equal to 30.";
}
return $invalidProperties;
}
}