Skip to content

Commit 5df2603

Browse files
committed
Improve module to Oney compatibility
1 parent 51d9714 commit 5df2603

File tree

20 files changed

+742
-49
lines changed

20 files changed

+742
-49
lines changed

Config/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<language>en_US</language>
1818
<language>fr_FR</language>
1919
</languages>
20-
<version>1.0.2</version>
20+
<version>1.0.3</version>
2121
<authors>
2222
<author>
2323
<name>Vincent Lopes-Vicente</name>

Config/schema.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@
4444
</foreign-key>
4545
</table>
4646

47+
<table name="pay_plug_module_delivery_type" namespace="PayPlugModule\Model">
48+
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
49+
<column name="module_id" type="integer" />
50+
<column name="delivery_type" size="255" type="VARCHAR" />
51+
<foreign-key foreignTable="module" name="fk_pay_plug_module_delivery_type_module_id" onDelete="CASCADE" onUpdate="RESTRICT">
52+
<reference foreign="id" local="module_id" />
53+
</foreign-key>
54+
</table>
55+
4756
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
4857
</database>

Config/thelia.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,25 @@ CREATE TABLE `order_pay_plug_multi_payment`
7373
ON DELETE CASCADE
7474
) ENGINE=InnoDB;
7575

76+
-- ---------------------------------------------------------------------
77+
-- pay_plug_module_delivery_type
78+
-- ---------------------------------------------------------------------
79+
80+
DROP TABLE IF EXISTS `pay_plug_module_delivery_type`;
81+
82+
CREATE TABLE `pay_plug_module_delivery_type`
83+
(
84+
`id` INTEGER NOT NULL AUTO_INCREMENT,
85+
`module_id` INTEGER,
86+
`delivery_type` VARCHAR(255),
87+
PRIMARY KEY (`id`),
88+
INDEX `fi_pay_plug_module_delivery_type_module_id` (`module_id`),
89+
CONSTRAINT `fk_pay_plug_module_delivery_type_module_id`
90+
FOREIGN KEY (`module_id`)
91+
REFERENCES `module` (`id`)
92+
ON UPDATE RESTRICT
93+
ON DELETE CASCADE
94+
) ENGINE=InnoDB;
95+
7696
# This restores the fkey checks, after having unset them earlier
7797
SET FOREIGN_KEY_CHECKS = 1;

Config/update/1.0.3.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
-- ---------------------------------------------------------------------
7+
-- pay_plug_module_delivery_type
8+
-- ---------------------------------------------------------------------
9+
10+
DROP TABLE IF EXISTS `pay_plug_module_delivery_type`;
11+
12+
CREATE TABLE `pay_plug_module_delivery_type`
13+
(
14+
`id` INTEGER NOT NULL AUTO_INCREMENT,
15+
`module_id` INTEGER,
16+
`delivery_type` VARCHAR(255),
17+
PRIMARY KEY (`id`),
18+
INDEX `fi_pay_plug_module_delivery_type_module_id` (`module_id`),
19+
CONSTRAINT `fk_pay_plug_module_delivery_type_module_id`
20+
FOREIGN KEY (`module_id`)
21+
REFERENCES `module` (`id`)
22+
ON UPDATE RESTRICT
23+
ON DELETE CASCADE
24+
) ENGINE=InnoDB;
25+
26+
# This restores the fkey checks, after having unset them earlier
27+
SET FOREIGN_KEY_CHECKS = 1;

Controller/Admin/ConfigurationController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PayPlugModule\Controller\Admin;
44

5+
use PayPlugModule\Form\ConfigurationForm;
56
use PayPlugModule\Model\PayPlugConfigValue;
7+
use PayPlugModule\Model\PayPlugModuleDeliveryTypeQuery;
68
use PayPlugModule\PayPlugModule;
79
use PayPlugModule\Service\OrderStatusService;
810
use Thelia\Controller\Admin\BaseAdminController;
@@ -18,9 +20,11 @@ public function viewAction()
1820
/** @var OrderStatusService $orderStatusesService */
1921
$orderStatusesService = $this->container->get('payplugmodule_order_status_service');
2022
$orderStatusesService->initAllStatuses();
23+
$deliveryModuleFormFields = ConfigurationForm::getDeliveryModuleFormFields();
2124

2225
return $this->render(
23-
"PayPlugModule/configuration"
26+
"PayPlugModule/configuration",
27+
compact('deliveryModuleFormFields')
2428
);
2529
}
2630

@@ -39,6 +43,14 @@ public function saveAction()
3943
if (in_array($key, PayPlugConfigValue::getConfigKeys())) {
4044
PayPlugModule::setConfigValue($key, $value);
4145
}
46+
47+
$explodedKey = explode(':', $key);
48+
if ($explodedKey[0] === ConfigurationForm::DELIVERY_MODULE_TYPE_KEY_PREFIX) {
49+
$moduleId = $explodedKey[1];
50+
$payPlugModuleDeliveryType = PayPlugModuleDeliveryTypeQuery::create()->filterByModuleId($moduleId)->findOneOrCreate();
51+
$payPlugModuleDeliveryType->setDeliveryType($value)
52+
->save();
53+
}
4254
}
4355

4456
} catch (\Exception $e) {

Controller/Admin/OrderController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function refundAction()
4242
);
4343
}
4444

45-
return $this->generateSuccessRedirect($form);
45+
// Sleep to let time for PayPlug to send validation
46+
sleep(2);
47+
$url = $this->retrieveSuccessUrl($form);
48+
return $this->generateRedirect($url.'#orderPayPlug');
4649
}
4750

4851
public function captureAction()
@@ -73,6 +76,9 @@ public function captureAction()
7376
);
7477
}
7578

76-
return $this->generateSuccessRedirect($form);
79+
// Sleep to let time for PayPlug to send validation
80+
sleep(2);
81+
$url = $this->retrieveSuccessUrl($form);
82+
return $this->generateRedirect($url.'#orderPayPlug');
7783
}
7884
}

0 commit comments

Comments
 (0)