Skip to content

Commit 6d2b3f6

Browse files
Merge pull request #38 from ThomasDaSilva/feat/EORI
Feature EORI For US expedition
2 parents a990730 + ec7a902 commit 6d2b3f6

20 files changed

Lines changed: 274 additions & 3 deletions

ColissimoLabel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class ColissimoLabel extends BaseModule
7676

7777
const CONFIG_KEY_ENDPOINT = 'colissimolabel-endpoint';
7878

79+
const CONFIG_KEY_EORI = 'colissimolabel-eori';
80+
7981
const CONFIG_DEFAULT_KEY_ENDPOINT = 'https://ws.colissimo.fr/sls-ws/SlsServiceWS/2.0?wsdl';
8082

8183
const CONFIG_KEY_FROM_NAME = 'colissimolabel-company-name';

Config/TheliaMain.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,27 @@ CREATE TABLE `colissimo_label`
3232
ON DELETE CASCADE
3333
) ENGINE=InnoDB;
3434

35+
-- ---------------------------------------------------------------------
36+
-- colissimo_label_product_customs
37+
-- ---------------------------------------------------------------------
38+
39+
DROP TABLE IF EXISTS `colissimo_label_product_customs`;
40+
41+
CREATE TABLE `colissimo_label_product_customs`
42+
(
43+
`id` INTEGER NOT NULL AUTO_INCREMENT,
44+
`product_id` INTEGER NOT NULL,
45+
`hs_code` VARCHAR(50) DEFAULT '' NOT NULL,
46+
`created_at` DATETIME,
47+
`updated_at` DATETIME,
48+
PRIMARY KEY (`id`),
49+
UNIQUE INDEX `colissimo_label_product_customs_product_id_unique` (`product_id`),
50+
CONSTRAINT `colissimo_label_product_customs_fk_product`
51+
FOREIGN KEY (`product_id`)
52+
REFERENCES `product` (`id`)
53+
ON UPDATE RESTRICT
54+
ON DELETE CASCADE
55+
) ENGINE=InnoDB;
56+
3557
# This restores the fkey checks, after having unset them earlier
3658
SET FOREIGN_KEY_CHECKS = 1;

Config/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
<hook id="colissimo.label.hook.hook.main.in.top.menu.items" class="ColissimoLabel\Hook\Back\MenuHook">
1717
<tag name="hook.event_listener" event="main.in-top-menu-items" type="back" />
1818
</hook>
19+
<hook id="colissimo.label.hook.back.product_tab" class="ColissimoLabel\Hook\Back\ProductTabHook">
20+
<tag name="hook.event_listener" event="product.tab" type="back" method="onProductTab" />
21+
</hook>
1922
</hooks>
2023
</config>

Config/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<language>en_US</language>
1414
<language>fr_FR</language>
1515
</languages>
16-
<version>2.2.2</version>
16+
<version>2.2.3</version>
1717
<authors>
1818
<author>
1919
<name>Gilles Bourgeat</name>

Config/schema.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,21 @@
2222
<behavior name="timestampable" />
2323
</table>
2424

25+
<table name="colissimo_label_product_customs" namespace="ColissimoLabel\Model">
26+
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
27+
<column name="product_id" required="true" type="INTEGER" />
28+
<column name="hs_code" type="VARCHAR" size="50" required="true" defaultValue="" />
29+
30+
<foreign-key foreignTable="product" onDelete="CASCADE" onUpdate="RESTRICT">
31+
<reference local="product_id" foreign="id" />
32+
</foreign-key>
33+
34+
<unique name="colissimo_label_product_customs_product_id_unique">
35+
<unique-column name="product_id" />
36+
</unique>
37+
38+
<behavior name="timestampable" />
39+
</table>
40+
2541
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
2642
</database>

Config/update/2.2.3.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is a fix for InnoDB in MySQL >= 4.1.x
2+
# It "suspends judgement" for fkey relationships until are tables are set.
3+
SET FOREIGN_KEY_CHECKS = 0;
4+
5+
-- ---------------------------------------------------------------------
6+
-- colissimo_label_product_customs
7+
-- ---------------------------------------------------------------------
8+
9+
CREATE TABLE IF NOT EXISTS `colissimo_label_product_customs`
10+
(
11+
`id` INTEGER NOT NULL AUTO_INCREMENT,
12+
`product_id` INTEGER NOT NULL,
13+
`hs_code` VARCHAR(50) DEFAULT '' NOT NULL,
14+
`created_at` DATETIME,
15+
`updated_at` DATETIME,
16+
PRIMARY KEY (`id`),
17+
UNIQUE INDEX `colissimo_label_product_customs_product_id_unique` (`product_id`),
18+
CONSTRAINT `colissimo_label_product_customs_fk_product`
19+
FOREIGN KEY (`product_id`)
20+
REFERENCES `product` (`id`)
21+
ON UPDATE RESTRICT
22+
ON DELETE CASCADE
23+
) ENGINE=InnoDB;
24+
25+
# This restores the fkey checks, after having unset them earlier
26+
SET FOREIGN_KEY_CHECKS = 1;

Controller/Admin/ConfigurationController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function saveConfig()
5151
}
5252
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_POSTAL_NETWORK, $postalNetwork);
5353
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_ENDPOINT, $vform->get(ColissimoLabel::CONFIG_KEY_ENDPOINT)->getData());
54+
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_EORI, $vform->get(ColissimoLabel::CONFIG_KEY_EORI)->getData());
5455

5556
/* Sender's address values */
5657
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_FROM_NAME, $vform->get(ColissimoLabel::CONFIG_KEY_FROM_NAME)->getData());
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace ColissimoLabel\Controller\Admin;
4+
5+
use ColissimoLabel\Model\ColissimoLabelProductCustoms;
6+
use ColissimoLabel\Model\ColissimoLabelProductCustomsQuery;
7+
use Symfony\Component\HttpFoundation\RedirectResponse;
8+
use Symfony\Component\HttpFoundation\Response;
9+
use Symfony\Component\Routing\Annotation\Route;
10+
use Thelia\Controller\Admin\BaseAdminController;
11+
use Thelia\Core\HttpFoundation\Request;
12+
use Thelia\Core\Security\AccessManager;
13+
use Thelia\Core\Security\Resource\AdminResources;
14+
use Thelia\Tools\URL;
15+
16+
#[Route('/admin/module/ColissimoLabel/product-customs', name: 'colissimo_label_product_customs_')]
17+
class ProductCustomsController extends BaseAdminController
18+
{
19+
#[Route('/save', name: 'save', methods: ['POST'])]
20+
public function saveAction(Request $request): Response
21+
{
22+
if (null !== $response = $this->checkAuth([AdminResources::PRODUCT], ['ColissimoLabel'], AccessManager::UPDATE)) {
23+
return $response;
24+
}
25+
26+
$productId = (int) $request->request->get('product_id');
27+
$hsCode = trim((string) $request->request->get('hs_code', ''));
28+
29+
if ($productId <= 0) {
30+
return $this->errorPage('Missing product_id', 400);
31+
}
32+
33+
$customs = ColissimoLabelProductCustomsQuery::create()->findOneByProductId($productId)
34+
?? (new ColissimoLabelProductCustoms())->setProductId($productId);
35+
36+
$customs->setHsCode($hsCode)->save();
37+
38+
return new RedirectResponse(
39+
URL::getInstance()->absoluteUrl(
40+
'/admin/products/update',
41+
['product_id' => $productId, 'current_tab' => 'colissimo_label_product_customs']
42+
)
43+
);
44+
}
45+
}

Form/ConfigureColissimoLabel.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ protected function buildForm()
138138
'label_attr' => ['for' => ColissimoLabel::CONFIG_KEY_ENDPOINT],
139139
]
140140
)
141+
->add(
142+
ColissimoLabel::CONFIG_KEY_EORI,
143+
TextType::class,
144+
[
145+
'required' => true,
146+
'data' => ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_EORI),
147+
'label' => $this->translator->trans('EORI', [], ColissimoLabel::DOMAIN_NAME),
148+
'label_attr' => ['for' => ColissimoLabel::CONFIG_KEY_EORI],
149+
]
150+
)
141151
->add(
142152
ColissimoLabel::CONFIG_KEY_FROM_NAME,
143153
TextType::class,

Hook/Back/ProductTabHook.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace ColissimoLabel\Hook\Back;
4+
5+
use ColissimoLabel\ColissimoLabel;
6+
use ColissimoLabel\Model\ColissimoLabelProductCustomsQuery;
7+
use Thelia\Core\Event\Hook\HookRenderBlockEvent;
8+
use Thelia\Core\Hook\BaseHook;
9+
10+
class ProductTabHook extends BaseHook
11+
{
12+
public function onProductTab(HookRenderBlockEvent $event): void
13+
{
14+
$productId = (int) $event->getArgument('id');
15+
16+
$customs = ColissimoLabelProductCustomsQuery::create()
17+
->findOneByProductId($productId);
18+
19+
$event->add([
20+
'id' => 'colissimo_label_product_customs',
21+
'title' => $this->trans('Douane Colissimo', [], ColissimoLabel::DOMAIN_NAME),
22+
'content' => $this->render('colissimo-label/hook/product-tab-customs.html', [
23+
'product_id' => $productId,
24+
'hs_code' => $customs?->getHsCode() ?? '',
25+
'default_hs_code' => (string) ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_CUSTOMS_PRODUCT_HSCODE),
26+
]),
27+
]);
28+
}
29+
}

0 commit comments

Comments
 (0)