From fa127ed4f01dfe4c1eced63d7dbd4d5807d401bd Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 14 Nov 2013 11:53:29 +0100 Subject: [PATCH] colissimo module --- core/lib/Thelia/Action/Order.php | 6 -- .../Controller/Front/OrderController.php | 3 - .../AdminIncludes/module_configuration.html | 18 ++-- local/modules/Colissimo/Colissimo.php | 8 +- local/modules/Colissimo/Config/config.xml | 4 +- local/modules/Colissimo/Loop/Price.php | 88 +++++++++++++++++++ 6 files changed, 104 insertions(+), 23 deletions(-) create mode 100755 local/modules/Colissimo/Loop/Price.php diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index ba794cb4c..6eb66fdb3 100755 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -279,12 +279,6 @@ class Order extends BaseAction implements EventSubscriberInterface $this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest()))); /* call pay method */ - /*$paymentModuleReflection = new \ReflectionClass($paymentModule->getFullNamespace()); - $paymentModuleInstance = $paymentModuleReflection->newInstance(); - - $paymentModuleInstance->setRequest($this->getRequest()); - $paymentModuleInstance->setDispatcher($this->getDispatcher());*/ - $paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode())); $paymentModuleInstance->pay($placedOrder); } diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php index 11e6768d3..4c20b784e 100755 --- a/core/lib/Thelia/Controller/Front/OrderController.php +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -84,9 +84,6 @@ class OrderController extends BaseFrontController } /* get postage amount */ - /*$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace()); - $moduleInstance = $moduleReflection->newInstance();*/ - $moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode())); $postage = $moduleInstance->getPostage($deliveryAddress->getCountry()); diff --git a/local/modules/Colissimo/AdminIncludes/module_configuration.html b/local/modules/Colissimo/AdminIncludes/module_configuration.html index 5e3a388f3..ee4d2d561 100644 --- a/local/modules/Colissimo/AdminIncludes/module_configuration.html +++ b/local/modules/Colissimo/AdminIncludes/module_configuration.html @@ -7,14 +7,16 @@

{intl l="Prices are not dynamically editable yet."}

-

{intl l="Prices below can be edited in Colissmo module code."}

+

{intl l="Prices below can be edited in local/modules/Colissimo/Config/prices.json file."}

+ + {loop type="area" name="list area" backend_context=true}
- + {loop type="colissimo" name="colissimo" area=$ID} - - + + - + {/loop}
- {intl l="Collismo prices"} + {intl l="Area : "}{$NAME} {loop type="auth" name="can_create" role="ADMIN" module="colissimo" access="CREATE"} @@ -29,10 +31,10 @@
{$MAX_WEIGHT}{$PRICE}
{loop type="auth" name="can_change" role="ADMIN" module="colissimo" access="UPDATE"} @@ -41,10 +43,12 @@
+ {/loop} +
@@ -70,7 +74,7 @@ dialog_id = "price_slice_delete_dialog" dialog_title = {intl l="Delete a price slice"} - dialog_body = "Not available yet." + dialog_message = "Not available yet." dialog_ok_label = {intl l="Delete"} dialog_cancel_label = {intl l="Cancel"} diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php index 51c8fc98f..9d2734812 100755 --- a/local/modules/Colissimo/Colissimo.php +++ b/local/modules/Colissimo/Colissimo.php @@ -39,7 +39,7 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface const JSON_PRICE_RESOURCE = "prices.json"; - public function getPrices() + public static function getPrices() { if(null === self::$prices) { self::$prices = json_decode(file_get_contents(sprintf('%s/Config/%s', __DIR__, self::JSON_PRICE_RESOURCE)), true); @@ -55,9 +55,9 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface * @return mixed * @throws \Thelia\Exception\OrderException */ - public function getPostageAmount($areaId, $weight) + public static function getPostageAmount($areaId, $weight) { - $prices = $this->getPrices(); + $prices = self::getPrices(); /* check if Colissimo delivers the asked area */ if(!isset($prices[$areaId]) || !isset($prices[$areaId]["slices"])) { @@ -119,7 +119,7 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface { $cartWeight = $this->getContainer()->get('request')->getSession()->getCart()->getWeight(); - $postage = $this->getPostageAmount( + $postage = self::getPostageAmount( $country->getAreaId(), $cartWeight ); diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml index 2430f5027..f158e6526 100755 --- a/local/modules/Colissimo/Config/config.xml +++ b/local/modules/Colissimo/Config/config.xml @@ -5,9 +5,7 @@ xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> - + diff --git a/local/modules/Colissimo/Loop/Price.php b/local/modules/Colissimo/Loop/Price.php new file mode 100755 index 000000000..1f68df8a5 --- /dev/null +++ b/local/modules/Colissimo/Loop/Price.php @@ -0,0 +1,88 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Colissimo\Loop; + +use Colissimo\Colissimo; +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; +use Thelia\Core\Template\Loop\Argument\Argument; + +/** + * + * Price loop + * + * + * Class Price + * @package Colissimo\Loop + * @author Etienne Roudeix + */ +class Price extends BaseLoop implements ArraySearchLoopInterface +{ + /* set countable to false since we need to preserve keys */ + protected $countable = false; + + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntTypeArgument('area', null, true) + ); + } + + public function buildArray() + { + $area = $this->getArea(); + + $prices = Colissimo::getPrices(); + + if(!isset($prices[$area]) || !isset($prices[$area]["slices"])) { + return array(); + } + + $areaPrices = $prices[$area]["slices"]; + ksort($areaPrices); + + return $areaPrices; + } + + public function parseResults(LoopResult $loopResult) + { + foreach ($loopResult->getResultDataCollection() as $maxWeight => $price) { + $loopResultRow = new LoopResultRow(); + $loopResultRow->set("MAX_WEIGHT", $maxWeight) + ->set("PRICE", $price); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + + } +}