colissimo module
This commit is contained in:
@@ -7,14 +7,16 @@
|
||||
|
||||
<div class="alert alert-danger">
|
||||
<p>{intl l="Prices are not dynamically editable yet."}</p>
|
||||
<p>{intl l="Prices below can be edited in Colissmo module code."}</p>
|
||||
<p>{intl l="Prices below can be edited in local/modules/Colissimo/Config/prices.json file."}</p>
|
||||
</div>
|
||||
|
||||
<div class="general-block-decorator">
|
||||
|
||||
{loop type="area" name="list area" backend_context=true}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<caption class="clearfix">
|
||||
{intl l="Collismo prices"}
|
||||
{intl l="Area : "}{$NAME}
|
||||
{loop type="auth" name="can_create" role="ADMIN" module="colissimo" access="CREATE"}
|
||||
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create a new price slice'}" href="#price_slice_create_dialog" data-toggle="modal">
|
||||
<span class="glyphicon glyphicon-plus"></span>
|
||||
@@ -29,10 +31,10 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{loop type="colissimo" name="colissimo" area=$ID}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{$MAX_WEIGHT}</td>
|
||||
<td>{$PRICE}</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
{loop type="auth" name="can_change" role="ADMIN" module="colissimo" access="UPDATE"}
|
||||
@@ -41,10 +43,12 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{/loop}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/loop}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<loops>
|
||||
<!-- sample definition
|
||||
<loop name="MySuperLoop" class="MyModule\Loop\MySuperLoop" />
|
||||
-->
|
||||
<loop class="Colissimo\Loop\Price" name="colissimo"/>
|
||||
</loops>
|
||||
|
||||
<forms>
|
||||
|
||||
88
local/modules/Colissimo/Loop/Price.php
Executable file
88
local/modules/Colissimo/Loop/Price.php
Executable file
@@ -0,0 +1,88 @@
|
||||
<?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 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 <eroudeix@openstudio.fr>
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user