[12/05/2025] Un peu de paramétrage, notamment les frais de port gratuits en fonction de certains seuils

This commit is contained in:
2025-05-12 17:02:55 +02:00
parent 49b1a63ecc
commit 5826bd7942
105 changed files with 18596 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping;
use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshippingQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
class AreaFreeshipping extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('area_id')
);
}
public function buildModelCriteria()
{
$areaId = $this->getAreaId();
$modes = ColissimoPickupPointAreaFreeshippingQuery::create();
if (null !== $areaId) {
$modes->filterByAreaId($areaId);
}
return $modes;
}
public function parseResults(LoopResult $loopResult)
{
/** @var ColissimoPickupPointAreaFreeshipping $mode */
foreach ($loopResult->getResultDataCollection() as $mode) {
$loopResultRow = new LoopResultRow($mode);
$loopResultRow
->set('ID', $mode->getId())
->set('AREA_ID', $mode->getAreaId())
->set('CART_AMOUNT', $mode->getCartAmount());
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Translation\Translator;
/**
* Class CheckRightsLoop
* @package Colissimo\Looop
* @author Thelia <info@thelia.net>
*/
class CheckRightsLoop extends BaseLoop implements ArraySearchLoopInterface
{
protected function getArgDefinitions()
{
return new ArgumentCollection();
}
public function buildArray()
{
$ret = array();
$dir = __DIR__ . '/../Config/';
if (!is_readable($dir)) {
$ret[] = array('ERRMES' => Translator::getInstance()->trans("Can't read Config directory"), 'ERRFILE' => '');
}
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (strlen($file) > 5 && substr($file, -5) === '.json') {
if (!is_readable($dir.$file)) {
$ret[] = array('ERRMES' => Translator::getInstance()->trans("Can't read file"), 'ERRFILE' => 'Colissimo/Config/' . $file);
}
}
}
}
return $ret;
}
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $arr) {
$loopResultRow = new LoopResultRow();
$loopResultRow
->set('ERRMES', $arr['ERRMES'])
->set('ERRFILE', $arr['ERRFILE'])
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\Model\AddressColissimoPickupPoint;
use ColissimoPickupPoint\Model\AddressColissimoPickupPointQuery;
use Thelia\Core\Template\Loop\Address;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
/**
* class ColissimoPickupPointDelivery
* @package ColissimoPickupPoint\Loop
* @author Thelia <info@thelia.net>
*/
class ColissimoPickupPointAddress extends Address
{
protected $exists = false;
protected $timestampable = false;
protected function setExists($id)
{
$this->exists = AddressColissimoPickupPointQuery::create()->findPK($id) !== null;
}
public function buildModelCriteria()
{
$id = $this->getId();
$this->setExists($id[0]);
return $this->exists ?
AddressColissimoPickupPointQuery::create()->filterById($id[0]) :
parent::buildModelCriteria();
}
public function parseResults(LoopResult $loopResult)
{
if (!$this->exists) {
return parent::parseResults($loopResult);
}
/** @var AddressColissimoPickupPoint $address */
foreach ($loopResult->getResultDataCollection() as $address) {
$loopResultRow = new LoopResultRow();
$loopResultRow
->set('TITLE', $address->getTitleId())
->set('COMPANY', $address->getCompany())
->set('FIRSTNAME', $address->getFirstname())
->set('LASTNAME', $address->getLastname())
->set('ADDRESS1', $address->getAddress1())
->set('ADDRESS2', $address->getAddress2())
->set('ADDRESS3', $address->getAddress3())
->set('ZIPCODE', $address->getZipcode())
->set('CITY', $address->getCity())
->set('COUNTRY', $address->getCountryId())
->set('CELLPHONE', $address->getCellphone())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping;
use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
class ColissimoPickupPointFreeshippingLoop extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('id')
);
}
public function buildModelCriteria()
{
if (null === $isFreeShippingActive = ColissimoPickupPointFreeshippingQuery::create()->findOneById(1)){
$isFreeShippingActive = new ColissimoPickupPointFreeshipping();
$isFreeShippingActive->setId(1);
$isFreeShippingActive->setActive(0);
$isFreeShippingActive->save();
}
return ColissimoPickupPointFreeshippingQuery::create()->filterById(1);
}
public function parseResults(LoopResult $loopResult)
{
/** @var ColissimoPickupPointFreeshipping $freeshipping */
foreach ($loopResult->getResultDataCollection() as $freeshipping) {
$loopResultRow = new LoopResultRow($freeshipping);
$loopResultRow
->set('FREESHIPPING_ACTIVE', $freeshipping->getActive())
->set('FREESHIPPING_FROM', $freeshipping->getFreeshippingFrom());
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
/**
* class ColissimoPickupPointId
* @package ColissimoPickupPoint\Loop
* @author Thelia <info@thelia.net>
*/
class ColissimoPickupPointId extends BaseLoop implements ArraySearchLoopInterface
{
/**
* this method returns an array
*
* @return array
*/
public function buildArray()
{
return array(ColissimoPickupPoint::getModCode());
}
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $id) {
$loopResultRow = new LoopResultRow();
$loopResult->addRow(
$loopResultRow->set('MODULE_ID', $id)
);
}
return $loopResult;
}
protected function getArgDefinitions()
{
return new ArgumentCollection();
}
}

View File

@@ -0,0 +1,92 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint;
use ColissimoPickupPoint\Model\OrderAddressColissimoPickupPointQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
class ColissimoPickupPointOrderAddressLoop extends BaseLoop implements PropelSearchLoopInterface
{
/**
* Definition of loop arguments
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
*
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* ...
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('id', null, true)
);
}
/**
* this method returns a Propel ModelCriteria
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildModelCriteria()
{
$query = OrderAddressColissimoPickupPointQuery::create();
if (($id = $this->getId()) !== null) {
$query->filterById((int)$id);
}
return $query;
}
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
/** @var OrderAddressColissimoPickupPoint $orderAddressColissimoPickupPoint */
foreach ($loopResult->getResultDataCollection() as $orderAddressColissimoPickupPoint) {
$row = new LoopResultRow();
$row->set('ID', $orderAddressColissimoPickupPoint->getId());
$row->set('CODE', $orderAddressColissimoPickupPoint->getCode());
$row->set('TYPE', $orderAddressColissimoPickupPoint->getType());
$loopResult->addRow($row)
;
}
return $loopResult;
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlicesQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
class ColissimoPickupPointPriceSlices extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('area_id', null, true)
);
}
public function buildModelCriteria()
{
$areaId = $this->getAreaId();
$areaPrices = ColissimoPickupPointPriceSlicesQuery::create()
->filterByAreaId($areaId)
->orderByWeightMax();
return $areaPrices;
}
public function parseResults(LoopResult $loopResult)
{
/** @var \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices $price */
foreach ($loopResult->getResultDataCollection() as $price) {
$loopResultRow = new LoopResultRow($price);
$loopResultRow
->set('SLICE_ID', $price->getId())
->set('MAX_WEIGHT', $price->getWeightMax())
->set('MAX_PRICE', $price->getPriceMax())
->set('PRICE', $price->getPrice())
->set('FRANCO', $price->getFrancoMinPrice())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,179 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use ColissimoPickupPoint\ColissimoPickupPoint;
use ColissimoPickupPoint\WebService\FindByAddress;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CountryQuery;
/**
* Class GetRelais
* @package ColissimoPickupPoint\Loop
* @author Thelia <info@thelia.net>
*/
class GetRelais extends BaseLoop implements ArraySearchLoopInterface
{
/**
* @inheritdoc
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('countryid', ''),
Argument::createAnyTypeArgument('zipcode', ''),
Argument::createAnyTypeArgument('city', ''),
Argument::createIntTypeArgument('address')
);
}
/**
* @return array|mixed
* @throws \ErrorException
* @throws \Propel\Runtime\Exception\PropelException
*/
public function buildArray()
{
// Find the address ... To find ! \m/
$zipcode = $this->getZipcode();
$city = $this->getCity();
$countryId = $this->getCountryid();
$addressId = $this->getAddress();
if (!empty($addressId) && (!empty($zipcode) || !empty($city))) {
throw new \InvalidArgumentException(
"Cannot have argument 'address' and 'zipcode' or 'city' at the same time."
);
}
if (null !== $addressModel = AddressQuery::create()->findPk($addressId)) {
$address = array(
'zipcode' => $addressModel->getZipcode(),
'city' => $addressModel->getCity(),
'address' => $addressModel->getAddress1(),
'countrycode' => $addressModel->getCountry()->getIsoalpha2()
);
} elseif (empty($zipcode) || empty($city)) {
$search = AddressQuery::create();
$customer = $this->securityContext->getCustomerUser();
if ($customer !== null) {
$search->filterByCustomerId($customer->getId());
$search->filterByIsDefault('1');
} else {
throw new \ErrorException('Customer not connected.');
}
$search = $search->findOne();
$address['zipcode'] = $search->getZipcode();
$address['city'] = $search->getCity();
$address['address'] = $search->getAddress1();
$address['countrycode'] = $search->getCountry()->getIsoalpha2();
} else {
$address = array(
'zipcode' => $zipcode,
'city' => $city,
'address' => '',
'countrycode' => CountryQuery::create()
->findOneById($countryId)
->getIsoalpha2()
);
}
// Then ask the Web Service
$request = new FindByAddress();
$request
->setAddress($address['address'])
->setZipCode($address['zipcode'])
->setCity($address['city'])
->setCountryCode($address['countrycode'])
->setFilterRelay('1')
->setRequestId(md5(microtime()))
->setLang('FR')
->setOptionInter('1')
->setShippingDate(date('d/m/Y'))
->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME))
->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD))
;
try {
$response = $request->exec();
} catch (InvalidArgumentException $e) {
$response = array();
} catch (\SoapFault $e) {
$response = array();
}
if (!is_array($response) && $response !== null) {
$newResponse[] = $response;
$response = $newResponse;
}
return $response;
}
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow();
//Tlog::getInstance()->addDebug(print_r($item, true));
foreach ($item as $key => $value) {
$loopResultRow->set($key, $value);
}
// format distance
$distance = (string) $loopResultRow->get('distanceEnMetre');
if (strlen($distance) < 4) {
$distance .= ' m';
} else {
$distance = (string)(float)$distance / 1000;
while (substr($distance, strlen($distance) - 1, 1) == "0") {
$distance = substr($distance, 0, strlen($distance) - 1);
}
$distance = str_replace('.', ',', $distance) . ' km';
}
$loopResultRow->set('distance', $distance);
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\OrderQuery;
use Thelia\Core\Template\Loop\Order;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;
/**
* Class NotSentOrders
* @package ColissimoPickupPoint\Loop
* @author Thelia <info@thelia.net>
*/
class NotSentOrders extends Order
{
public function getArgDefinitions()
{
return new ArgumentCollection(Argument::createBooleanTypeArgument('with_prev_next_info', false));
}
/**
* this method returns a Propel ModelCriteria
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildModelCriteria()
{
$status = OrderStatusQuery::create()
->filterByCode(
array(
OrderStatus::CODE_PAID,
OrderStatus::CODE_PROCESSING,
),
Criteria::IN
)
->find()
->toArray('code');
$query = OrderQuery::create()
->filterByDeliveryModuleId(ColissimoPickupPoint::getModCode())
->filterByStatusId(
array(
$status[OrderStatus::CODE_PAID]['Id'],
$status[OrderStatus::CODE_PROCESSING]['Id']),
Criteria::IN
);
return $query;
}
}