[11/05/2025] On remplace les modules Colissimo par le combo ColissimoHomeDelivery + ColissimoPickupPoint + ColissimoLabel
This commit is contained in:
132
local/modules/ColissimoLabel/Request/AbstractLabelRequest.php
Normal file
132
local/modules/ColissimoLabel/Request/AbstractLabelRequest.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request;
|
||||
|
||||
use ColissimoLabel\ColissimoLabel;
|
||||
use ColissimoLabel\Request\Helper\Letter;
|
||||
use ColissimoLabel\Request\Helper\OutputFormat;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
abstract class AbstractLabelRequest extends AbstractRequest
|
||||
{
|
||||
/** @var OutputFormat|null */
|
||||
private $outputFormat;
|
||||
|
||||
/** @var Letter */
|
||||
private $letter;
|
||||
|
||||
/**
|
||||
* @return OutputFormat|null
|
||||
*/
|
||||
public function getOutputFormat()
|
||||
{
|
||||
return $this->outputFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormat $outputFormat
|
||||
* @return self
|
||||
*/
|
||||
protected function setOutputFormat(OutputFormat $outputFormat)
|
||||
{
|
||||
$this->outputFormat = $outputFormat;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Letter
|
||||
*/
|
||||
public function getLetter()
|
||||
{
|
||||
return $this->letter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Letter $letter
|
||||
* @return self
|
||||
*/
|
||||
protected function setLetter(Letter $letter)
|
||||
{
|
||||
$this->letter = $letter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function generateArrayRequest()
|
||||
{
|
||||
return array_merge_recursive(parent::generateArrayRequest(), [
|
||||
'outputFormat' => [
|
||||
'x' => $this->getOutputFormat()->getX(),
|
||||
'y' => $this->getOutputFormat()->getY(),
|
||||
'outputPrintingType' => $this->getOutputFormat()->getOutputPrintingType()
|
||||
],
|
||||
'letter' => [
|
||||
'service' => [
|
||||
'productCode' => $this->getLetter()->getService()->getProductCode(),
|
||||
'depositDate' => $this->getLetter()->getService()->getDepositDate()->format('Y-m-d'),
|
||||
'transportationAmount' => $this->getLetter()->getService()->getTransportationAmount(),
|
||||
'totalAmount' => $this->getLetter()->getService()->getTransportationAmount(),
|
||||
'orderNumber' => $this->getLetter()->getService()->getOrderNumber(),
|
||||
'commercialName' => $this->getLetter()->getService()->getCommercialName(),
|
||||
'returnTypeChoice' => $this->getLetter()->getService()->getReturnTypeChoice(),
|
||||
],
|
||||
'parcel' => [
|
||||
'weight' => $this->getLetter()->getParcel()->getWeight(),
|
||||
'pickupLocationId' => $this->getLetter()->getParcel()->getPickupLocationId()
|
||||
],
|
||||
'customsDeclarations' => [
|
||||
'includeCustomsDeclarations' => $this->getLetter()->getCustomsDeclarations()->getIncludeCustomsDeclarations(),
|
||||
'contents' => [
|
||||
'article' => 'falseArticle',
|
||||
'category' => [
|
||||
'value' => $this->getLetter()->getCustomsDeclarations()->getCategory(),
|
||||
]
|
||||
]
|
||||
|
||||
],
|
||||
'sender' => [
|
||||
'senderParcelRef' => $this->getLetter()->getSender()->getSenderParcelRef(),
|
||||
'address' => [
|
||||
'companyName' => $this->getLetter()->getSender()->getAddress()->getCompanyName(),
|
||||
'lastName' => $this->getLetter()->getSender()->getAddress()->getLastName(),
|
||||
'firstName' => $this->getLetter()->getSender()->getAddress()->getFirstName(),
|
||||
'line0' => $this->getLetter()->getSender()->getAddress()->getLine0(),
|
||||
'line1' => $this->getLetter()->getSender()->getAddress()->getLine1(),
|
||||
'line2' => $this->getLetter()->getSender()->getAddress()->getLine2(),
|
||||
'line3' => $this->getLetter()->getSender()->getAddress()->getLine3(),
|
||||
'countryCode' => $this->getLetter()->getSender()->getAddress()->getCountryCode(),
|
||||
'city' => $this->getLetter()->getSender()->getAddress()->getCity(),
|
||||
'zipCode' => $this->getLetter()->getSender()->getAddress()->getZipCode(),
|
||||
'phoneNumber' => $this->getLetter()->getSender()->getAddress()->getPhoneNumber(),
|
||||
'mobileNumber' => $this->getLetter()->getSender()->getAddress()->getMobileNumber(),
|
||||
'email'=> $this->getLetter()->getSender()->getAddress()->getEmail(),
|
||||
'language' => $this->getLetter()->getSender()->getAddress()->getLanguage()
|
||||
]
|
||||
],
|
||||
'addressee' => [
|
||||
'addresseeParcelRef' => $this->getLetter()->getAddressee()->getAddresseeParcelRef(),
|
||||
'address' => [
|
||||
'companyName' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getCompanyName()),
|
||||
'lastName' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getLastName()),
|
||||
'firstName' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getFirstName()),
|
||||
'line0' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getLine0()),
|
||||
'line1' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getLine1()),
|
||||
'line2' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getLine2()),
|
||||
'line3' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getLine3()),
|
||||
'countryCode' => $this->getLetter()->getAddressee()->getAddress()->getCountryCode(),
|
||||
'city' => ColissimoLabel::removeAccents($this->getLetter()->getAddressee()->getAddress()->getCity()),
|
||||
'zipCode' => $this->getLetter()->getAddressee()->getAddress()->getZipCode(),
|
||||
'phoneNumber' => $this->getLetter()->getAddressee()->getAddress()->getPhoneNumber(),
|
||||
'mobileNumber' => $this->getLetter()->getAddressee()->getAddress()->getMobileNumber(),
|
||||
'email'=> $this->getLetter()->getAddressee()->getAddress()->getEmail(),
|
||||
'language' => $this->getLetter()->getAddressee()->getAddress()->getLanguage()
|
||||
]
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
57
local/modules/ColissimoLabel/Request/AbstractRequest.php
Normal file
57
local/modules/ColissimoLabel/Request/AbstractRequest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
abstract class AbstractRequest
|
||||
{
|
||||
protected $contractNumber = '';
|
||||
|
||||
protected $password = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContractNumber()
|
||||
{
|
||||
return $this->contractNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $contractNumber
|
||||
* @return self
|
||||
*/
|
||||
public function setContractNumber($contractNumber)
|
||||
{
|
||||
$this->contractNumber = $contractNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return self
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function generateArrayRequest()
|
||||
{
|
||||
return [
|
||||
'contractNumber' => $this->getContractNumber(),
|
||||
'password' => $this->getPassword()
|
||||
];
|
||||
}
|
||||
}
|
||||
119
local/modules/ColissimoLabel/Request/Helper/APIConfiguration.php
Normal file
119
local/modules/ColissimoLabel/Request/Helper/APIConfiguration.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
use ColissimoLabel\ColissimoLabel;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
abstract class APIConfiguration
|
||||
{
|
||||
protected $contractNumber = '';
|
||||
|
||||
protected $password = '';
|
||||
|
||||
protected $version = '2.0';
|
||||
|
||||
protected $wsdl = '';
|
||||
|
||||
protected $method = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setContractNumber(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_CONTRACT_NUMBER));
|
||||
$this->setPassword(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_PASSWORD));
|
||||
$this->setWsdl(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_ENDPOINT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContractNumber()
|
||||
{
|
||||
return $this->contractNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $contractNumber
|
||||
* @return self
|
||||
*/
|
||||
public function setContractNumber($contractNumber)
|
||||
{
|
||||
$this->contractNumber = $contractNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return self
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
* @return self
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWsdl()
|
||||
{
|
||||
return $this->wsdl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $wsdl
|
||||
* @return self
|
||||
*/
|
||||
public function setWsdl($wsdl)
|
||||
{
|
||||
$this->wsdl = $wsdl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return self
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
289
local/modules/ColissimoLabel/Request/Helper/Address.php
Normal file
289
local/modules/ColissimoLabel/Request/Helper/Address.php
Normal file
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Address
|
||||
{
|
||||
protected $companyName ='';
|
||||
|
||||
protected $lastName = '';
|
||||
|
||||
protected $firstName = '';
|
||||
|
||||
protected $line0 = '';
|
||||
|
||||
protected $line1 = '';
|
||||
|
||||
protected $line2 = '';
|
||||
|
||||
protected $line3 = '';
|
||||
|
||||
protected $countryCode = '';
|
||||
|
||||
protected $city = '';
|
||||
|
||||
protected $zipCode = '';
|
||||
|
||||
protected $phoneNumber = '';
|
||||
|
||||
protected $mobileNumber = '';
|
||||
|
||||
protected $email = '';
|
||||
|
||||
protected $language = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $language
|
||||
* @return Address
|
||||
*/
|
||||
public function setLanguage($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPhoneNumber()
|
||||
{
|
||||
return $this->phoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phoneNumber
|
||||
* @return Address
|
||||
*/
|
||||
public function setPhoneNumber($phoneNumber)
|
||||
{
|
||||
$this->phoneNumber = $phoneNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMobileNumber()
|
||||
{
|
||||
return $this->mobileNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mobileNumber
|
||||
* @return Address
|
||||
*/
|
||||
public function setMobileNumber($mobileNumber)
|
||||
{
|
||||
$this->mobileNumber = $mobileNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return Address
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCompanyName()
|
||||
{
|
||||
return $this->companyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $companyName
|
||||
* @return self
|
||||
*/
|
||||
public function setCompanyName($companyName)
|
||||
{
|
||||
$this->companyName = $companyName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $lastName
|
||||
* @return self
|
||||
*/
|
||||
public function setLastName($lastName)
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $firstName
|
||||
* @return self
|
||||
*/
|
||||
public function setFirstName($firstName)
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLine0()
|
||||
{
|
||||
return $this->line0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line0
|
||||
* @return self
|
||||
*/
|
||||
public function setLine0($line0)
|
||||
{
|
||||
$this->line0 = $line0;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLine1()
|
||||
{
|
||||
return $this->line1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line1
|
||||
* @return self
|
||||
*/
|
||||
public function setLine1($line1)
|
||||
{
|
||||
$this->line1 = $line1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLine2()
|
||||
{
|
||||
return $this->line2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line2
|
||||
* @return self
|
||||
*/
|
||||
public function setLine2($line2)
|
||||
{
|
||||
$this->line2 = $line2;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLine3()
|
||||
{
|
||||
return $this->line3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line3
|
||||
* @return self
|
||||
*/
|
||||
public function setLine3($line3)
|
||||
{
|
||||
$this->line3 = $line3;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCountryCode()
|
||||
{
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $countryCode
|
||||
* @return self
|
||||
*/
|
||||
public function setCountryCode($countryCode)
|
||||
{
|
||||
$this->countryCode = $countryCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $city
|
||||
* @return self
|
||||
*/
|
||||
public function setCity($city)
|
||||
{
|
||||
$this->city = $city;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getZipCode()
|
||||
{
|
||||
return $this->zipCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $zipCode
|
||||
* @return self
|
||||
*/
|
||||
public function setZipCode($zipCode)
|
||||
{
|
||||
$this->zipCode = $zipCode;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
44
local/modules/ColissimoLabel/Request/Helper/Addressee.php
Normal file
44
local/modules/ColissimoLabel/Request/Helper/Addressee.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Addressee
|
||||
{
|
||||
/** @var string */
|
||||
protected $addresseeParcelRef;
|
||||
|
||||
/** @var Address */
|
||||
protected $address;
|
||||
|
||||
public function __construct(Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddresseeParcelRef()
|
||||
{
|
||||
return $this->addresseeParcelRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $addresseeParcelRef
|
||||
*/
|
||||
public function setAddresseeParcelRef($addresseeParcelRef)
|
||||
{
|
||||
$this->addresseeParcelRef = $addresseeParcelRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
}
|
||||
161
local/modules/ColissimoLabel/Request/Helper/Article.php
Normal file
161
local/modules/ColissimoLabel/Request/Helper/Article.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
|
||||
use ColissimoLabel\ColissimoLabel;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\Order;
|
||||
|
||||
class Article
|
||||
{
|
||||
protected $description = '';
|
||||
|
||||
protected $quantity = 0;
|
||||
|
||||
protected $weight = 0;
|
||||
|
||||
protected $value = 0;
|
||||
|
||||
protected $hsCode = '';
|
||||
|
||||
protected $currency = 'EUR';
|
||||
|
||||
protected $authorizedCurrencies = [
|
||||
'USD',
|
||||
'EUR',
|
||||
'CHF',
|
||||
'GBP',
|
||||
'CNY',
|
||||
'JPY',
|
||||
'CAD',
|
||||
'AUD',
|
||||
'HKD',
|
||||
];
|
||||
|
||||
public function __construct($description, $quantity, $weight, $value, $hsCode, $currency)
|
||||
{
|
||||
|
||||
$this->description = $description;
|
||||
$this->quantity = $quantity;
|
||||
$this->weight = (float) $weight;
|
||||
$this->value = (float) $value;
|
||||
$this->hsCode = $hsCode;
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return \Transliterator::create('NFD; [:Nonspacing Mark:] Remove; NFC')->transliterate($this->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $description
|
||||
* @return $this
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $quantity
|
||||
* @return $this
|
||||
*/
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
public function getWeight()
|
||||
{
|
||||
return $this->weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|int $weight
|
||||
* @return self
|
||||
*/
|
||||
public function setWeight($weight)
|
||||
{
|
||||
$this->weight = $weight;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHsCode()
|
||||
{
|
||||
return $this->hsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $hsCode
|
||||
* @return $this
|
||||
*/
|
||||
public function setHsCode($hsCode)
|
||||
{
|
||||
$this->hsCode = $hsCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOriginCountry() {
|
||||
return CountryQuery::create()->findOneById(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_COUNTRY))->getIsoalpha2();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency
|
||||
* @return $this
|
||||
*/
|
||||
public function setCurrency($currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency() {
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class BordereauRequestAPIConfiguration extends APIConfiguration
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->setMethod('generateBordereauByParcelsNumbers');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
|
||||
class CustomsDeclarations
|
||||
{
|
||||
protected $includeCustomsDeclarations = false;
|
||||
|
||||
protected $articles = [];
|
||||
|
||||
protected $category = 3;
|
||||
|
||||
public function __construct($includeCustomsDeclarations, $category, $articles)
|
||||
{
|
||||
$this->includeCustomsDeclarations = $includeCustomsDeclarations;
|
||||
$this->category = $category;
|
||||
$this->articles = $articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getIncludeCustomsDeclarations()
|
||||
{
|
||||
if (!$this->includeCustomsDeclarations) {
|
||||
return 'false';
|
||||
}
|
||||
return $this->includeCustomsDeclarations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $includeCustomsDeclarations
|
||||
* @return $this
|
||||
*/
|
||||
public function setIncludeCustomsDeclarations($includeCustomsDeclarations)
|
||||
{
|
||||
$this->includeCustomsDeclarations = $includeCustomsDeclarations;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $category
|
||||
* @return $this
|
||||
*/
|
||||
public function setCategory($category)
|
||||
{
|
||||
$this->category = $category;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArticles()
|
||||
{
|
||||
return $this->articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $articles
|
||||
* @return $this
|
||||
*/
|
||||
public function setArticles($articles)
|
||||
{
|
||||
$this->articles[] = $articles;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class LabelRequestAPIConfiguration extends APIConfiguration
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->setMethod('generateLabel');
|
||||
}
|
||||
}
|
||||
78
local/modules/ColissimoLabel/Request/Helper/Letter.php
Normal file
78
local/modules/ColissimoLabel/Request/Helper/Letter.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Letter
|
||||
{
|
||||
/** @var Sender */
|
||||
protected $sender;
|
||||
|
||||
/** @var Addressee */
|
||||
protected $addressee;
|
||||
|
||||
/** @var Parcel */
|
||||
protected $parcel;
|
||||
|
||||
/** @var Service */
|
||||
protected $service;
|
||||
|
||||
/** @var CustomsDeclarations */
|
||||
protected $customsDeclarations;
|
||||
|
||||
public function __construct(
|
||||
Service $service,
|
||||
Sender $sender,
|
||||
Addressee $addressee,
|
||||
Parcel $parcel,
|
||||
CustomsDeclarations $customsDeclarations
|
||||
) {
|
||||
$this->sender = $sender;
|
||||
$this->addressee = $addressee;
|
||||
$this->parcel = $parcel;
|
||||
$this->service = $service;
|
||||
$this->customsDeclarations = $customsDeclarations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Service
|
||||
*/
|
||||
public function getService()
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Sender
|
||||
*/
|
||||
public function getSender()
|
||||
{
|
||||
return $this->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Addressee
|
||||
*/
|
||||
public function getAddressee()
|
||||
{
|
||||
return $this->addressee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Parcel
|
||||
*/
|
||||
public function getParcel()
|
||||
{
|
||||
return $this->parcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CustomsDeclarations
|
||||
*/
|
||||
public function getCustomsDeclarations()
|
||||
{
|
||||
return $this->customsDeclarations;
|
||||
}
|
||||
}
|
||||
87
local/modules/ColissimoLabel/Request/Helper/OutputFormat.php
Normal file
87
local/modules/ColissimoLabel/Request/Helper/OutputFormat.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
use ColissimoLabel\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class OutputFormat
|
||||
{
|
||||
const OUTPUT_PRINTING_TYPE = [
|
||||
0 => 'ZPL_10x15_203dpi',
|
||||
1 => 'ZPL_10x15_300dpi',
|
||||
2 => 'DPL_10x15_203dpi',
|
||||
3 => 'DPL_10x15_300dpi',
|
||||
4 => 'PDF_10x15_300dpi',
|
||||
5 => 'PDF_A4_300dpi'
|
||||
];
|
||||
|
||||
/** Default label format is : PDF_10x15_300dpi */
|
||||
const OUTPUT_PRINTING_TYPE_DEFAULT = 4;
|
||||
|
||||
protected $x = 0;
|
||||
|
||||
protected $y = 0;
|
||||
|
||||
protected $outputPrintingType = self::OUTPUT_PRINTING_TYPE_DEFAULT;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getX()
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @return self
|
||||
*/
|
||||
public function setX($x)
|
||||
{
|
||||
$this->x = (int) $x;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getY()
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $y
|
||||
* @return self
|
||||
*/
|
||||
public function setY($y)
|
||||
{
|
||||
$this->y = (int) $y;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string value of the list ColissimoAPI\Request\Helper\LabelOutputFormat::OUTPUT_PRINTING_TYPE
|
||||
*/
|
||||
public function getOutputPrintingType()
|
||||
{
|
||||
return $this->outputPrintingType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $outputPrintingType value of the list ColissimoAPI\Request\Helper\LabelOutputFormat::OUTPUT_PRINTING_TYPE
|
||||
* @return self
|
||||
*/
|
||||
public function setOutputPrintingType($outputPrintingType)
|
||||
{
|
||||
if (\in_array($outputPrintingType, self::OUTPUT_PRINTING_TYPE)) {
|
||||
new InvalidArgumentException('Invalid value "' . $outputPrintingType . '" for argument $outputPrintingType');
|
||||
}
|
||||
|
||||
$this->outputPrintingType = $outputPrintingType;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
94
local/modules/ColissimoLabel/Request/Helper/Parcel.php
Normal file
94
local/modules/ColissimoLabel/Request/Helper/Parcel.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Parcel
|
||||
{
|
||||
protected $weight = 0;
|
||||
|
||||
protected $signedDelivery = false;
|
||||
|
||||
protected $instructions = '';
|
||||
|
||||
protected $pickupLocationId;
|
||||
|
||||
public function __construct($weight)
|
||||
{
|
||||
$this->weight = (float) $weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWeight()
|
||||
{
|
||||
return $this->weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight
|
||||
* @return self
|
||||
*/
|
||||
public function setWeight($weight)
|
||||
{
|
||||
$this->weight = $weight;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getSignedDelivery()
|
||||
{
|
||||
return $this->signedDelivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $signedDelivery
|
||||
* @return self
|
||||
*/
|
||||
public function setSignedDelivery($signedDelivery)
|
||||
{
|
||||
$this->signedDelivery = $signedDelivery;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInstructions()
|
||||
{
|
||||
return $this->instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $instructions
|
||||
* @return self
|
||||
*/
|
||||
public function setInstructions($instructions)
|
||||
{
|
||||
$this->instructions = $instructions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPickupLocationId()
|
||||
{
|
||||
return $this->pickupLocationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pickupLocationId
|
||||
* @return self
|
||||
*/
|
||||
public function setPickupLocationId($pickupLocationId)
|
||||
{
|
||||
$this->pickupLocationId = $pickupLocationId;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
46
local/modules/ColissimoLabel/Request/Helper/Sender.php
Normal file
46
local/modules/ColissimoLabel/Request/Helper/Sender.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Sender
|
||||
{
|
||||
/** @var string */
|
||||
protected $senderParcelRef;
|
||||
|
||||
/** @var Address */
|
||||
protected $address;
|
||||
|
||||
public function __construct(Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderParcelRef()
|
||||
{
|
||||
return $this->senderParcelRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $senderParcelRef
|
||||
* @return self
|
||||
*/
|
||||
public function setSenderParcelRef($senderParcelRef)
|
||||
{
|
||||
$this->senderParcelRef = $senderParcelRef;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
}
|
||||
234
local/modules/ColissimoLabel/Request/Helper/Service.php
Normal file
234
local/modules/ColissimoLabel/Request/Helper/Service.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Helper;
|
||||
|
||||
use ColissimoLabel\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class Service
|
||||
{
|
||||
const PRODUCT_CODE_LIST = [
|
||||
0 => 'DOM',
|
||||
1 => 'COLD',
|
||||
2 => 'DOS',
|
||||
3 => 'COL',
|
||||
4 => 'BPR',
|
||||
5 => 'A2P',
|
||||
6 => 'CORE',
|
||||
7 => 'COLR',
|
||||
8 => 'J+1 ',
|
||||
9 => 'CORI',
|
||||
10 => 'COM',
|
||||
11 => 'CDS',
|
||||
12 => 'ECO',
|
||||
13 => 'CORI',
|
||||
14 => 'COLI',
|
||||
15 => 'ACCI',
|
||||
16 => 'CMT',
|
||||
17 => 'PCS',
|
||||
18 => 'DOM',
|
||||
19 => 'DOS',
|
||||
20 => 'BDP'
|
||||
];
|
||||
|
||||
const PRODUCT_CODE_LIST_COMMERCIAL_NAME = [
|
||||
0 => 'France Colissimo Domicile - sans signature',
|
||||
1 => 'France Colissimo Domicile - sans signature',
|
||||
2 => 'France Colissimo Domicile - avec signature',
|
||||
3 => 'France Colissimo Domicile - avec signature',
|
||||
4 => 'France Colissimo - Point Retrait – en Bureau de Poste ** ',
|
||||
5 => 'France Colissimo - Point Retrait – en relais Pickup ou en consigne Pickup Station',
|
||||
6 => 'France Colissimo Retour France',
|
||||
7 => 'France Colissimo Flash - sans signature',
|
||||
8 => 'Colissimo Flash – avec signature',
|
||||
9 => 'Colissimo Retour International ',
|
||||
10 => 'Outre-Mer Colissimo Domicile - sans signature ',
|
||||
11 => 'Outre-Mer Colissimo Domicile - avec signature',
|
||||
12 => 'Outre-Mer Colissimo Eco OM',
|
||||
13 => 'Outre-Mer Colissimo Retour OM',
|
||||
14 => 'International Colissimo Expert International',
|
||||
15 => 'International Offre Economique Grand Export (offre en test pour la Chine pour un client Pilote)',
|
||||
16 => 'International (Europe) Colissimo - Point Retrait – en relais ****',
|
||||
17 => 'International (Europe) Colissimo - Point Retrait – Consigne Pickup Station – Sauf France et Belgique',
|
||||
18 => 'International (Europe) Colissimo Domicile - sans signature ****',
|
||||
19 => 'International (Europe) Colissimo Domicile - avec signature ****',
|
||||
20 => 'International (Europe) Colissimo Point Retrait – en bureau de poste ****'
|
||||
];
|
||||
|
||||
const EUROPE_ISOCODES = [
|
||||
'040', /** Austria */
|
||||
'056', /** Belgium */
|
||||
'100', /** Bulgaria */
|
||||
'191', /** Croatia */
|
||||
'196', /** Cyprus */
|
||||
'203', /** Czech Republic */
|
||||
'208', /** Denmark */
|
||||
'233', /** Estonia */
|
||||
'246', /** Finland */
|
||||
'250', /** France */
|
||||
'276', /** Germany */
|
||||
'300', /** Greece */
|
||||
'348', /** Hungary */
|
||||
'352', /** Iceland */
|
||||
'372', /** Ireland */
|
||||
'380', /** Italy */
|
||||
'428', /** Latvia */
|
||||
'440', /** Lithuania */
|
||||
'442', /** Luxembourg */
|
||||
'470', /** Malta */
|
||||
'528', /** Netherlands */
|
||||
'578', /** Norway */
|
||||
'616', /** Poland */
|
||||
'620', /** Portugal */
|
||||
'642', /** Romania */
|
||||
'703', /** Slovakia */
|
||||
'705', /** Slovenia */
|
||||
'724', /** Spain */
|
||||
'752', /** Sweden */
|
||||
'756', /** Switzerland */
|
||||
'826', /** United Kingdom */
|
||||
];
|
||||
|
||||
const DOMTOM_ISOCODES = [
|
||||
'175', /** Mayotte */
|
||||
'254', /** Guyane Française */
|
||||
'258', /** Polynésie Française */
|
||||
'312', /** Guadeloupe */
|
||||
'474', /** Martinique */
|
||||
'540', /** Nouvelle-Calédonie */
|
||||
'638', /** Réunion(La) */
|
||||
'666', /** St Pierre et Miquelon */
|
||||
'876', /** Wallis et Futuna */
|
||||
];
|
||||
|
||||
protected $productCode = '';
|
||||
|
||||
/** @var \DateTime */
|
||||
protected $depositDate;
|
||||
|
||||
protected $orderNumber = '';
|
||||
|
||||
protected $commercialName = '';
|
||||
|
||||
protected $transportationAmount = '';
|
||||
|
||||
protected $returnTypeChoice = 3;
|
||||
|
||||
public function __construct($productCode, \DateTime $depositDate, $orderNumber, $transportationAmount, $returnTypeChoice)
|
||||
{
|
||||
if (empty($orderNumber)) {
|
||||
throw new InvalidArgumentException('Invalid argument orderNumber');
|
||||
}
|
||||
|
||||
if (empty($productCode)) {
|
||||
throw new InvalidArgumentException('Invalid argument productCode');
|
||||
}
|
||||
|
||||
$this->orderNumber = $orderNumber;
|
||||
$this->depositDate = $depositDate;
|
||||
$this->productCode = $productCode;
|
||||
$this->transportationAmount = $transportationAmount;
|
||||
$this->returnTypeChoice = $returnTypeChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProductCode()
|
||||
{
|
||||
return $this->productCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $productCode
|
||||
* @return $this
|
||||
*/
|
||||
public function setProductCode($productCode)
|
||||
{
|
||||
$this->productCode = $productCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDepositDate()
|
||||
{
|
||||
return $this->depositDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderNumber()
|
||||
{
|
||||
return $this->orderNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCommercialName()
|
||||
{
|
||||
return $this->commercialName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $commercialName
|
||||
* @return Service
|
||||
*/
|
||||
public function setCommercialName($commercialName)
|
||||
{
|
||||
$this->commercialName = $commercialName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTransportationAmount()
|
||||
{
|
||||
/** DO NOT use strict comparison here */
|
||||
if ($this->transportationAmount == 0) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
/** Formatting the postage price in a XXXX format (price in cents without separator), as requested by the Colissimo API */
|
||||
$nbr = number_format($this->transportationAmount, 2, '.', '');
|
||||
if ((float)$nbr < 10) {
|
||||
$nbr = '0' . $nbr;
|
||||
}
|
||||
return str_pad(str_replace('.', '', $nbr), 4, '0', STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $transportationAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setTransportationAmount($transportationAmount)
|
||||
{
|
||||
$this->transportationAmount = $transportationAmount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getReturnTypeChoice()
|
||||
{
|
||||
return $this->returnTypeChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $returnTypeChoice
|
||||
* @return $this
|
||||
*/
|
||||
public function setReturnTypeChoice($returnTypeChoice)
|
||||
{
|
||||
$this->returnTypeChoice = $returnTypeChoice;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
145
local/modules/ColissimoLabel/Request/LabelRequest.php
Normal file
145
local/modules/ColissimoLabel/Request/LabelRequest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request;
|
||||
|
||||
use ColissimoLabel\ColissimoLabel;
|
||||
use ColissimoLabel\Request\Helper\Addressee;
|
||||
use ColissimoLabel\Request\Helper\Article;
|
||||
use ColissimoLabel\Request\Helper\CustomsDeclarations;
|
||||
use ColissimoLabel\Request\Helper\Letter;
|
||||
use ColissimoLabel\Request\Helper\OutputFormat;
|
||||
use ColissimoLabel\Request\Helper\Parcel;
|
||||
use ColissimoLabel\Request\Helper\Sender;
|
||||
use ColissimoLabel\Request\Helper\Service;
|
||||
use ColissimoLabel\Request\Traits\MethodCreateAddressFromOrderAddress;
|
||||
use ColissimoLabel\Request\Traits\MethodCreateAddressFromStore;
|
||||
use DateTime;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Order;
|
||||
use Thelia\Model\OrderAddress;
|
||||
use Thelia\Model\OrderAddressQuery;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class LabelRequest extends AbstractLabelRequest
|
||||
{
|
||||
use MethodCreateAddressFromStore;
|
||||
use MethodCreateAddressFromOrderAddress;
|
||||
|
||||
public function __construct(Order $order, $pickupCode = null, $pickupType = null, $signedDelivery = false)
|
||||
{
|
||||
$orderAddress = OrderAddressQuery::create()->findOneById($order->getDeliveryOrderAddressId());
|
||||
|
||||
/**
|
||||
* If a pickup type was given (relay point delivery), we set the delivery code $productCode as this.
|
||||
* Otherwise, we check in getProductCode which delivery type is necessary given the delivery country and whether this
|
||||
* is a signed delivery or not, and set $productCode as what ie returns
|
||||
*/
|
||||
if (null === $productCode = $pickupType) {
|
||||
$productCode = $this->getProductCode($order, $signedDelivery);
|
||||
}
|
||||
|
||||
$articles = [];
|
||||
foreach ($order->getOrderProducts() as $orderProduct) {
|
||||
$productPrice = $orderProduct->getWasInPromo() ? $orderProduct->getPromoPrice() : $orderProduct->getPrice();
|
||||
$articles[] = new Article(
|
||||
$orderProduct->getTitle(),
|
||||
$orderProduct->getQuantity(),
|
||||
$orderProduct->getWeight(),
|
||||
$productPrice,
|
||||
ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_CUSTOMS_PRODUCT_HSCODE),
|
||||
CurrencyQuery::create()->findOneById($order->getCurrencyId())->getCode()
|
||||
);
|
||||
}
|
||||
|
||||
$this->setLetter(new Letter(
|
||||
/** We set the general delivery informations */
|
||||
new Service(
|
||||
$productCode,
|
||||
new DateTime(),
|
||||
$order->getRef(),
|
||||
$order->getPostage(),
|
||||
3
|
||||
),
|
||||
/** We set the sender address */
|
||||
new Sender(
|
||||
$this->createAddressFromStore()
|
||||
),
|
||||
/** We set the receiver address */
|
||||
new Addressee(
|
||||
$this->createAddressFromOrderAddress(
|
||||
$orderAddress,
|
||||
$order->getCustomer()
|
||||
)
|
||||
),
|
||||
new Parcel(
|
||||
$order->getWeight()
|
||||
),
|
||||
new CustomsDeclarations(
|
||||
(bool)ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_GET_CUSTOMS_INVOICES),
|
||||
3,
|
||||
$articles
|
||||
)
|
||||
));
|
||||
|
||||
/** If this is a pickup/relay point delivery, we set the pickup location ID */
|
||||
if (null !== $pickupCode) {
|
||||
$this->getLetter()->getParcel()->setPickupLocationId($pickupCode);
|
||||
}
|
||||
|
||||
$this->getLetter()->getAddressee()->setAddresseeParcelRef($order->getRef());
|
||||
$this->getLetter()->getSender()->setSenderParcelRef($order->getRef());
|
||||
|
||||
/** We initialize the label format */
|
||||
$this->setOutputFormat(new OutputFormat());
|
||||
|
||||
/** We set the label format from the one indicated in the module config table */
|
||||
$this->getOutputFormat()->setOutputPrintingType(
|
||||
OutputFormat::OUTPUT_PRINTING_TYPE[ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_DEFAULT_LABEL_FORMAT)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a domicile delivery code given the order country and whether this is a signed delivery or not
|
||||
*
|
||||
* @param Order $order
|
||||
* @param bool $signedDelivery
|
||||
* @return mixed
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
protected function getProductCode(Order $order, $signedDelivery = false)
|
||||
{
|
||||
/** @var OrderAddress $deliveryAddress */
|
||||
$deliveryAddress = $order->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
|
||||
$code = $deliveryAddress->getCountry()->getIsocode();
|
||||
|
||||
/** France Case */
|
||||
if ($code == '250') {
|
||||
if ($signedDelivery) {
|
||||
return Service::PRODUCT_CODE_LIST[2];
|
||||
}
|
||||
return Service::PRODUCT_CODE_LIST[0];
|
||||
}
|
||||
|
||||
/** Europe Case */
|
||||
if (in_array($code, Service::EUROPE_ISOCODES, false)) {
|
||||
if ($signedDelivery) {
|
||||
return Service::PRODUCT_CODE_LIST[2];
|
||||
}
|
||||
return Service::PRODUCT_CODE_LIST[0];
|
||||
}
|
||||
|
||||
/** DOM TOM case */
|
||||
if (in_array($code, Service::DOMTOM_ISOCODES, false)) {
|
||||
if ($signedDelivery) {
|
||||
return Service::PRODUCT_CODE_LIST[11];
|
||||
}
|
||||
return Service::PRODUCT_CODE_LIST[10];
|
||||
}
|
||||
|
||||
/** Other cases */
|
||||
return Service::PRODUCT_CODE_LIST[14];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Traits;
|
||||
|
||||
use ColissimoLabel\Request\Helper\Address;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\OrderAddress;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
trait MethodCreateAddressFromOrderAddress
|
||||
{
|
||||
public function createAddressFromOrderAddress(OrderAddress $orderAddress, Customer $customer)
|
||||
{
|
||||
return (new Address())
|
||||
->setCompanyName($orderAddress->getCompany())
|
||||
->setFirstName($orderAddress->getFirstname())
|
||||
->setLastName($orderAddress->getLastname())
|
||||
->setCity($orderAddress->getCity())
|
||||
->setZipCode($orderAddress->getZipcode())
|
||||
->setCountryCode($orderAddress->getCountry()->getIsoalpha2())
|
||||
->setLine2($orderAddress->getAddress1())
|
||||
->setLine3($orderAddress->getAddress2())
|
||||
->setPhoneNumber(trim(str_replace(' ', '', $orderAddress->getPhone())))
|
||||
->setMobileNumber(trim(str_replace(' ', '', $orderAddress->getCellphone())))
|
||||
->setEmail($customer->getEmail())
|
||||
->setLanguage(strtoupper(LangQuery::create()->filterByByDefault(true)->findOne()->getCode()))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace ColissimoLabel\Request\Traits;
|
||||
|
||||
use ColissimoLabel\ColissimoLabel;
|
||||
use ColissimoLabel\Request\Helper\Address;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
/**
|
||||
* @author Gilles Bourgeat >gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
trait MethodCreateAddressFromStore
|
||||
{
|
||||
public function createAddressFromStore()
|
||||
{
|
||||
return (new Address())
|
||||
->setCompanyName(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_NAME))
|
||||
->setCity(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_CITY))
|
||||
->setZipCode(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_ZIPCODE))
|
||||
->setCountryCode(CountryQuery::create()->findOneById(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_COUNTRY))->getIsoalpha2())
|
||||
->setLine2(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_ADDRESS_1))
|
||||
->setLine3(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_ADDRESS_2))
|
||||
->setEmail(trim(ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_CONTACT_EMAIL)))
|
||||
->setPhoneNumber(trim(str_replace(' ', '', ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_FROM_PHONE))))
|
||||
->setLanguage(strtoupper(LangQuery::create()->filterByByDefault(true)->findOne()->getCode()))
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user