Skip to content

Commit 488829a

Browse files
author
Etienne Perriere
committed
Save used equation when ordering, link order to customerFamily
1 parent 6cfbe46 commit 488829a

21 files changed

+3120
-88
lines changed

Config/config.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
</service>
7070

7171
<!-- Listening order creation -->
72-
<service id="customer.family.order" class="CustomerFamily\EventListeners\CustomerFamilyOrderPurchasePriceListener">
72+
<service id="customer.family.order" class="CustomerFamily\EventListeners\CustomerFamilyOrderListener">
73+
<argument type="service" id="customer.family.service"/>
7374
<tag name="kernel.event_subscriber"/>
7475
</service>
7576

Config/create.sql

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
# This is a fix for InnoDB in MySQL >= 4.1.x
3+
# It "suspends judgement" for fkey relationships until are tables are set.
4+
SET FOREIGN_KEY_CHECKS = 0;
5+
6+
-- ---------------------------------------------------------------------
7+
-- customer_family
8+
-- ---------------------------------------------------------------------
9+
10+
CREATE TABLE IF NOT EXISTS `customer_family`
11+
(
12+
`id` INTEGER NOT NULL AUTO_INCREMENT,
13+
`code` VARCHAR(45) NOT NULL,
14+
`is_default` TINYINT,
15+
`created_at` DATETIME,
16+
`updated_at` DATETIME,
17+
PRIMARY KEY (`id`),
18+
UNIQUE INDEX `customer_family_U_1` (`code`)
19+
) ENGINE=InnoDB;
20+
21+
-- ---------------------------------------------------------------------
22+
-- customer_customer_family
23+
-- ---------------------------------------------------------------------
24+
25+
CREATE TABLE IF NOT EXISTS `customer_customer_family`
26+
(
27+
`customer_id` INTEGER NOT NULL,
28+
`customer_family_id` INTEGER NOT NULL,
29+
`siret` VARCHAR(50),
30+
`vat` VARCHAR(50),
31+
PRIMARY KEY (`customer_id`),
32+
INDEX `idx_customer_customer_family_customer_family_id` (`customer_family_id`),
33+
CONSTRAINT `customer_customer_family_FK_1`
34+
FOREIGN KEY (`customer_id`)
35+
REFERENCES `customer` (`id`)
36+
ON DELETE CASCADE,
37+
CONSTRAINT `customer_customer_family_FK_2`
38+
FOREIGN KEY (`customer_family_id`)
39+
REFERENCES `customer_family` (`id`)
40+
ON DELETE CASCADE
41+
) ENGINE=InnoDB;
42+
43+
-- ---------------------------------------------------------------------
44+
-- customer_family_price
45+
-- ---------------------------------------------------------------------
46+
47+
CREATE TABLE IF NOT EXISTS `customer_family_price`
48+
(
49+
`customer_family_id` INTEGER NOT NULL,
50+
`promo` TINYINT DEFAULT 0 NOT NULL,
51+
`use_equation` TINYINT DEFAULT 0 NOT NULL,
52+
`amount_added_before` DECIMAL(16,6) DEFAULT 0,
53+
`amount_added_after` DECIMAL(16,6) DEFAULT 0,
54+
`multiplication_coefficient` DECIMAL(16,6) DEFAULT 1,
55+
`is_taxed` TINYINT DEFAULT 1 NOT NULL,
56+
PRIMARY KEY (`customer_family_id`,`promo`),
57+
CONSTRAINT `fk_customer_family_id`
58+
FOREIGN KEY (`customer_family_id`)
59+
REFERENCES `customer_family` (`id`)
60+
ON UPDATE RESTRICT
61+
ON DELETE CASCADE
62+
) ENGINE=InnoDB;
63+
64+
-- ---------------------------------------------------------------------
65+
-- product_purchase_price
66+
-- ---------------------------------------------------------------------
67+
68+
CREATE TABLE IF NOT EXISTS `product_purchase_price`
69+
(
70+
`product_sale_elements_id` INTEGER NOT NULL,
71+
`currency_id` INTEGER NOT NULL,
72+
`purchase_price` DECIMAL(16,6) DEFAULT 0,
73+
PRIMARY KEY (`product_sale_elements_id`,`currency_id`),
74+
INDEX `FI_currency_id` (`currency_id`),
75+
CONSTRAINT `fk_product_sale_elements_id`
76+
FOREIGN KEY (`product_sale_elements_id`)
77+
REFERENCES `product_sale_elements` (`id`)
78+
ON UPDATE RESTRICT
79+
ON DELETE CASCADE,
80+
CONSTRAINT `fk_currency_id`
81+
FOREIGN KEY (`currency_id`)
82+
REFERENCES `currency` (`id`)
83+
ON UPDATE RESTRICT
84+
ON DELETE CASCADE
85+
) ENGINE=InnoDB;
86+
87+
-- ---------------------------------------------------------------------
88+
-- order_product_purchase_price
89+
-- ---------------------------------------------------------------------
90+
91+
CREATE TABLE IF NOT EXISTS `order_product_purchase_price`
92+
(
93+
`order_product_id` INTEGER NOT NULL,
94+
`purchase_price` DECIMAL(16,6) DEFAULT 0,
95+
`sale_day_equation` TEXT NOT NULL,
96+
PRIMARY KEY (`order_product_id`),
97+
CONSTRAINT `fk_order_product_id`
98+
FOREIGN KEY (`order_product_id`)
99+
REFERENCES `order_product` (`id`)
100+
ON UPDATE RESTRICT
101+
ON DELETE CASCADE
102+
) ENGINE=InnoDB;
103+
104+
-- ---------------------------------------------------------------------
105+
-- customer_family_order
106+
-- ---------------------------------------------------------------------
107+
108+
CREATE TABLE IF NOT EXISTS `customer_family_order`
109+
(
110+
`order_id` INTEGER NOT NULL,
111+
`customer_family_code` VARCHAR(45) NOT NULL,
112+
PRIMARY KEY (`order_id`),
113+
INDEX `FI_customer_family_code` (`customer_family_code`),
114+
CONSTRAINT `fk_customer_family_order_id`
115+
FOREIGN KEY (`order_id`)
116+
REFERENCES `order` (`id`)
117+
ON DELETE CASCADE,
118+
CONSTRAINT `fk_customer_family_code`
119+
FOREIGN KEY (`customer_family_code`)
120+
REFERENCES `customer_family` (`code`)
121+
ON UPDATE CASCADE
122+
) ENGINE=InnoDB;
123+
124+
-- ---------------------------------------------------------------------
125+
-- customer_family_i18n
126+
-- ---------------------------------------------------------------------
127+
128+
CREATE TABLE IF NOT EXISTS `customer_family_i18n`
129+
(
130+
`id` INTEGER NOT NULL,
131+
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
132+
`title` VARCHAR(255),
133+
PRIMARY KEY (`id`,`locale`),
134+
CONSTRAINT `customer_family_i18n_FK_1`
135+
FOREIGN KEY (`id`)
136+
REFERENCES `customer_family` (`id`)
137+
ON DELETE CASCADE
138+
) ENGINE=InnoDB;
139+
140+
# This restores the fkey checks, after having unset them earlier
141+
SET FOREIGN_KEY_CHECKS = 1;

Config/schema.xml

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262
<reference foreign="id" local="order_product_id" />
6363
</foreign-key>
6464
<column name="purchase_price" type="DECIMAL" size="16" scale="6" defaultValue="0"/>
65+
<column name="sale_day_equation" type="LONGVARCHAR" required="true"/>
66+
</table>
67+
68+
<table name="customer_family_order">
69+
<column name="order_id" primaryKey="true" required="true" type="INTEGER"/>
70+
<foreign-key foreignTable="order" name="fk_customer_family_order_id" onDelete="CASCADE">
71+
<reference foreign="id" local="order_id" />
72+
</foreign-key>
73+
<column name="customer_family_code" required="true" type="VARCHAR" size="45"/>
74+
<foreign-key foreignTable="customer_family" name="fk_customer_family_code" onDelete="NONE" onUpdate="CASCADE">
75+
<reference foreign="code" local="customer_family_code" />
76+
</foreign-key>
6577
</table>
6678

6779
<external-schema filename="local/config/schema.xml" referenceOnly="true" />

Config/thelia.sql

+23
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ CREATE TABLE `order_product_purchase_price`
102102
(
103103
`order_product_id` INTEGER NOT NULL,
104104
`purchase_price` DECIMAL(16,6) DEFAULT 0,
105+
`sale_day_equation` TEXT NOT NULL,
105106
PRIMARY KEY (`order_product_id`),
106107
CONSTRAINT `fk_order_product_id`
107108
FOREIGN KEY (`order_product_id`)
@@ -110,6 +111,28 @@ CREATE TABLE `order_product_purchase_price`
110111
ON DELETE CASCADE
111112
) ENGINE=InnoDB;
112113

114+
-- ---------------------------------------------------------------------
115+
-- customer_family_order
116+
-- ---------------------------------------------------------------------
117+
118+
DROP TABLE IF EXISTS `customer_family_order`;
119+
120+
CREATE TABLE `customer_family_order`
121+
(
122+
`order_id` INTEGER NOT NULL,
123+
`customer_family_code` VARCHAR(45) NOT NULL,
124+
PRIMARY KEY (`order_id`),
125+
INDEX `FI_customer_family_code` (`customer_family_code`),
126+
CONSTRAINT `fk_customer_family_order_id`
127+
FOREIGN KEY (`order_id`)
128+
REFERENCES `order` (`id`)
129+
ON DELETE CASCADE,
130+
CONSTRAINT `fk_customer_family_code`
131+
FOREIGN KEY (`customer_family_code`)
132+
REFERENCES `customer_family` (`code`)
133+
ON UPDATE CASCADE
134+
) ENGINE=InnoDB;
135+
113136
-- ---------------------------------------------------------------------
114137
-- customer_family_i18n
115138
-- ---------------------------------------------------------------------

Config/update/1.3.sql

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
-- customer_family
7+
-- ---------------------------------------------------------------------
8+
9+
ALTER TABLE `customer_family` ADD `is_default` TINYINT AFTER `code`;
10+
11+
-- ---------------------------------------------------------------------
12+
-- customer_family_price
13+
-- ---------------------------------------------------------------------
14+
15+
CREATE TABLE IF NOT EXISTS `customer_family_price`
16+
(
17+
`customer_family_id` INTEGER NOT NULL,
18+
`promo` TINYINT DEFAULT 0 NOT NULL,
19+
`use_equation` TINYINT DEFAULT 0 NOT NULL,
20+
`amount_added_before` DECIMAL(16,6) DEFAULT 0,
21+
`amount_added_after` DECIMAL(16,6) DEFAULT 0,
22+
`multiplication_coefficient` DECIMAL(16,6) DEFAULT 1,
23+
`is_taxed` TINYINT DEFAULT 1 NOT NULL,
24+
PRIMARY KEY (`customer_family_id`,`promo`),
25+
CONSTRAINT `fk_customer_family_id`
26+
FOREIGN KEY (`customer_family_id`)
27+
REFERENCES `customer_family` (`id`)
28+
ON UPDATE RESTRICT
29+
ON DELETE CASCADE
30+
) ENGINE=InnoDB;
31+
32+
-- ---------------------------------------------------------------------
33+
-- product_purchase_price
34+
-- ---------------------------------------------------------------------
35+
36+
CREATE TABLE IF NOT EXISTS `product_purchase_price`
37+
(
38+
`product_sale_elements_id` INTEGER NOT NULL,
39+
`currency_id` INTEGER NOT NULL,
40+
`purchase_price` DECIMAL(16,6) DEFAULT 0,
41+
PRIMARY KEY (`product_sale_elements_id`,`currency_id`),
42+
INDEX `FI_currency_id` (`currency_id`),
43+
CONSTRAINT `fk_product_sale_elements_id`
44+
FOREIGN KEY (`product_sale_elements_id`)
45+
REFERENCES `product_sale_elements` (`id`)
46+
ON UPDATE RESTRICT
47+
ON DELETE CASCADE,
48+
CONSTRAINT `fk_currency_id`
49+
FOREIGN KEY (`currency_id`)
50+
REFERENCES `currency` (`id`)
51+
ON UPDATE RESTRICT
52+
ON DELETE CASCADE
53+
) ENGINE=InnoDB;
54+
55+
-- ---------------------------------------------------------------------
56+
-- order_product_purchase_price
57+
-- ---------------------------------------------------------------------
58+
59+
CREATE TABLE IF NOT EXISTS `order_product_purchase_price`
60+
(
61+
`order_product_id` INTEGER NOT NULL,
62+
`purchase_price` DECIMAL(16,6) DEFAULT 0,
63+
`sale_day_equation` TEXT NOT NULL,
64+
PRIMARY KEY (`order_product_id`),
65+
CONSTRAINT `fk_order_product_id`
66+
FOREIGN KEY (`order_product_id`)
67+
REFERENCES `order_product` (`id`)
68+
ON UPDATE RESTRICT
69+
ON DELETE CASCADE
70+
) ENGINE=InnoDB;
71+
72+
-- ---------------------------------------------------------------------
73+
-- customer_family_order
74+
-- ---------------------------------------------------------------------
75+
76+
CREATE TABLE IF NOT EXISTS `customer_family_order`
77+
(
78+
`order_id` INTEGER NOT NULL,
79+
`customer_family_code` VARCHAR(45) NOT NULL,
80+
PRIMARY KEY (`order_id`),
81+
INDEX `FI_customer_family_code` (`customer_family_code`),
82+
CONSTRAINT `fk_customer_family_order_id`
83+
FOREIGN KEY (`order_id`)
84+
REFERENCES `order` (`id`)
85+
ON DELETE CASCADE,
86+
CONSTRAINT `fk_customer_family_code`
87+
FOREIGN KEY (`customer_family_code`)
88+
REFERENCES `customer_family` (`code`)
89+
ON UPDATE CASCADE
90+
) ENGINE=InnoDB;
91+
92+
# This restores the fkey checks, after having unset them earlier
93+
SET FOREIGN_KEY_CHECKS = 1;

CustomerFamily.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use CustomerFamily\Model\CustomerFamilyQuery;
1616
use Propel\Runtime\Connection\ConnectionInterface;
17+
use Symfony\Component\Finder\Finder;
1718
use Thelia\Install\Database;
1819
use Thelia\Module\BaseModule;
1920
use CustomerFamily\Model\CustomerFamily as CustomerFamilyModel;
@@ -43,12 +44,7 @@ class CustomerFamily extends BaseModule
4344
public function postActivation(ConnectionInterface $con = null)
4445
{
4546
$database = new Database($con);
46-
47-
try {
48-
CustomerFamilyQuery::create()->findOne();
49-
} catch (\Exception $e) {
50-
$database->insertSql(null, array(__DIR__ . "/Config/thelia.sql"));
51-
}
47+
$database->insertSql(null, [__DIR__ . "/Config/create.sql"]);
5248

5349
//Generate the 2 defaults customer_family
5450

@@ -61,6 +57,24 @@ public function postActivation(ConnectionInterface $con = null)
6157
self::getCustomerFamilyByCode(self::CUSTOMER_FAMILY_PROFESSIONAL, "Professional", "en_US");
6258
}
6359

60+
public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
61+
{
62+
$finder = Finder::create()
63+
->name('*.sql')
64+
->depth(0)
65+
->sortByName()
66+
->in(__DIR__ . DS . 'Config' . DS . 'update');
67+
68+
$database = new Database($con);
69+
70+
/** @var \SplFileInfo $file */
71+
foreach ($finder as $file) {
72+
if (version_compare($currentVersion, $file->getBasename('.sql'), '<')) {
73+
$database->insertSql(null, [$file->getPathname()]);
74+
}
75+
}
76+
}
77+
6478
/**
6579
* @param $code
6680
* @param null $title

0 commit comments

Comments
 (0)