From 9338cdb472d3bcdd48ea2f0d833463a034096b28 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 22:05:33 +0200 Subject: [PATCH 01/27] Merge branch 'master' of https://github.com/thelia/thelia into coupon # By Manuel Raynaud (19) and others # Via Manuel Raynaud (5) and others * 'master' of https://github.com/thelia/thelia: (37 commits) add PropelDataCollector to debugbar, still missing some informations remove unused class integrate debugbar module remove htmlpurifier modify insert.sql including debugBar module add new event and new tag Started category modification Factorized modal dialogs javascript Factorized creation and confirmation modal dialogs create controller adding delivery module in session create Delivery loop Working : Continuing categories administration... Working : create base loop for delivery and payment entities remove htmlpurifier dependency country id can be an argument for calculate method Working : Working : fix typo ... Conflicts: composer.lock core/lib/Thelia/Controller/Admin/CategoryController.php templates/admin/default/assets/less/thelia/variables.less --- local/modules/Colissimo/Colissimo.php | 0 local/modules/Colissimo/Config/config.xml | 0 local/modules/Colissimo/Config/plugin.xml | 0 local/modules/Colissimo/Config/schema.xml | 0 local/modules/DebugBar/Config/config.xml | 0 local/modules/DebugBar/Config/plugin.xml | 0 local/modules/DebugBar/Config/schema.xml | 0 local/modules/DebugBar/DataCollector/PropelCollector.php | 0 local/modules/DebugBar/DebugBar.php | 0 local/modules/DebugBar/Listeners/DebugBarListeners.php | 0 local/modules/DebugBar/Smarty/Plugin/DebugBar.php | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 local/modules/Colissimo/Colissimo.php mode change 100644 => 100755 local/modules/Colissimo/Config/config.xml mode change 100644 => 100755 local/modules/Colissimo/Config/plugin.xml mode change 100644 => 100755 local/modules/Colissimo/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/Config/config.xml mode change 100644 => 100755 local/modules/DebugBar/Config/plugin.xml mode change 100644 => 100755 local/modules/DebugBar/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/DataCollector/PropelCollector.php mode change 100644 => 100755 local/modules/DebugBar/DebugBar.php mode change 100644 => 100755 local/modules/DebugBar/Listeners/DebugBarListeners.php mode change 100644 => 100755 local/modules/DebugBar/Smarty/Plugin/DebugBar.php diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/Colissimo/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/config.xml b/local/modules/DebugBar/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/plugin.xml b/local/modules/DebugBar/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/schema.xml b/local/modules/DebugBar/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DataCollector/PropelCollector.php b/local/modules/DebugBar/DataCollector/PropelCollector.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DebugBar.php b/local/modules/DebugBar/DebugBar.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Listeners/DebugBarListeners.php b/local/modules/DebugBar/Listeners/DebugBarListeners.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php old mode 100644 new mode 100755 From 6f1c77a57ede3ccc358710d2b752fbee540b2965 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 22:41:17 +0200 Subject: [PATCH 02/27] WIP : Coupon functional tests --- .../functionnal/casperjs/exe/00_parameters.js | 5 - .../casperjs/exe/31_coupons_rule.js | 618 +++++++++--------- 2 files changed, 309 insertions(+), 314 deletions(-) diff --git a/tests/functionnal/casperjs/exe/00_parameters.js b/tests/functionnal/casperjs/exe/00_parameters.js index df5470229..29bf20a25 100644 --- a/tests/functionnal/casperjs/exe/00_parameters.js +++ b/tests/functionnal/casperjs/exe/00_parameters.js @@ -7,11 +7,6 @@ var thelia2_login_coupon_create_url = thelia2_base_url + 'admin/coupon/create/'; var thelia2_login_coupon_read_url = thelia2_base_url + 'admin/coupon/read/1'; var thelia2_login_coupon_update_url = thelia2_base_url + 'admin/coupon/update/1'; - - -//var findMyId = /([0-9]+)$/; -//var currentId; - casper.test.comment('Variables are set'); casper.test.done(0); diff --git a/tests/functionnal/casperjs/exe/31_coupons_rule.js b/tests/functionnal/casperjs/exe/31_coupons_rule.js index 66706aada..4b9ada4ba 100644 --- a/tests/functionnal/casperjs/exe/31_coupons_rule.js +++ b/tests/functionnal/casperjs/exe/31_coupons_rule.js @@ -1,312 +1,312 @@ -//// -////var casper = require('casper').create({ -//// viewportSize:{ -//// width:1024, height:768 -//// }, -//// pageSettings:{ -//// userAgent:'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11' -//// }, -//// verbose:true -////}); // -//casper.test.comment('Testing coupons rules'); -// -////UPDATE COUPON RULE -//casper.start(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png'); -// this.test.comment('COUPON RULE - EDIT'); -// this.test.assertTitle('Update coupon - Thelia Back Office', 'Web page title OK'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','1) 1st default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','1) 2nd default rule found'); -// -// // Create rule -// this.evaluate(function() { -// $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); -// return true; +//var casper = require('casper').create({ +// viewportSize:{ +// width:1024, height:768 +// }, +// pageSettings:{ +// userAgent:'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11' +// }, +// verbose:true +//}); + +casper.test.comment('Testing coupons rules'); + +//UPDATE COUPON RULE +casper.start(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png'); + this.test.comment('COUPON RULE - EDIT'); + this.test.assertTitle('Update coupon - Thelia Back Office', 'Web page title OK'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','1) 1st default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','1) 2nd default rule found'); + + // Create rule + this.evaluate(function() { + $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); + return true; + }); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected.png'); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +// Test Rule updating +casper.then(function(){ + this.evaluate(function() { + $('#quantity-operator').val('>=').change(); + return true; + }); + this.sendKeys('input#quantity-value', '4'); + this.click('#constraint-save-btn'); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +casper.then(function(){ + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-added.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','2) 1st default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','2) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', ' If cart products quantity is superior or equal to 4','2) 3rd rule found'); + + // Click on Edit button + this.click('tbody#constraint-list tr:nth-child(3) .constraint-update-btn'); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); + +casper.then(function(){ + this.evaluate(function() { + $('#quantity-operator').val('==').change(); + return true; + }); + + // Removing old value +// casper.evaluate(function triggerKeyDownEvent() { +// var e = $.Event("keydown"); +// e.which = 8; +// e.keyCode = 8; +// $("#quantity-value").trigger(e); // }); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected.png'); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -// -//// Test Rule updating -//casper.then(function(){ -// this.evaluate(function() { -// $('#quantity-operator').val('>=').change(); -// return true; + this.evaluate(function() { + $("#quantity-value").val('').change(); + return true; + }); + + // Adding new value + this.sendKeys('#quantity-value', '5'); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-being-edited.png'); + this.click('#constraint-save-btn'); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); +// Check if updated rule has been saved and list refreshed +casper.then(function(){ + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-edited.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','3) 1st default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','3) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart products quantity is equal to 5','3) 3rd rule updated found'); +}); + +// Check if updated rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-edited-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','4) 1st default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','4) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart products quantity is equal to 5','4) 3rd rule updated found'); + + // Click on Delete button + this.click('tbody#constraint-list tr:nth-child(2) .constraint-delete-btn'); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); + +casper.then(function(){ + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','5) 1st default rule found'); + this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','5) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','5) 3rd rule updated found'); +}); + +// Check if updated rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-deleted-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','6) 1st default rule found'); + this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','6) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','6) 3rd rule updated found'); +}); + +// Test creating rule that won't be edited +casper.then(function(){ +// Create rule + this.evaluate(function() { + $('#category-rule').val('thelia.constraint.rule.available_for_total_amount').change(); + return true; + }); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected2.png'); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); + +// Test Rule creation +casper.then(function(){ + this.evaluate(function() { + $('#price-operator').val('<=').change(); + return true; + }); + // Removing old value +// casper.evaluate(function triggerKeyDownEvent() { +// var e = $.Event("keydown"); +// e.which = 8; +// e.keyCode = 8; +// $("input#price-value").trigger(e); // }); -// this.sendKeys('input#quantity-value', '4'); -// this.click('#constraint-save-btn'); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -// -//casper.then(function(){ -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-added.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','2) 1st default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','2) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', ' If cart products quantity is superior or equal to 4','2) 3rd rule found'); -// -// // Click on Edit button -// this.click('tbody#constraint-list tr:nth-child(3) .constraint-update-btn'); -//}); -// -//casper.wait(2000, function() { -// this.echo("\nWaiting...."); -//}); -// -//casper.then(function(){ -// this.evaluate(function() { -// $('#quantity-operator').val('==').change(); -// return true; -// }); -// -// // Removing old value -//// casper.evaluate(function triggerKeyDownEvent() { -//// var e = $.Event("keydown"); -//// e.which = 8; -//// e.keyCode = 8; -//// $("#quantity-value").trigger(e); -//// }); -// this.evaluate(function() { -// $("#quantity-value").val('').change(); -// return true; -// }); -// -// // Adding new value -// this.sendKeys('#quantity-value', '5'); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-being-edited.png'); -// this.click('#constraint-save-btn'); -//}); -// -//casper.wait(2000, function() { -// this.echo("\nWaiting...."); -//}); -//// Check if updated rule has been saved and list refreshed -//casper.then(function(){ -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-edited.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','3) 1st default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','3) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart products quantity is equal to 5','3) 3rd rule updated found'); -//}); -// -//// Check if updated rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-edited-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','4) 1st default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','4) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart products quantity is equal to 5','4) 3rd rule updated found'); -// -// // Click on Delete button -// this.click('tbody#constraint-list tr:nth-child(2) .constraint-delete-btn'); -//}); -// -//casper.wait(2000, function() { -// this.echo("\nWaiting...."); -//}); -// -//casper.then(function(){ -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','5) 1st default rule found'); -// this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','5) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','5) 3rd rule updated found'); -//}); -// -//// Check if updated rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-deleted-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','6) 1st default rule found'); -// this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','6) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','6) 3rd rule updated found'); -//}); -// -//// Test creating rule that won't be edited -//casper.then(function(){ -//// Create rule -// this.evaluate(function() { -// $('#category-rule').val('thelia.constraint.rule.available_for_total_amount').change(); -// return true; -// }); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected2.png'); -//}); -// -//casper.wait(2000, function() { -// this.echo("\nWaiting...."); -//}); -// -//// Test Rule creation -//casper.then(function(){ -// this.evaluate(function() { -// $('#price-operator').val('<=').change(); -// return true; -// }); -// // Removing old value -//// casper.evaluate(function triggerKeyDownEvent() { -//// var e = $.Event("keydown"); -//// e.which = 8; -//// e.keyCode = 8; -//// $("input#price-value").trigger(e); -//// }); -// this.evaluate(function() { -// $("input#price-value").val('').change(); -// return true; -// }); -// -// // Changing 400 to 401 -// this.sendKeys('input#price-value', '401'); -// this.evaluate(function() { -// $('#currency-value').val('GBP').change(); -// return true; -// }); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-saved-edited-before-click-save.png'); -// this.click('#constraint-save-btn'); -//}); -// -//casper.wait(2000, function() { -// this.echo("\nWaiting...."); -//}); -// -//casper.then(function(){ -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','7) 1st default rule found'); -// this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','7) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','7) 3rd rule updated found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart total amount is inferior or equal to 401 GBP','7) 4rd rule created found'); -//}); -// -//// Check if created rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-added-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','8) 1st default rule found'); -// this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','8) 2nd default rule found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','8) 3rd rule updated found'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart total amount is inferior or equal to 401 GBP','8) 4rd rule created found'); -//}); -// -//// Testing deleting all rules -//casper.then(function(){ -//// Click on Delete button -// this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); -//}); -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -//casper.then(function(){ -//// Click on Delete button -// this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); -//}); -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -//casper.then(function(){ -//// Click on Delete button -// this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); -//}); -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -//casper.then(function(){ -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','9) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -//// Check if created rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','10) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -// -//// Test add no condition rule -//casper.then(function(){ -// this.evaluate(function() { -// $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); -// return true; -// }); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -// -//// Test Rule updating -//casper.then(function(){ -// this.evaluate(function() { -// $('#quantity-operator').val('>').change(); -// return true; -// }); -// this.sendKeys('input#quantity-value', '4'); -// this.click('#constraint-save-btn'); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -// -//casper.then(function(){ -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart products quantity is superior to 4', '11) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -//// Check if created rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart products quantity is superior to 4','12) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -//casper.then(function(){ -// this.evaluate(function() { -// $('#category-rule').val('thelia.constraint.rule.available_for_everyone').change(); -// return true; -// }); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -// -//// Test Rule updating -//casper.then(function(){ -// this.click('#constraint-save-btn'); -//}); -// -//casper.wait(1000, function() { -// this.echo("\nWaiting...."); -//}); -//casper.then(function(){ -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','13) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -//// Check if created rule has been well saved -//casper.thenOpen(thelia2_login_coupon_update_url, function() { -// this.test.assertHttpStatus(200); -// this.test.comment('Now on : ' + this.getCurrentUrl()); -// this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); -// this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','14) 1st default rule found'); -// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); -//}); -// -////RUN -//casper.run(function() { -// this.test.done(); -//}); \ No newline at end of file + this.evaluate(function() { + $("input#price-value").val('').change(); + return true; + }); + + // Changing 400 to 401 + this.sendKeys('input#price-value', '401'); + this.evaluate(function() { + $('#currency-value').val('GBP').change(); + return true; + }); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-saved-edited-before-click-save.png'); + this.click('#constraint-save-btn'); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); + +casper.then(function(){ + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','7) 1st default rule found'); + this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','7) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','7) 3rd rule updated found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart total amount is inferior or equal to 401 GBP','7) 4rd rule created found'); +}); + +// Check if created rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-added-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart total amount is superior to 40 EUR','8) 1st default rule found'); + this.test.assertSelectorDoesntHaveText('tbody#constraint-list tr:nth-child(2)', 'If cart total amount is inferior to 400 EUR','8) 2nd default rule found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(2)', 'If cart products quantity is equal to 5','8) 3rd rule updated found'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(3)', 'If cart total amount is inferior or equal to 401 GBP','8) 4rd rule created found'); +}); + +// Testing deleting all rules +casper.then(function(){ +// Click on Delete button + this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); +}); +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); +casper.then(function(){ +// Click on Delete button + this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); +}); +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); +casper.then(function(){ +// Click on Delete button + this.click('tbody#constraint-list tr:nth-child(1) .constraint-delete-btn'); +}); +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); +casper.then(function(){ + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','9) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + +// Check if created rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','10) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + + +// Test add no condition rule +casper.then(function(){ + this.evaluate(function() { + $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); + return true; + }); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +// Test Rule updating +casper.then(function(){ + this.evaluate(function() { + $('#quantity-operator').val('>').change(); + return true; + }); + this.sendKeys('input#quantity-value', '4'); + this.click('#constraint-save-btn'); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +casper.then(function(){ + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart products quantity is superior to 4', '11) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + +// Check if created rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'If cart products quantity is superior to 4','12) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + +casper.then(function(){ + this.evaluate(function() { + $('#category-rule').val('thelia.constraint.rule.available_for_everyone').change(); + return true; + }); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +// Test Rule updating +casper.then(function(){ + this.click('#constraint-save-btn'); +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); +casper.then(function(){ + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','13) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + +// Check if created rule has been well saved +casper.thenOpen(thelia2_login_coupon_update_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-all-deleted-refreshed.png'); + this.test.assertSelectorHasText('tbody#constraint-list tr:nth-child(1)', 'No conditions','14) 1st default rule found'); + test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); +}); + +//RUN +casper.run(function() { + this.test.done(); +}); \ No newline at end of file From 73c0a96979501b5c9a3f44e4dd69e6aed824954f Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 23:05:46 +0200 Subject: [PATCH 03/27] WIP : Coupon : unit tests on Operator --- .../Tests/Constraint/Rule/OperatorsTest.php | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php index 0b29baa62..d5a340d2b 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon; -use Thelia\Constraint\Validator\QuantityParam; use Thelia\Constraint\Rule\Operators; /** @@ -48,14 +47,58 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase { } - public function testSomething() +// public function testSomething() +// { +// // Stop here and mark this test as incomplete. +// $this->markTestIncomplete( +// 'This test has not been implemented yet.' +// ); +// } + + public function testOperatorI18n() { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $stubTranslator = $this->getMockBuilder('\Symfony\Component\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnCallback((array($this, 'callbackI18n')))); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); + $expected = 'inferior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); + $expected = 'inferior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::EQUAL); + $expected = 'equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL); + $expected = 'superior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); + $expected = 'superior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); + $expected = 'different from'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::IN); + $expected = 'in'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::OUT); + $expected = 'not in'; + $this->assertEquals($expected, $actual); } + // /** // * // * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator @@ -424,4 +467,11 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase { } + function callbackI18n() { + $args = func_get_args(); + + return $args[0]; + } } + + From ad48823b4819fdfe0a7a615fce8fabd38b9a991a Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 23:51:47 +0200 Subject: [PATCH 04/27] WIP : Coupon : unit tests on Rules --- ...=> AvailableForTotalAmountManagerTest.php} | 259 +++++++++++------- ...p => AvailableForXArticlesManagerTest.php} | 122 +++++---- .../Tests/Constraint/Rule/OperatorsTest.php | 4 + 3 files changed, 236 insertions(+), 149 deletions(-) rename core/lib/Thelia/Tests/Constraint/Rule/{AvailableForTotalAmountTest.php => AvailableForTotalAmountManagerTest.php} (78%) rename core/lib/Thelia/Tests/Constraint/Rule/{AvailableForXArticlesTest.php => AvailableForXArticlesManagerTest.php} (89%) diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php similarity index 78% rename from core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php rename to core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php index c3f7249df..4ad790a5b 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php @@ -26,19 +26,20 @@ namespace Thelia\Coupon; use Thelia\Constraint\ConstraintValidator; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\Operators; +use Thelia\Exception\InvalidRuleValueException; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test AvailableForTotalAmount Class + * Unit Test AvailableForTotalAmountManager Class * * @package Constraint * @author Guillaume MOREL * */ -class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase +class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase { /** @var CouponAdapterInterface $stubTheliaAdapter */ protected $stubTheliaAdapter = null; @@ -49,108 +50,168 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ -// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + } -// /** -// * Generate valid CouponBaseAdapter -// * -// * @param float $cartTotalPrice Total amount of the current Cart -// * -// * @return CouponAdapterInterface -// */ -// protected function generateValidCouponBaseAdapterMock($cartTotalPrice = 421.23) -// { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ -// $stubTheliaAdapter = $this->getMock( -// 'Thelia\Coupon\CouponBaseAdapter', -// array('getCartTotalPrice'), -// array() -// ); -// $stubTheliaAdapter->expects($this->any()) -// ->method('getCartTotalPrice') -// ->will($this->returnValue($cartTotalPrice)); -// -// return $stubTheliaAdapter; -// } + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidRuleOperatorException + * + */ + public function testInValidBackOfficeInputOperator() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput -// * -// */ -// public function testValidBackOfficeInput() -// { -// $adapter = new CouponBaseAdapter(); -// -// $validators = array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// new PriceParam( -// $adapter, 421.23, 'EUR' -// ) -// ) -// ); -// $rule = new AvailableForTotalAmount($adapter, $validators); -// -// $expected = true; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(399)); + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleOperatorException -// * -// */ -// public function testInValidBackOfficeInputOperator() -// { -// $adapter = new CouponBaseAdapter(); -// -// $validators = array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// 'X', -// new PriceParam( -// $adapter, 421.23, 'EUR' -// ) -// ) -// ); -// -// $rule = new AvailableForTotalAmount($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } + $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $operators = array( + AvailableForTotalAmountManager::INPUT1 => Operators::IN, + AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + AvailableForTotalAmountManager::INPUT1 => '400', + AvailableForTotalAmountManager::INPUT2 => 'EUR'); + $rule1->setValidatorsFromForm($operators, $values); -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput -// * @expectedException \ErrorException -// * -// */ -// public function testInValidBackOfficeInputValue() -// { -// $adapter = $this->generateValidCouponBaseAdapterMock(); -// -// $validators = array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// 421 -// ) -// ); -// -// $rule = new AvailableForTotalAmount($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidRuleOperatorException + * + */ + public function testInValidBackOfficeInputOperator2() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(399)); + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $operators = array( + AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + AvailableForTotalAmountManager::INPUT2 => Operators::INFERIOR + ); + $values = array( + AvailableForTotalAmountManager::INPUT1 => '400', + AvailableForTotalAmountManager::INPUT2 => 'EUR'); + $rule1->setValidatorsFromForm($operators, $values); + + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidRuleValueException + * + */ + public function testInValidBackOfficeInputValue() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(399)); + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $operators = array( + AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + AvailableForTotalAmountManager::INPUT1 => 'X', + AvailableForTotalAmountManager::INPUT2 => 'EUR'); + $rule1->setValidatorsFromForm($operators, $values); + + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidRuleValueException + * + */ + public function testInValidBackOfficeInputValue2() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(399)); + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $operators = array( + AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + AvailableForTotalAmountManager::INPUT1 => 400, + AvailableForTotalAmountManager::INPUT2 => 'FLA'); + $rule1->setValidatorsFromForm($operators, $values); + + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } /** * Check if test inferior operator is working diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php similarity index 89% rename from core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php rename to core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php index 4ecbcb8ac..12deb34b8 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php @@ -33,13 +33,13 @@ use Thelia\Constraint\Rule\SerializableRule; * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test AvailableForXArticles Class + * Unit Test AvailableForXArticlesManager Class * * @package Constraint * @author Guillaume MOREL * */ -class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase +class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase { // /** @var CouponAdapterInterface $stubTheliaAdapter */ @@ -51,30 +51,8 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ -// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - } -// /** -// * Generate valid CouponBaseAdapter -// * -// * @param int $nbArticlesInCart Total articles in the current Cart -// * -// * @return CouponAdapterInterface -// */ -// protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4) -// { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ -// $stubTheliaAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') -// ->disableOriginalConstructor() -// ->setMethods(array('getNbArticlesInCart')) -// ->getMock(); -// $stubTheliaAdapter->expects($this->any()) -// ->method('getNbArticlesInCart') -// ->will($this->returnValue($nbArticlesInCart)); -// -// return $stubTheliaAdapter; -// } + } // /** // * Check if validity test on BackOffice inputs are working @@ -100,31 +78,75 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase // $this->assertEquals($expected, $actual); // } -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleValueException -// */ -// public function testInValidBackOfficeInputFloat() -// { -// $adapter = $this->stubTheliaAdapter; -// -// $validators = array( -// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( -// Operators::SUPERIOR, -// new QuantityParam( -// $adapter, -// 4.5 -// ) -// ) -// ); -// $rule = new AvailableForXArticles($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @expectedException \Thelia\Exception\InvalidRuleOperatorException + */ + public function testInValidBackOfficeInputOperator() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getNbArticlesInCart') + ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $rule1 = new AvailableForXArticlesManager($stubAdapter); + $operators = array( + AvailableForXArticlesManager::INPUT1 => Operators::IN + ); + $values = array( + AvailableForXArticlesManager::INPUT1 => 5 + ); + $rule1->setValidatorsFromForm($operators, $values); + + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @expectedException \Thelia\Exception\InvalidRuleValueException + */ + public function testInValidBackOfficeInputValue() + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getNbArticlesInCart') + ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $rule1 = new AvailableForXArticlesManager($stubAdapter); + $operators = array( + AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + ); + $values = array( + AvailableForXArticlesManager::INPUT1 => 'X' + ); + $rule1->setValidatorsFromForm($operators, $values); + + $isValid = $rule1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } // /** // * Check if validity test on BackOffice inputs are working diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php index d5a340d2b..6cdcb3430 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php @@ -96,6 +96,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase $actual = Operators::getI18n($stubTranslator, Operators::OUT); $expected = 'not in'; $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, 'unexpected operator'); + $expected = 'unexpected operator'; + $this->assertEquals($expected, $actual); } From a7ef4300aa16ba189a9d383ed1d2f2ba5f8c374b Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 23:56:31 +0200 Subject: [PATCH 05/27] WIP : Coupon : unit tests on Rules --- .../Rule/AvailableForTotalAmountManager.php | 12 +-- .../Rule/AvailableForXArticlesManager.php | 9 ++- core/lib/Thelia/Constraint/Rule/Operators.php | 56 ------------- .../Rule/AvailableForXArticlesManagerTest.php | 80 +------------------ 4 files changed, 13 insertions(+), 144 deletions(-) diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php index 30bc86ad6..d8a4755f6 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php @@ -111,8 +111,8 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for price field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'price' ); } @@ -121,15 +121,15 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT2] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for currency field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'price' ); } $floatType = new FloatType(); if (!$floatType->isValid($priceValue) || $priceValue <= 0) { - throw new \InvalidArgumentException( - 'Value for price field is not legit' + throw new InvalidRuleValueException( + get_class(), 'price' ); } diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php b/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php index 572d39b1d..f73d5e2be 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php @@ -30,6 +30,7 @@ use Thelia\Constraint\Validator\QuantityParam; use Thelia\Constraint\Validator\RuleValidator; use Thelia\Coupon\CouponAdapterInterface; use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidRuleOperatorException; use Thelia\Exception\InvalidRuleValueException; use Thelia\Type\FloatType; @@ -98,14 +99,14 @@ class AvailableForXArticlesManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for quantity field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'quantity' ); } if ((int) $quantityValue <= 0) { - throw new \InvalidArgumentException( - 'Value for quantity field is not legit' + throw new InvalidRuleValueException( + get_class(), 'quantity' ); } diff --git a/core/lib/Thelia/Constraint/Rule/Operators.php b/core/lib/Thelia/Constraint/Rule/Operators.php index 2ed5c2909..a6c457c75 100644 --- a/core/lib/Thelia/Constraint/Rule/Operators.php +++ b/core/lib/Thelia/Constraint/Rule/Operators.php @@ -56,62 +56,6 @@ abstract class Operators /** Param1 is not in Param2 */ CONST OUT = 'out'; -// /** -// * Check if a parameter is valid against a ComparableInterface from its operator -// * -// * @param mixed $a Parameter to validate -// * @param string $operator Operator to validate against -// * @param ComparableInterface $b Comparable to validate against -// * -// * @return bool -// */ -// public static function isValid($a, $operator, ComparableInterface $b) -// { -// $ret = false; -// -// try { -// $comparison = $b->compareTo($a); -// } catch (\Exception $e) { -// return false; -// } -// -// switch ($operator) { -// case self::INFERIOR: -// if ($comparison == 1) { -// return true; -// } -// break; -// case self::INFERIOR_OR_EQUAL: -// if ($comparison == 1 || $comparison == 0) { -// return true; -// } -// break; -// case self::EQUAL: -// if ($comparison == 0) { -// return true; -// } -// break; -// case self::SUPERIOR_OR_EQUAL: -// if ($comparison == -1 || $comparison == 0) { -// return true; -// } -// break; -// case self::SUPERIOR: -// if ($comparison == -1) { -// return true; -// } -// break; -// case self::DIFFERENT: -// if ($comparison != 0) { -// return true; -// } -// break; -// default: -// } -// -// return $ret; -// } - /** * Get operator translation * diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php index 12deb34b8..4937826b6 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php @@ -54,34 +54,10 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase } -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * -// */ -// public function testValidBackOfficeInput() -// { -// $translator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $rule = new AvailableForXArticles($translator); -// $operators = array(AvailableForXArticles::PARAM1_QUANTITY => Operators::SUPERIOR); -// $values = array( -// AvailableForXArticles::PARAM1_QUANTITY => 4 -// ); -// $rule->populateFromForm($operators, $values); -// -// $expected = true; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidRuleOperatorException */ public function testInValidBackOfficeInputOperator() @@ -116,7 +92,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidRuleValueException */ public function testInValidBackOfficeInputValue() @@ -148,58 +124,6 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleValueException -// */ -// public function testInValidBackOfficeInputNegative() -// { -// $adapter = $this->stubTheliaAdapter; -// -// $validators = array( -// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( -// Operators::SUPERIOR, -// new QuantityParam( -// $adapter, -// -1 -// ) -// ) -// ); -// $rule = new AvailableForXArticles($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleValueException -// */ -// public function testInValidBackOfficeInputString() -// { -// $adapter = $this->stubTheliaAdapter; -// -// $validators = array( -// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( -// Operators::SUPERIOR, -// new QuantityParam( -// $adapter, -// 'bad' -// ) -// ) -// ); -// $rule = new AvailableForXArticles($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - /** * Check if test inferior operator is working * From 3b249dc21c65bea8836a275d867b1d00d516cb4e Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 11:41:09 +0200 Subject: [PATCH 06/27] Working : Coupon : Unit testing --- .../Rule/AvailableForTotalAmountManager.php | 11 +- .../Constraint/Rule/CouponRuleAbstract.php | 51 +++ .../Controller/Admin/CouponController.php | 2 + .../Thelia/Coupon/CouponAdapterInterface.php | 7 + core/lib/Thelia/Coupon/CouponBaseAdapter.php | 15 + .../AvailableForTotalAmountManagerTest.php | 290 ++++-------------- 6 files changed, 135 insertions(+), 241 deletions(-) diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php index d8a4755f6..c4087e734 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php @@ -126,14 +126,11 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract ); } - $floatType = new FloatType(); - if (!$floatType->isValid($priceValue) || $priceValue <= 0) { - throw new InvalidRuleValueException( - get_class(), 'price' - ); - } + $this->isPriceValid($priceValue); + + + $this->IsCurrencyValid($currencyValue); - // @todo check currency is legit or not $this->operators = array( self::INPUT1 => $priceOperator, diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php index 0986daa50..ffd1eb0f3 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php @@ -31,6 +31,9 @@ use Thelia\Constraint\Validator\ComparableInterface; use Thelia\Constraint\Validator\RuleValidator; use Thelia\Exception\InvalidRuleException; use Thelia\Exception\InvalidRuleOperatorException; +use Thelia\Exception\InvalidRuleValueException; +use Thelia\Model\Currency; +use Thelia\Type\FloatType; /** * Created by JetBrains PhpStorm. @@ -268,4 +271,52 @@ abstract class CouponRuleAbstract implements CouponRuleInterface return $serializableRule; } + + /** + * Check if currency if valid or not + * + * @param string $currencyValue Currency EUR|USD|.. + * + * @return bool + * @throws \Thelia\Exception\InvalidRuleValueException + */ + protected function IsCurrencyValid($currencyValue) + { + $availableCurrencies = $this->adapter->getAvailableCurrencies(); + /** @var Currency $currency */ + $currencyFound = false; + foreach ($availableCurrencies as $key => $currency) { + if ($currencyValue == $currency->getCode()) { + $currencyFound = true; + } + } + if (!$currencyFound) { + throw new InvalidRuleValueException( + get_class(), 'currency' + ); + } + + return true; + } + + /** + * Check if price is valid + * + * @param float $priceValue Price value to check + * + * @return bool + * @throws \Thelia\Exception\InvalidRuleValueException + */ + protected function isPriceValid($priceValue) + { + $floatType = new FloatType(); + if (!$floatType->isValid($priceValue) || $priceValue <= 0) { + throw new InvalidRuleValueException( + get_class(), 'price' + ); + } + + return true; + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 6803addfd..f50c58307 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -49,7 +49,9 @@ use Thelia\Form\Exception\FormValidationException; use Thelia\Log\Tlog; use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; +use Thelia\Model\CurrencyQuery; use Thelia\Model\Lang; +use Thelia\Model\LangQuery; use Thelia\Tools\I18n; /** diff --git a/core/lib/Thelia/Coupon/CouponAdapterInterface.php b/core/lib/Thelia/Coupon/CouponAdapterInterface.php index b2c168186..413fc3df6 100644 --- a/core/lib/Thelia/Coupon/CouponAdapterInterface.php +++ b/core/lib/Thelia/Coupon/CouponAdapterInterface.php @@ -169,4 +169,11 @@ interface CouponAdapterInterface */ public function getConstraintValidator(); + /** + * Return all available currencies + * + * @return array of Currency + */ + public function getAvailableCurrencies(); + } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/CouponBaseAdapter.php b/core/lib/Thelia/Coupon/CouponBaseAdapter.php index f9fae8651..cb5162090 100644 --- a/core/lib/Thelia/Coupon/CouponBaseAdapter.php +++ b/core/lib/Thelia/Coupon/CouponBaseAdapter.php @@ -35,6 +35,8 @@ use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; use Thelia\Cart\CartTrait; use Thelia\Model\Currency; +use Thelia\Model\CurrencyQuery; +use Thelia\Model\LangQuery; /** * Created by JetBrains PhpStorm. @@ -266,4 +268,17 @@ class CouponBaseAdapter implements CouponAdapterInterface { return $this->container->get('thelia.constraint.validator'); } + + + /** + * Return all available currencies + * + * @return array of Currency + */ + public function getAvailableCurrencies() + { + $currencies = CurrencyQuery::create(); + + return $currencies->find(); + } } diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php index 4ad790a5b..a883a0712 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php @@ -27,6 +27,7 @@ use Thelia\Constraint\ConstraintValidator; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\Operators; use Thelia\Exception\InvalidRuleValueException; +use Thelia\Model\Currency; /** * Created by JetBrains PhpStorm. @@ -44,6 +45,43 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase /** @var CouponAdapterInterface $stubTheliaAdapter */ protected $stubTheliaAdapter = null; + /** + * Generate adapter stub + * + * @param int $cartTotalPrice Cart total price + * @param string $checkoutCurrency Checkout currency + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue($cartTotalPrice)); + + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue($checkoutCurrency)); + + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); + + $currency1 = new Currency(); + $currency1->setCode('EUR'); + $currency2 = new Currency(); + $currency2->setCode('USD'); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue(array($currency1, $currency2))); + + return $stubAdapter; + } + /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -62,19 +100,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputOperator() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -102,19 +128,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputOperator2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -142,19 +156,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputValue() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -182,19 +184,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputValue2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -221,19 +211,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -260,19 +238,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -299,19 +265,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -338,19 +292,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleInferiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -377,19 +319,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(401)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -416,19 +346,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -455,19 +373,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -494,19 +400,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(401)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -533,19 +427,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleSuperiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -572,19 +454,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399.00)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -611,19 +481,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(401)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -650,19 +508,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(399.00)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -689,19 +535,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleCurrency() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400.00)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -728,19 +562,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleCurrency() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400.00)); - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue('EUR')); - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + $stubAdapter = $this->generateAdapterStub(400.00, 'EUR'); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( From 5326ab1341549c1020ff4235abda6e03386d703a Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 22:54:49 +0200 Subject: [PATCH 07/27] Working : Coupon : fixture add old coupon --- install/faker.php | 57 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/install/faker.php b/install/faker.php index 66303f05a..25112d904 100755 --- a/install/faker.php +++ b/install/faker.php @@ -1,5 +1,6 @@ setIsUsed(1); $coupon1->setIsEnabled(1); $date = new \DateTime(); - $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); + $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months"))); $rule1 = new AvailableForTotalAmountManager($adapter); $operators = array( @@ -588,27 +589,18 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $rules = new CouponRuleCollection(); $rules->add($rule1); $rules->add($rule2); - /** @var ConstraintFactory $constraintFactory */ $constraintFactory = $container->get('thelia.constraint.factory'); $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon1->setSerializedRules($serializedRules); - $coupon1->setMaxUsage(40); $coupon1->setIsCumulative(1); $coupon1->setIsRemovingPostage(0); $coupon1->setIsAvailableOnSpecialOffers(1); - $coupon1->save(); - - - - - - // Coupons $coupon2 = new Thelia\Model\Coupon(); $coupon2->setCode('SPRINGBREAK'); @@ -628,7 +620,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $coupon2->setIsUsed(1); $coupon2->setIsEnabled(1); $date = new \DateTime(); - $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); + $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months"))); $rule1 = new AvailableForXArticlesManager($adapter); $operators = array( @@ -638,7 +630,6 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua AvailableForXArticlesManager::INPUT1 => 4, ); $rule1->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); $rules->add($rule1); @@ -647,11 +638,49 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon2->setSerializedRules($serializedRules); - $coupon2->setMaxUsage(-1); $coupon2->setIsCumulative(0); $coupon2->setIsRemovingPostage(1); $coupon2->setIsAvailableOnSpecialOffers(1); - $coupon2->save(); + + + // Coupons + $coupon3 = new Thelia\Model\Coupon(); + $coupon3->setCode('OLD'); + $coupon3->setType('thelia.coupon.type.remove_x_percent'); + $coupon3->setTitle('Old coupon'); + $coupon3->setShortDescription('Coupon for Springbreak removing 10% if you have more than 4 articles in your cart'); + $coupon3->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla. + +Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla. + +Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros. + +Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non. + +Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); + $coupon3->setAmount(10.00); + $coupon3->setIsUsed(1); + $coupon3->setIsEnabled(0); + $date = new \DateTime(); + $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); + + $rule1 = new AvailableForEveryoneManager($adapter); + $operators = array(); + $values = array(); + $rule1->setValidatorsFromForm($operators, $values); + $rules = new CouponRuleCollection(); + $rules->add($rule1); + + /** @var ConstraintFactory $constraintFactory */ + $constraintFactory = $container->get('thelia.constraint.factory'); + + $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); + $coupon3->setSerializedRules($serializedRules); + $coupon3->setMaxUsage(-1); + $coupon3->setIsCumulative(0); + $coupon3->setIsRemovingPostage(1); + $coupon3->setIsAvailableOnSpecialOffers(1); + $coupon3->save(); } From ce72a2007476b368f900cd18e986890d6426f453 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 23:09:55 +0200 Subject: [PATCH 08/27] Working : Coupon : fix loop --- core/lib/Thelia/Core/Template/Loop/Coupon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 4e8ca3e71..dff5e782b 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -88,8 +88,8 @@ class Coupon extends BaseI18nLoop $search->filterById($id, Criteria::IN); } - if ($isEnabled != BooleanOrBothType::ANY) { - $search->filterByIsEnabled($isEnabled ? 1 : 0); + if (isset($isEnabled)) { + $search->filterByIsEnabled($isEnabled ? true : false); } // Perform search From 542a1423298431263c72d3d0f6a835b13971c247 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 23:19:09 +0200 Subject: [PATCH 09/27] Working : Coupon : fix loop, fix read display --- core/lib/Thelia/Core/Template/Loop/Coupon.php | 2 +- install/faker.php | 8 ++++---- templates/admin/default/coupon-read.html | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index dff5e782b..063ffa397 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -63,7 +63,7 @@ class Coupon extends BaseI18nLoop { return new ArgumentCollection( Argument::createIntListTypeArgument('id'), - Argument::createBooleanOrBothTypeArgument('is_enabled', 1) + Argument::createBooleanOrBothTypeArgument('is_enabled') ); } diff --git a/install/faker.php b/install/faker.php index 94c507d02..9a1d3d480 100755 --- a/install/faker.php +++ b/install/faker.php @@ -742,7 +742,7 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon3->setAmount(10.00); - $coupon3->setIsUsed(1); + $coupon3->setIsUsed(0); $coupon3->setIsEnabled(0); $date = new \DateTime(); $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); @@ -760,8 +760,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon3->setSerializedRules($serializedRules); $coupon3->setMaxUsage(-1); - $coupon3->setIsCumulative(0); - $coupon3->setIsRemovingPostage(1); - $coupon3->setIsAvailableOnSpecialOffers(1); + $coupon3->setIsCumulative(1); + $coupon3->setIsRemovingPostage(0); + $coupon3->setIsAvailableOnSpecialOffers(0); $coupon3->save(); } diff --git a/templates/admin/default/coupon-read.html b/templates/admin/default/coupon-read.html index 4ae5e5c68..859163fc8 100755 --- a/templates/admin/default/coupon-read.html +++ b/templates/admin/default/coupon-read.html @@ -63,7 +63,11 @@ {intl l='Usage left'} - {if $USAGE_LEFT} + {if $USAGE_LEFT == -1} + + {intl l='Unlimited'} + + {elseif $USAGE_LEFT} {$USAGE_LEFT} From be665cba56d7ed3da0caf3d8d65e1ffea79625ef Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 23:25:38 +0200 Subject: [PATCH 10/27] Working : Coupon : fix loop, fix read display --- templates/admin/default/coupon-list.html | 36 ++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/templates/admin/default/coupon-list.html b/templates/admin/default/coupon-list.html index 2eafde586..a17d01e96 100755 --- a/templates/admin/default/coupon-list.html +++ b/templates/admin/default/coupon-list.html @@ -41,7 +41,23 @@ {block name="coupon-code"}{$CODE}{/block} {block name="coupon-title"}{$TITLE}{/block} {block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block} - {block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + + {block name="coupon-usage-left"} + {if $USAGE_LEFT == -1} + + {intl l='Unlimited'} + + {elseif $USAGE_LEFT} + + {$USAGE_LEFT} + + {else} + + 0 + + {/if} + {/block} + {block name="coupon-action"} @@ -77,7 +93,23 @@ {block name="coupon-code"}{$CODE}{/block} {block name="coupon-title"}{$TITLE}{/block} {block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block} - {block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + + {block name="coupon-usage-left"} + {if $USAGE_LEFT == -1} + + {intl l='Unlimited'} + + {elseif $USAGE_LEFT} + + {$USAGE_LEFT} + + {else} + + 0 + + {/if} + {/block} + {block name="coupon-action"} From b545e1c012f1d3ef609612021b34c812ca5d36a3 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 23:29:25 +0200 Subject: [PATCH 11/27] Working : Coupon : fix loop, fix read display --- core/lib/Thelia/Core/Template/Loop/Coupon.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 063ffa397..9b720ef13 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -31,13 +31,11 @@ use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Element\BaseI18nLoop; 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; - +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Coupon\Type\CouponInterface; -use Thelia\Model\CouponQuery; use Thelia\Model\Coupon as MCoupon; +use Thelia\Model\CouponQuery; use Thelia\Type; use Thelia\Type\BooleanOrBothType; From 8e308d21e99dc44a247213c74b69400400125d4c Mon Sep 17 00:00:00 2001 From: gmorel Date: Thu, 19 Sep 2013 23:25:01 +0200 Subject: [PATCH 12/27] Working : Coupon : fix update effect (becomes type), update max usage --- .../Thelia/Config/Resources/routing/admin.xml | 19 ++++++++++++------- .../Controller/Admin/CouponController.php | 7 ++++--- .../Coupon/CouponCreateOrUpdateEvent.php | 12 ++++++------ core/lib/Thelia/Form/CouponCreationForm.php | 2 +- core/lib/Thelia/Model/Coupon.php | 6 +++--- .../Thelia/Tests/Coupon/RuleOrganizerTest.php | 3 ++- templates/admin/default/assets/js/coupon.js | 17 ++++++++++++----- templates/admin/default/coupon/form.html | 18 ++++++++++-------- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index af7c950af..15e450c01 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -160,26 +160,31 @@ - + Thelia\Controller\Admin\CouponController::browseAction - + Thelia\Controller\Admin\CouponController::createAction - + Thelia\Controller\Admin\CouponController::updateAction + \d+ - + Thelia\Controller\Admin\CouponController::readAction + \d+ - + Thelia\Controller\Admin\CouponController::getRuleInputAction + .* - + Thelia\Controller\Admin\CouponController::updateRulesAction + \d+ - + Thelia\Controller\Admin\CouponController::consumeAction + .* diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f50c58307..f7804de8e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -201,7 +201,7 @@ class CouponController extends BaseAdminController $lang = $this->getSession()->getLang(); $eventToDispatch = TheliaEvents::COUPON_UPDATE; - // Create + // Update if ($this->getRequest()->isMethod('POST')) { $this->validateCreateOrUpdateForm( $i18n, @@ -210,7 +210,7 @@ class CouponController extends BaseAdminController 'updated', 'update' ); - } else { // Update + } else { // Display // Prepare the data that will hydrate the form /** @var ConstraintFactory $constraintFactory */ @@ -495,11 +495,12 @@ class CouponController extends BaseAdminController // Get the form field values $data = $form->getData(); + $couponEvent = new CouponCreateOrUpdateEvent( $data['code'], $data['title'], $data['amount'], - $data['effect'], + $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 2e004b818..e8f54fffb 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -90,7 +90,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent * @param string $code Coupon Code * @param string $title Coupon title * @param float $amount Amount removed from the Total Checkout - * @param string $effect Coupon effect + * @param string $type Coupon type * @param string $shortDescription Coupon short description * @param string $description Coupon description * @param boolean $isEnabled Enable/Disable @@ -106,7 +106,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $code, $title, $amount, - $effect, + $type, $shortDescription, $description, $isEnabled, @@ -130,7 +130,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $this->rules = $rules; $this->shortDescription = $shortDescription; $this->title = $title; - $this->effect = $effect; + $this->type = $type; $this->locale = $locale; } @@ -264,13 +264,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent } /** - * Get Coupon effect + * Get Coupon type (effect) * * @return string */ - public function getEffect() + public function getType() { - return $this->effect; + return $this->type; } /** diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 1625ab685..f3ee0df63 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -87,7 +87,7 @@ class CouponCreationForm extends BaseForm ) ) ->add( - 'effect', + 'type', 'text', array( 'constraints' => array( diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 032de412a..e40fd9078 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -54,7 +54,7 @@ class Coupon extends BaseCoupon * @param string $code Coupon Code * @param string $title Coupon title * @param float $amount Amount removed from the Total Checkout - * @param string $effect Coupon effect + * @param string $type Coupon type * @param bool $isRemovingPostage Is removing Postage * @param string $shortDescription Coupon short description * @param string $description Coupon description @@ -67,13 +67,13 @@ class Coupon extends BaseCoupon * * @throws \Exception */ - function createOrUpdate($code, $title, $amount, $effect, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null) + function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null) { $this->setCode($code) ->setTitle($title) ->setShortDescription($shortDescription) ->setDescription($description) - ->setType($effect) + ->setType($type) ->setAmount($amount) ->setIsRemovingPostage($isRemovingPostage) ->setIsEnabled($isEnabled) diff --git a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php index 3300cb19b..d13184a8c 100644 --- a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php +++ b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php @@ -23,6 +23,7 @@ namespace Thelia\Coupon; +use Thelia\Coupon\RuleOrganizer; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 @@ -47,7 +48,7 @@ class RuleOrganizerTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->object = new RuleOrganizer; + $this->object = new RuleOrganizer(); } /** diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 41e0c1430..dae26d4b4 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -138,17 +138,24 @@ $(function($){ // Set max usage to unlimited or not couponManager.onUsageUnlimitedChange = function() { - if (!$('#max-usage').parent().hasClass('has-error')) { - $('#max-usage').hide().attr('value', '-1'); + var isUnlimited = $('#is-unlimited'); + if ($('#max-usage').val() == -1) { + isUnlimited.prop('checked', true); + $('#max-usage').hide(); $('#max-usage-label').hide(); + } else { + $isUnlimited.prop('checked', false); + $('#max-usage').show(); + $('#max-usage-label').show(); } - $('#is-unlimited').change(function(){ + + isUnlimited.change(function(){ var $this = $(this); if ($this.is(':checked')) { - $('#max-usage').hide().attr('value', '-1'); + $('#max-usage').hide().val('-1'); $('#max-usage-label').hide(); } else { - $('#max-usage').show().val('').attr('value', ''); + $('#max-usage').show().val(''); $('#max-usage-label').show(); } }); diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index a4ec8b14a..68c74bee2 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -88,11 +88,11 @@
- + {if $error}{$message}{/if}
{/form_field} @@ -101,17 +101,19 @@
- {form_field form=$form field='effect'} + {form_field form=$form field='type'}
- - + {foreach from=$availableCoupons item=availableCoupon} - + {/foreach} {if $error}{$message}{/if} - {$availableCoupons.0.toolTip} + {$availableCoupons.0.toolTip}
{/form_field}
From d0f20cca1d5b3d9a4e49a86a7df0145d39cceaa9 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 23 Sep 2013 23:04:00 +0200 Subject: [PATCH 13/27] Working : coupon creation : add default rule (thelia.constraint.rule.available_for_everyone) --- core/lib/Thelia/Action/Coupon.php | 16 ++- core/lib/Thelia/Action/Image.php | 2 +- .../Controller/Admin/CouponController.php | 41 ++------ .../Coupon/CouponCreateOrUpdateEvent.php | 63 +++--------- core/lib/Thelia/Model/Coupon.php | 8 +- templates/admin/default/admin-layout.tpl | 2 +- templates/admin/default/assets/js/coupon.js | 99 ++++++++++--------- templates/admin/default/coupon-create.html | 2 +- templates/admin/default/coupon-list.html | 42 +++++++- templates/admin/default/coupon-read.html | 8 +- templates/admin/default/coupon-update.html | 18 ++-- templates/admin/default/coupon/form.html | 9 +- 12 files changed, 154 insertions(+), 156 deletions(-) diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 036502c68..c1affe633 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -32,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Core\HttpFoundation\Request; use Thelia\Coupon\CouponFactory; use Thelia\Coupon\CouponManager; +use Thelia\Coupon\CouponRuleCollection; use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon as CouponModel; @@ -137,11 +138,21 @@ class Coupon extends BaseAction implements EventSubscriberInterface { $coupon->setDispatcher($this->getDispatcher()); + // Set default rule if none found + $noConditionRule = $this->container->get('thelia.constraint.rule.available_for_everyone'); + $constraintFactory = $this->container->get('thelia.constraint.factory'); + $couponRuleCollection = new CouponRuleCollection(); + $couponRuleCollection->add($noConditionRule); + $defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection( + $couponRuleCollection + ); + + $coupon->createOrUpdate( $event->getCode(), $event->getTitle(), $event->getAmount(), - $event->getEffect(), + $event->getType(), $event->isRemovingPostage(), $event->getShortDescription(), $event->getDescription(), @@ -150,9 +161,12 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->isAvailableOnSpecialOffers(), $event->isCumulative(), $event->getMaxUsage(), + $defaultSerializedRule, $event->getLocale() ); + + $event->setCoupon($coupon); } diff --git a/core/lib/Thelia/Action/Image.php b/core/lib/Thelia/Action/Image.php index 4660f93b8..ba5ee153f 100755 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -229,7 +229,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface // Compute the image URL $processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath)); - // compute the full resulution image path in cache + // compute the full resolution image path in cache $original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache)); // Update the event with file path and file URL diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f7804de8e..1c7b1c603 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -78,13 +78,13 @@ class CouponController extends BaseAdminController $args['urlReadCoupon'] = $this->getRoute( 'admin.coupon.read', - array('couponId' => 'couponId'), + array('couponId' => 0), Router::ABSOLUTE_URL ); $args['urlEditCoupon'] = $this->getRoute( 'admin.coupon.update', - array('couponId' => 'couponId'), + array('couponId' => 0), Router::ABSOLUTE_URL ); @@ -164,7 +164,7 @@ class CouponController extends BaseAdminController $args['dateFormat'] = $this->getSession()->getLang()->getDateFormat(); $args['availableCoupons'] = $this->getAvailableCoupons(); - $args['formAction'] = 'admin/coupon/create/'; + $args['formAction'] = 'admin/coupon/create'; return $this->render( 'coupon-create', @@ -223,7 +223,7 @@ class CouponController extends BaseAdminController 'code' => $coupon->getCode(), 'title' => $coupon->getTitle(), 'amount' => $coupon->getAmount(), - 'effect' => $coupon->getType(), + 'type' => $coupon->getType(), 'shortDescription' => $coupon->getShortDescription(), 'description' => $coupon->getDescription(), 'isEnabled' => ($coupon->getIsEnabled() == 1), @@ -271,7 +271,7 @@ class CouponController extends BaseAdminController Router::ABSOLUTE_URL ); - $args['formAction'] = 'admin/coupon/update/' . $couponId; + $args['formAction'] = 'admin/coupon/update' . $couponId; return $this->render('coupon-update', $args); } @@ -347,20 +347,7 @@ class CouponController extends BaseAdminController ); $couponEvent = new CouponCreateOrUpdateEvent( - $coupon->getCode(), - $coupon->getTitle(), - $coupon->getAmount(), - $coupon->getType(), - $coupon->getShortDescription(), - $coupon->getDescription(), - $coupon->getIsEnabled(), - $coupon->getExpirationDate(), - $coupon->getIsAvailableOnSpecialOffers(), - $coupon->getIsCumulative(), - $coupon->getIsRemovingPostage(), - $coupon->getMaxUsage(), - $rules, - $coupon->getLocale() + $coupon->getCode(), $coupon->getTitle(), $coupon->getAmount(), $coupon->getType(), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), $coupon->getExpirationDate(), $coupon->getIsAvailableOnSpecialOffers(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getMaxUsage(), $coupon->getLocale() ); $couponEvent->setCoupon($coupon); @@ -497,20 +484,7 @@ class CouponController extends BaseAdminController $data = $form->getData(); $couponEvent = new CouponCreateOrUpdateEvent( - $data['code'], - $data['title'], - $data['amount'], - $data['type'], - $data['shortDescription'], - $data['description'], - $data['isEnabled'], - \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), - $data['isAvailableOnSpecialOffers'], - $data['isCumulative'], - $data['isRemovingPostage'], - $data['maxUsage'], - new CouponRuleCollection(array()), - $data['locale'] + $data['code'], $data['title'], $data['amount'], $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale'] ); // Dispatch Event to the Action @@ -538,7 +512,6 @@ class CouponController extends BaseAdminController } catch (FormValidationException $e) { // Invalid data entered $message = 'Please check your input:'; - $this->logError($action, $message, $e); } catch (\Exception $e) { // Any other error diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index e8f54fffb..4b85065dc 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -78,8 +78,8 @@ class CouponCreateOrUpdateEvent extends ActionEvent /** @var Coupon Coupon model */ protected $coupon = null; - /** @var string Coupon effect */ - protected $effect; + /** @var string Coupon type */ + protected $type; /** @var string Language code ISO (ex: fr_FR) */ protected $locale = null; @@ -87,36 +87,22 @@ class CouponCreateOrUpdateEvent extends ActionEvent /** * Constructor * - * @param string $code Coupon Code - * @param string $title Coupon title - * @param float $amount Amount removed from the Total Checkout - * @param string $type Coupon type - * @param string $shortDescription Coupon short description - * @param string $description Coupon description - * @param boolean $isEnabled Enable/Disable - * @param \DateTime $expirationDate Coupon expiration date - * @param boolean $isAvailableOnSpecialOffers Is available on special offers - * @param boolean $isCumulative Is cumulative - * @param boolean $isRemovingPostage Is removing Postage - * @param int $maxUsage Coupon quantity - * @param CouponRuleCollection $rules CouponRuleInterface to add - * @param string $locale Coupon Language code ISO (ex: fr_FR) + * @param string $code Coupon Code + * @param string $title Coupon title + * @param float $amount Amount removed from the Total Checkout + * @param string $type Coupon type + * @param string $shortDescription Coupon short description + * @param string $description Coupon description + * @param boolean $isEnabled Enable/Disable + * @param \DateTime $expirationDate Coupon expiration date + * @param boolean $isAvailableOnSpecialOffers Is available on special offers + * @param boolean $isCumulative Is cumulative + * @param boolean $isRemovingPostage Is removing Postage + * @param int $maxUsage Coupon quantity + * @param string $locale Coupon Language code ISO (ex: fr_FR) */ public function __construct( - $code, - $title, - $amount, - $type, - $shortDescription, - $description, - $isEnabled, - \DateTime $expirationDate, - $isAvailableOnSpecialOffers, - $isCumulative, - $isRemovingPostage, - $maxUsage, - $rules, - $locale + $code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale ) { $this->amount = $amount; $this->code = $code; @@ -127,7 +113,6 @@ class CouponCreateOrUpdateEvent extends ActionEvent $this->isEnabled = $isEnabled; $this->isRemovingPostage = $isRemovingPostage; $this->maxUsage = $maxUsage; - $this->rules = $rules; $this->shortDescription = $shortDescription; $this->title = $title; $this->type = $type; @@ -206,22 +191,6 @@ class CouponCreateOrUpdateEvent extends ActionEvent return $this->amount; } - /** - * Return condition to validate the Coupon or not - * - * @return CouponRuleCollection - */ - public function getRules() - { - if ($this->rules === null || !is_object($this->rules)) { - $rules = $this->rules; - } else { - $rules = clone $this->rules; - } - - return $rules; - } - /** * Return Coupon expiration date * diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index e40fd9078..d25c48354 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -63,11 +63,12 @@ class Coupon extends BaseCoupon * @param boolean $isAvailableOnSpecialOffers Is available on special offers * @param boolean $isCumulative Is cumulative * @param int $maxUsage Coupon quantity + * @param string $defaultSerializedRule Serialized default rule added if none found * @param string $locale Coupon Language code ISO (ex: fr_FR) * * @throws \Exception */ - function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null) + function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) { $this->setCode($code) ->setTitle($title) @@ -82,6 +83,11 @@ class Coupon extends BaseCoupon ->setIsCumulative($isCumulative) ->setMaxUsage($maxUsage); + // If no rule given, set default rule + if (null === $this->getSerializedRules()) { + $this->setSerializedRules($defaultSerializedRule); + } + // Set object language (i18n) if (!is_null($locale)) { $this->setLocale($locale); diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index 553466def..2dbf87a46 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -147,7 +147,7 @@ {loop name="menu-auth-coupon" type="auth" roles="ADMIN" permissions="admin.coupon.view"}
  • - {intl l="Coupons"} + {intl l="Coupons"}
  • {/loop} diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index dae26d4b4..089db5ef2 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -1,5 +1,17 @@ $(function($){ + // Manage how coupon and rules are saved + $.couponManager = {}; + // Rule to be saved + $.couponManager.ruleToSave = {}; + $.couponManager.ruleToSave.serviceId = false; + $.couponManager.ruleToSave.operators = {}; + $.couponManager.ruleToSave.values = {}; + // Rules payload to save + $.couponManager.rulesToSave = []; + // Rule being updated id + $.couponManager.ruleToUpdateId = false; + // Clean array from deleteValue (undefined) keys Array.prototype.clean = function(deleteValue) { for (var i = 0; i < this.length; i++) { @@ -12,109 +24,109 @@ $(function($){ }; // Remove 1 Rule then Save Rules AJAX - couponManager.removeRuleAjax = function(id) { + $.couponManager.removeRuleAjax = function(id) { // Delete rule in temporary array - delete couponManager.rulesToSave[id]; - couponManager.rulesToSave.clean(undefined); + delete $.couponManager.rulesToSave[id]; + $.couponManager.rulesToSave.clean(undefined); // Save - couponManager.saveRuleAjax(); + $.couponManager.saveRuleAjax(); }; // Add 1 Rule / or update the temporary Rules array then Save Rules via AJAX - couponManager.createOrUpdateRuleAjax = function() { - var id = couponManager.ruleToUpdateId; + $.couponManager.createOrUpdateRuleAjax = function() { + var id = $.couponManager.ruleToUpdateId; // If create if(!id) { - couponManager.rulesToSave.push(couponManager.ruleToSave); + $.couponManager.rulesToSave.push($.couponManager.ruleToSave); } else { // else update - couponManager.rulesToSave[id] = couponManager.ruleToSave; + $.couponManager.rulesToSave[id] = $.couponManager.ruleToSave; // reset edit mode to off - couponManager.ruleToUpdateId = false; + $.couponManager.ruleToUpdateId = false; } // Save - couponManager.saveRuleAjax(); + $.couponManager.saveRuleAjax(); }; // Set rule inputs to allow editing - couponManager.updateRuleSelectAjax = function(id) { - couponManager.ruleToUpdateId = id; - couponManager.ruleToSave = couponManager.rulesToSave[id]; + $.couponManager.updateRuleSelectAjax = function(id) { + $.couponManager.ruleToUpdateId = id; + $.couponManager.ruleToSave = $.couponManager.rulesToSave[id]; // Set the rule selector $("#category-rule option").filter(function() { - return $(this).val() == couponManager.ruleToSave.serviceId; + return $(this).val() == $.couponManager.ruleToSave.serviceId; }).prop('selected', true); // Force rule input refresh - couponManager.loadRuleInputs(couponManager.ruleToSave.serviceId, function() { - couponManager.fillInRuleInputs(); + $.couponManager.loadRuleInputs($.couponManager.ruleToSave.serviceId, function() { + $.couponManager.fillInRuleInputs(); }); }; // Fill in rule inputs - couponManager.fillInRuleInputs = function() { + $.couponManager.fillInRuleInputs = function() { var operatorId = null; var valueId = null; var idName = null; - var id = couponManager.ruleToUpdateId; + var id = $.couponManager.ruleToUpdateId; if(id) { - couponManager.ruleToSave = couponManager.rulesToSave[id]; + $.couponManager.ruleToSave = $.couponManager.rulesToSave[id]; } - for (idName in couponManager.ruleToSave.operators) { + for (idName in $.couponManager.ruleToSave.operators) { // Setting idName operator select operatorId = idName + '-operator'; - $('#' + operatorId).val(couponManager.ruleToSave.operators[idName]); + $('#' + operatorId).val($.couponManager.ruleToSave.operators[idName]); // Setting idName value input valueId = idName + '-value'; - $('#' + valueId).val(couponManager.ruleToSave.values[idName]); + $('#' + valueId).val($.couponManager.ruleToSave.values[idName]); } }; // Save rules on click - couponManager.onClickSaveRule = function() { + $.couponManager.onClickSaveRule = function() { $('#constraint-save-btn').on('click', function () { if($('#category-rule').val() == 'thelia.constraint.rule.available_for_everyone') { // @todo translate + modal var r= confirm("Do you really want to set this coupon available to everyone ?"); if (r == true) { - couponManager.createOrUpdateRuleAjax(); + $.couponManager.createOrUpdateRuleAjax(); } } }); }; - couponManager.onClickSaveRule(); + $.couponManager.onClickSaveRule(); // Remove rule on click - couponManager.onClickDeleteRule = function() { + $.couponManager.onClickDeleteRule = function() { $('.constraint-delete-btn').on('click', function (e) { e.preventDefault(); var $this = $(this); - couponManager.removeRuleAjax($this.attr('data-int')); + $.couponManager.removeRuleAjax($this.attr('data-int')); }); }; - couponManager.onClickDeleteRule(); + $.couponManager.onClickDeleteRule(); // Update rule on click - couponManager.onClickUpdateRule = function() { + $.couponManager.onClickUpdateRule = function() { $('.constraint-update-btn').on('click', function (e) { e.preventDefault(); var $this = $(this); - couponManager.updateRuleSelectAjax($this.attr('data-int')); + $.couponManager.updateRuleSelectAjax($this.attr('data-int')); // Hide row being updated $this.parent().parent().remove(); }); }; - couponManager.onClickUpdateRule(); + $.couponManager.onClickUpdateRule(); // Reload effect inputs when changing effect - couponManager.onEffectChange = function() { + $.couponManager.onEffectChange = function() { var optionSelected = $("option:selected", this); $('#effectToolTip').html(optionSelected.attr("data-description")); $('#effect').on('change', function () { @@ -122,22 +134,22 @@ $(function($){ $('#effectToolTip').html(optionSelected.attr("data-description")); }); }; - couponManager.onEffectChange(); + $.couponManager.onEffectChange(); // Reload rule inputs when changing effect - couponManager.onRuleChange = function() { + $.couponManager.onRuleChange = function() { $('#category-rule').on('change', function () { - couponManager.loadRuleInputs($(this).val(), function() {}); + $.couponManager.loadRuleInputs($(this).val(), function() {}); }); }; - couponManager.onRuleChange(); + $.couponManager.onRuleChange(); // Fill in ready to be saved rule array // var onInputsChange = function() // In AJAX response // Set max usage to unlimited or not - couponManager.onUsageUnlimitedChange = function() { + $.couponManager.onUsageUnlimitedChange = function() { var isUnlimited = $('#is-unlimited'); if ($('#max-usage').val() == -1) { isUnlimited.prop('checked', true); @@ -160,20 +172,9 @@ $(function($){ } }); }; - couponManager.onUsageUnlimitedChange(); + $.couponManager.onUsageUnlimitedChange(); }); -// Rule to save -var couponManager = {}; -// Rule to be saved -couponManager.ruleToSave = {}; -couponManager.ruleToSave.serviceId = false; -couponManager.ruleToSave.operators = {}; -couponManager.ruleToSave.values = {}; -// Rules payload to save -couponManager.rulesToSave = []; -// Rule being updated id -couponManager.ruleToUpdateId = false; diff --git a/templates/admin/default/coupon-create.html b/templates/admin/default/coupon-create.html index f8a0411e1..4b23ca118 100755 --- a/templates/admin/default/coupon-create.html +++ b/templates/admin/default/coupon-create.html @@ -8,7 +8,7 @@ diff --git a/templates/admin/default/coupon-list.html b/templates/admin/default/coupon-list.html index 3abc9268d..07e7420db 100755 --- a/templates/admin/default/coupon-list.html +++ b/templates/admin/default/coupon-list.html @@ -8,7 +8,7 @@ @@ -39,13 +39,29 @@ {loop type="coupon" name="list_coupon" is_enabled="1" backend_context="true"} - {block name="coupon-code"}{$CODE}{/block} + {block name="coupon-code"}{$CODE}{/block} {block name="coupon-title"}{$TITLE}{/block} {block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block} - {block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + + {block name="coupon-usage-left"} + {if $USAGE_LEFT == -1} + + {intl l="Unlimited"} + + {elseif $USAGE_LEFT} + + {$USAGE_LEFT} + + {else} + + 0 + + {/if} + {/block} + {block name="coupon-action"} - + {intl l='Edit'} {/block} @@ -80,7 +96,23 @@ {block name="coupon-code"}{$CODE}{/block} {block name="coupon-title"}{$TITLE}{/block} {block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block} - {block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + + {block name="coupon-usage-left"} + {if $USAGE_LEFT == -1} + + {intl l="Unlimited"} + + {elseif $USAGE_LEFT} + + {$USAGE_LEFT} + + {else} + + 0 + + {/if} + {/block} + {block name="coupon-action"} diff --git a/templates/admin/default/coupon-read.html b/templates/admin/default/coupon-read.html index 8f14dd44f..aa0bfc5a1 100755 --- a/templates/admin/default/coupon-read.html +++ b/templates/admin/default/coupon-read.html @@ -8,7 +8,7 @@ @@ -64,7 +64,11 @@ {intl l='Usage left'} - {if $USAGE_LEFT} + {if $USAGE_LEFT == -1} + + {intl l="Unlimited"} + + {elseif $USAGE_LEFT} {$USAGE_LEFT} diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index 0902dae4c..8ef58f271 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -8,7 +8,7 @@ @@ -48,7 +48,7 @@ miniBrowser(0, '/test_to_remove/datas_coupon_edit.json'); // Init Rules - couponManager.initRules = function() { + $.couponManager.initRules = function() { var rules = []; {foreach from=$rulesObject key=k item=rule} // Init rule @@ -70,13 +70,13 @@ }; // Save Rules AJAX - couponManager.saveRuleAjax = function() { + $.couponManager.saveRuleAjax = function() { $('#constraint-add-operators-values').html('
    '); var $url = '{$urlAjaxUpdateRules}'; $.ajax({ type: "POST", url: $url, - data: {literal}{{/literal}rules:JSON.stringify(couponManager.rulesToSave){literal}}{/literal}, + data: {literal}{{/literal}rules:JSON.stringify($.couponManager.rulesToSave){literal}}{/literal}, statusCode: { 404: function() { $('#constraint-add-operators-values').html( @@ -92,13 +92,13 @@ return $(this).val() == 'thelia.constraint.rule.available_for_everyone'; }).prop('selected', true); - couponManager.onClickUpdateRule(); - couponManager.onClickDeleteRule(); + $.couponManager.onClickUpdateRule(); + $.couponManager.onClickDeleteRule(); }); }; // Reload rule inputs - couponManager.loadRuleInputs = function(ruleId, callBack) { + $.couponManager.loadRuleInputs = function(ruleId, callBack) { $('#constraint-add-operators-values').html('
    '); var url = "{$urlAjaxGetRuleInput}"; url = url.replace('ruleId', ruleId) @@ -113,7 +113,7 @@ } }).done(function(data) { $('#constraint-add-operators-values').html(data); - couponManager.ruleToSave.serviceId = ruleId; + $.couponManager.ruleToSave.serviceId = ruleId; if (ruleId == -1) { // Placeholder can't be saved $('#constraint-save-btn').hide(); @@ -125,7 +125,7 @@ }; // Rules which will be saved - couponManager.rulesToSave = couponManager.initRules(); + $.couponManager.rulesToSave = $.couponManager.initRules(); $('#constraint-save-btn').hide(); diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 68c74bee2..299c6598b 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -11,7 +11,7 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field}
    @@ -104,10 +104,10 @@ {form_field form=$form field='type'}
    - + {foreach from=$availableCoupons item=availableCoupon} - {/foreach} @@ -285,4 +285,3 @@ {/if} - From 033bebdd3046953e04c9a13927455e054c0544f0 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 24 Sep 2013 22:46:54 +0200 Subject: [PATCH 14/27] Working : coupon creation : Fix js --- .../admin/default/coupon/rule-input-ajax.html | 20 +++++++++---------- templates/admin/default/coupon/rules.html | 8 +++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/templates/admin/default/coupon/rule-input-ajax.html b/templates/admin/default/coupon/rule-input-ajax.html index 9911ded32..50ff64a08 100644 --- a/templates/admin/default/coupon/rule-input-ajax.html +++ b/templates/admin/default/coupon/rule-input-ajax.html @@ -73,32 +73,32 @@ // Init Rules to set // Update only if no rule are already set - if(!couponManager.ruleToSave){ - couponManager.ruleToSave['serviceId'] = '{$ruleId}'; - couponManager.ruleToSave['operators'] = {literal}{}{/literal}; - couponManager.ruleToSave['values'] = {literal}{}{/literal}; + if(!$.couponManager.ruleToSave){ + $.couponManager.ruleToSave['serviceId'] = '{$ruleId}'; + $.couponManager.ruleToSave['operators'] = {literal}{}{/literal}; + $.couponManager.ruleToSave['values'] = {literal}{}{/literal}; } else { } {foreach from=$inputs.inputs key=name item=input} - couponManager.ruleToSave['operators']['{$name nofilter}'] = '{foreach from=$inputs.inputs[$name].availableOperators key=keyOperator item=valueOperator name=operators}{if $smarty.foreach.operators.first}{$keyOperator nofilter}{/if}{/foreach}'; - couponManager.ruleToSave['values']['{$name nofilter}'] = '{if count($inputs.inputs[$name].availableValues) != 0}{foreach from=$inputs.inputs[$name].availableValues key=keyValue item=valueValue name=values}{if $smarty.foreach.values.first}{$keyValue nofilter}{/if}{/foreach}{else}to set{/if}'; + $.couponManager.ruleToSave['operators']['{$name nofilter}'] = '{foreach from=$inputs.inputs[$name].availableOperators key=keyOperator item=valueOperator name=operators}{if $smarty.foreach.operators.first}{$keyOperator nofilter}{/if}{/foreach}'; + $.couponManager.ruleToSave['values']['{$name nofilter}'] = '{if count($inputs.inputs[$name].availableValues) != 0}{foreach from=$inputs.inputs[$name].availableValues key=keyValue item=valueValue name=values}{if $smarty.foreach.values.first}{$keyValue nofilter}{/if}{/foreach}{else}to set{/if}'; {/foreach} // Fill in ready to be saved rule array - couponManager.onInputsChange = function() {literal}{{/literal} + $.couponManager.onInputsChange = function() {literal}{{/literal} {foreach from=$inputs.inputs key=name item=input} // Operator selector $('#{$name}-operator').change(function (e) { var $this = $(this); - couponManager.ruleToSave['operators']['{$name nofilter}'] = $this.val(); + $.couponManager.ruleToSave['operators']['{$name nofilter}'] = $this.val(); }); // Value input $('#{$name}-value').change(function (e) { var $this = $(this); - couponManager.ruleToSave['values']['{$name nofilter}'] = $this.val(); + $.couponManager.ruleToSave['values']['{$name nofilter}'] = $this.val(); }); {/foreach} {literal}}{/literal} - couponManager.onInputsChange(); + $.couponManager.onInputsChange(); \ No newline at end of file diff --git a/templates/admin/default/coupon/rules.html b/templates/admin/default/coupon/rules.html index 199ee44c3..c5a09aa97 100644 --- a/templates/admin/default/coupon/rules.html +++ b/templates/admin/default/coupon/rules.html @@ -10,9 +10,11 @@ {intl l='Edit'} - - {intl l='Delete'} - + {if $rules|count != 1} + + {intl l='Delete'} + + {/if} {/foreach} From cb389f126c409d99163452c15c7437d42dacfd18 Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 12:58:12 +0200 Subject: [PATCH 15/27] WIP : Refactor contraint/rule becomes conditions (more generic) --- .../Thelia/Condition/ConditionEvaluator.php | 144 +++++++++++++++ .../lib/Thelia/Condition/ConditionFactory.php | 169 +++++++++++++++++ .../ConditionManagerAbstract.php} | 63 +++---- .../ConditionManagerInterface.php} | 28 ++- .../MatchForEveryoneManager.php} | 19 +- .../MatchForTotalAmountManager.php} | 42 ++--- .../MatchForXArticlesManager.php} | 42 ++--- .../Rule => Condition}/Operators.php | 23 ++- .../SerializableCondition.php} | 32 ++-- .../Thelia/Constraint/ConstraintFactory.php | 174 ------------------ 10 files changed, 423 insertions(+), 313 deletions(-) create mode 100644 core/lib/Thelia/Condition/ConditionEvaluator.php create mode 100644 core/lib/Thelia/Condition/ConditionFactory.php rename core/lib/Thelia/{Constraint/Rule/CouponRuleAbstract.php => Condition/ConditionManagerAbstract.php} (82%) rename core/lib/Thelia/{Constraint/Rule/CouponRuleInterface.php => Condition/ConditionManagerInterface.php} (86%) rename core/lib/Thelia/{Constraint/Rule/AvailableForEveryoneManager.php => Condition/Implementation/MatchForEveryoneManager.php} (87%) rename core/lib/Thelia/{Constraint/Rule/AvailableForTotalAmountManager.php => Condition/Implementation/MatchForTotalAmountManager.php} (88%) rename core/lib/Thelia/{Constraint/Rule/AvailableForXArticlesManager.php => Condition/Implementation/MatchForXArticlesManager.php} (86%) rename core/lib/Thelia/{Constraint/Rule => Condition}/Operators.php (91%) rename core/lib/Thelia/{Constraint/Rule/SerializableRule.php => Condition/SerializableCondition.php} (79%) delete mode 100644 core/lib/Thelia/Constraint/ConstraintFactory.php diff --git a/core/lib/Thelia/Condition/ConditionEvaluator.php b/core/lib/Thelia/Condition/ConditionEvaluator.php new file mode 100644 index 000000000..327c80a3d --- /dev/null +++ b/core/lib/Thelia/Condition/ConditionEvaluator.php @@ -0,0 +1,144 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition; + +use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\Condition\Operators; +use Thelia\Coupon\ConditionCollection; + + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Validate Conditions + * + * @package Condition + * @author Guillaume MOREL + * + */ +class ConditionEvaluator +{ + /** + * Check if an Event matches SerializableCondition + * + * @param ConditionCollection $conditions Conditions to check against the Event + * + * @return bool + */ + public function isMatching(ConditionCollection $conditions) + { + $isMatching = true; + /** @var ConditionManagerInterface $condition */ + foreach ($conditions->getConditions() as $condition) { + if (!$condition->isMatching()) { + $isMatching = false; + } + } + + return $isMatching; + + } + + /** + * Do variable comparison + * + * @param mixed $v1 Variable 1 + * @param string $o Operator ex : Operators::DIFFERENT + * @param mixed $v2 Variable 2 + * + * @throws \Exception + * @return bool + */ + public function variableOpComparison($v1, $o, $v2) + { + if ($o == Operators::DIFFERENT) { + return ($v1 != $v2); + } + + switch ($o) { + case Operators::SUPERIOR : + // > + if ($v1 > $v2) { + return true; + } else { + continue; + } + break; + case Operators::SUPERIOR_OR_EQUAL : + // >= + if ($v1 >= $v2) { + return true; + } else { + continue; + } + break; + case Operators::INFERIOR : + // < + if ($v1 < $v2) { + return true; + } else { + continue; + } + break; + case Operators::INFERIOR_OR_EQUAL : + // <= + if ($v1 <= $v2) { + return true; + } else { + continue; + } + break; + case Operators::EQUAL : + // == + if ($v1 == $v2) { + return true; + } else { + continue; + } + break; + case Operators::IN: + // in + if (in_array($v1, $v2)) { + return true; + } else { + continue; + } + break; + case Operators::OUT: + // not in + if (!in_array($v1, $v2)) { + return true; + } else { + continue; + } + break; + default: + throw new \Exception('Unrecognized operator ' . $o); + } + + return false; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php new file mode 100644 index 000000000..8e8c37b1d --- /dev/null +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -0,0 +1,169 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition; + +use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\Coupon\AdapterInterface; +use Thelia\Coupon\ConditionCollection; + + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Manage how Condition could interact with the current application state (Thelia) + * + * @package Constraint + * @author Guillaume MOREL + * + */ +class ConditionFactory +{ + /** @var ContainerInterface Service Container */ + protected $container = null; + + /** @var AdapterInterface Provide necessary value from Thelia */ + protected $adapter; + + /** @var array ConditionCollection to process*/ + protected $conditions = null; + + /** + * Constructor + * + * @param ContainerInterface $container Service container + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + $this->adapter = $container->get('thelia.adapter'); + } + + /** + * Serialize a collection of conditions + * + * @param ConditionCollection $collection A collection of conditions + * + * @return string A ready to be stored Condition collection + */ + public function serializeCouponRuleCollection(ConditionCollection $collection) + { + if ($collection->isEmpty()) { + /** @var ConditionManagerInterface $conditionNone */ + $conditionNone = $this->container->get( + 'thelia.constraint.rule.available_for_everyone' + ); + $collection->add($conditionNone); + } + $serializableConditions = array(); + $conditions = $collection->getConditions(); + if ($conditions !== null) { + /** @var $condition ConditionManagerInterface */ + foreach ($conditions as $condition) { + // Remove all rule if the "no condition" condition is found +// if ($condition->getServiceId() == 'thelia.constraint.rule.available_for_everyone') { +// return base64_encode(json_encode(array($condition->getSerializableRule()))); +// } + $serializableConditions[] = $condition->getSerializableCondition(); + } + } + + return base64_encode(json_encode($serializableConditions)); + } + + /** + * Unserialize a collection of conditions + * + * @param string $serializedConditions Serialized Conditions + * + * @return ConditionCollection Conditions ready to be processed + */ + public function unserializeCouponRuleCollection($serializedConditions) + { + $unserializedConditions = json_decode(base64_decode($serializedConditions)); + + $collection = new ConditionCollection(); + + if (!empty($unserializedConditions) && !empty($unserializedConditions)) { + /** @var SerializableCondition $condition */ + foreach ($unserializedConditions as $condition) { + if ($this->container->has($condition->conditionServiceId)) { + /** @var ConditionManagerInterface $conditionManager */ + $conditionManager = $this->build( + $condition->conditionServiceId, + (array) $condition->operators, + (array) $condition->values + ); + $collection->add(clone $conditionManager); + } + } + } + + return $collection; + } + + + /** + * Build a Condition from form + * + * @param string $conditionServiceId Condition class name + * @param array $operators Condition Operator (<, >, = ) + * @param array $values Values setting this Condition + * + * @throws \InvalidArgumentException + * @return ConditionManagerInterface Ready to use Condition or false + */ + public function build($conditionServiceId, array $operators, array $values) + { + if (!$this->container->has($conditionServiceId)) { + return false; + } + + /** @var ConditionManagerInterface $condition */ + $condition = $this->container->get($conditionServiceId); + $condition->setValidatorsFromForm($operators, $values); + + return $condition; + } + + /** + * Get Condition inputs from serviceId + * + * @param string $conditionServiceId ConditionManager class name + * + * @return array Ready to be drawn rule inputs + */ + public function getInputs($conditionServiceId) + { + if (!$this->container->has($conditionServiceId)) { + return false; + } + + /** @var ConditionManagerInterface $condition */ + $condition = $this->container->get($conditionServiceId); + + return $condition->getValidators(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Condition/ConditionManagerAbstract.php similarity index 82% rename from core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php rename to core/lib/Thelia/Condition/ConditionManagerAbstract.php index ffd1eb0f3..16ef2c044 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Condition/ConditionManagerAbstract.php @@ -21,17 +21,12 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition; use Symfony\Component\Intl\Exception\NotImplementedException; -use Thelia\Constraint\ConstraintValidator; use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Constraint\Validator\ComparableInterface; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Exception\InvalidRuleException; -use Thelia\Exception\InvalidRuleOperatorException; -use Thelia\Exception\InvalidRuleValueException; +use Thelia\Coupon\AdapterInterface; +use Thelia\Exception\InvalidConditionValueException; use Thelia\Model\Currency; use Thelia\Type\FloatType; @@ -46,7 +41,7 @@ use Thelia\Type\FloatType; * @author Guillaume MOREL * */ -abstract class CouponRuleAbstract implements CouponRuleInterface +abstract class ConditionManagerAbstract implements ConditionManagerInterface { // /** Operator key in $validators */ // CONST OPERATOR = 'operator'; @@ -65,7 +60,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface // /** @var array Parameters to be validated */ // protected $paramsToValidate = array(); - /** @var CouponAdapterInterface Provide necessary value from Thelia */ + /** @var AdapterInterface Provide necessary value from Thelia */ protected $adapter = null; /** @var Translator Service Translator */ @@ -77,19 +72,19 @@ abstract class CouponRuleAbstract implements CouponRuleInterface /** @var array Values set by Admin in BackOffice */ protected $values = array(); - /** @var ConstraintValidator Constaints validator */ - protected $constraintValidator = null; + /** @var ConditionEvaluator Conditions validator */ + protected $conditionValidator = null; /** * Constructor * - * @param CouponAdapterInterface $adapter Service adapter + * @param AdapterInterface $adapter Service adapter */ - function __construct(CouponAdapterInterface $adapter) + public function __construct(AdapterInterface $adapter) { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->constraintValidator = $adapter->getConstraintValidator(); + $this->conditionValidator = $adapter->getConditionValidator(); } // /** @@ -108,7 +103,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface // throw new InvalidRuleException(get_class()); // } // if (!in_array($validator->getOperator(), $this->availableOperators)) { -// throw new InvalidRuleOperatorException( +// throw new InvalidConditionOperatorException( // get_class(), // $validator->getOperator() // ); @@ -149,7 +144,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface // } /** - * Return all available Operators for this Rule + * Return all available Operators for this Condition * * @return array Operators::CONST */ @@ -161,7 +156,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface // /** // * Check if Operators set for this Rule in the BackOffice are legit // * -// * @throws InvalidRuleOperatorException if Operator is not allowed +// * @throws InvalidConditionOperatorException if Operator is not allowed // * @return bool // */ // protected function checkBackOfficeInputsOperators() @@ -172,7 +167,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface // if (!isset($operator) // ||!in_array($operator, $this->availableOperators) // ) { -// throw new InvalidRuleOperatorException(get_class(), $key); +// throw new InvalidConditionOperatorException(get_class(), $key); // } // } // return true; @@ -233,7 +228,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface } /** - * Get Rule Service id + * Get ConditionManager Service id * * @return string */ @@ -243,7 +238,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface } /** - * Validate if Operator given is available for this Coupon + * Validate if Operator given is available for this Condition * * @param string $operator Operator to validate ex < * @param array $availableOperators Available operators @@ -256,19 +251,19 @@ abstract class CouponRuleAbstract implements CouponRuleInterface } /** - * Return a serializable Rule + * Return a serializable Condition * - * @return SerializableRule + * @return SerializableCondition */ - public function getSerializableRule() + public function getSerializableCondition() { - $serializableRule = new SerializableRule(); - $serializableRule->ruleServiceId = $this->serviceId; - $serializableRule->operators = $this->operators; + $serializableCondition = new SerializableCondition(); + $serializableCondition->conditionServiceId = $this->serviceId; + $serializableCondition->operators = $this->operators; - $serializableRule->values = $this->values; + $serializableCondition->values = $this->values; - return $serializableRule; + return $serializableCondition; } @@ -278,20 +273,20 @@ abstract class CouponRuleAbstract implements CouponRuleInterface * @param string $currencyValue Currency EUR|USD|.. * * @return bool - * @throws \Thelia\Exception\InvalidRuleValueException + * @throws \Thelia\Exception\InvalidConditionValueException */ protected function IsCurrencyValid($currencyValue) { $availableCurrencies = $this->adapter->getAvailableCurrencies(); /** @var Currency $currency */ $currencyFound = false; - foreach ($availableCurrencies as $key => $currency) { + foreach ($availableCurrencies as $currency) { if ($currencyValue == $currency->getCode()) { $currencyFound = true; } } if (!$currencyFound) { - throw new InvalidRuleValueException( + throw new InvalidConditionValueException( get_class(), 'currency' ); } @@ -305,13 +300,13 @@ abstract class CouponRuleAbstract implements CouponRuleInterface * @param float $priceValue Price value to check * * @return bool - * @throws \Thelia\Exception\InvalidRuleValueException + * @throws \Thelia\Exception\InvalidConditionValueException */ protected function isPriceValid($priceValue) { $floatType = new FloatType(); if (!$floatType->isValid($priceValue) || $priceValue <= 0) { - throw new InvalidRuleValueException( + throw new InvalidConditionValueException( get_class(), 'price' ); } diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php b/core/lib/Thelia/Condition/ConditionManagerInterface.php similarity index 86% rename from core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php rename to core/lib/Thelia/Condition/ConditionManagerInterface.php index ac9579094..37f75479f 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php +++ b/core/lib/Thelia/Condition/ConditionManagerInterface.php @@ -21,30 +21,30 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition; use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; +use Thelia\Coupon\AdapterInterface; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * Represents a condition of whether the Rule is applied or not + * Manage how the application checks its state in order to check if it matches the implemented condition * - * @package Constraint + * @package Condition * @author Guillaume MOREL * */ -interface CouponRuleInterface +interface ConditionManagerInterface { /** * Constructor * - * @param CouponAdapterInterface $adapter Service adapter + * @param AdapterInterface $adapter Service adapter */ - function __construct(CouponAdapterInterface $adapter); + function __construct(AdapterInterface $adapter); /** * Get Rule Service id @@ -86,14 +86,14 @@ interface CouponRuleInterface // public function isMatching(); /** - * Test if Customer meets conditions + * Test if the current application state matches conditions * * @return bool */ public function isMatching(); /** - * Return all available Operators for this Rule + * Return all available Operators for this condition * * @return array Operators::CONST */ @@ -133,14 +133,10 @@ interface CouponRuleInterface /** - * Return a serializable Rule + * Return a serializable Condition * - * @return SerializableRule + * @return SerializableCondition */ - public function getSerializableRule(); - - - - + public function getSerializableCondition(); } diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForEveryoneManager.php b/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php similarity index 87% rename from core/lib/Thelia/Constraint/Rule/AvailableForEveryoneManager.php rename to core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php index 15e0e3ab7..57a7814b9 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForEveryoneManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php @@ -21,17 +21,10 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition\Implementation; use InvalidArgumentException; -use Symfony\Component\Translation\Translator; -use Thelia\Constraint\ConstraintValidator; -use Thelia\Constraint\Validator\QuantityParam; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Exception\InvalidRuleException; -use Thelia\Exception\InvalidRuleValueException; -use Thelia\Type\FloatType; +use Thelia\Condition\ConditionManagerAbstract; /** * Created by JetBrains PhpStorm. @@ -40,11 +33,11 @@ use Thelia\Type\FloatType; * * Allow every one, perform no check * - * @package Constraint + * @package Condition * @author Guillaume MOREL * */ -class AvailableForEveryoneManager extends CouponRuleAbstract +class MatchForEveryoneManager extends ConditionManagerAbstract { /** @var string Service Id from Resources/config.xml */ protected $serviceId = 'thelia.constraint.rule.available_for_everyone'; @@ -102,7 +95,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract return $this->translator->trans( 'Everybody can use it (no condition)', array(), - 'constraint' + 'condition' ); } @@ -116,7 +109,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract $toolTip = $this->translator->trans( 'Will return always true', array(), - 'constraint' + 'condition' ); return $toolTip; diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php similarity index 88% rename from core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php rename to core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php index c4087e734..87524cdc9 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php @@ -21,38 +21,33 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition\Implementation; use Symfony\Component\Intl\Exception\NotImplementedException; -use Symfony\Component\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Constraint\Validator\PriceParam; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Exception\InvalidRuleException; -use Thelia\Exception\InvalidRuleOperatorException; -use Thelia\Exception\InvalidRuleValueException; +use Thelia\Condition\ConditionManagerAbstract; +use Thelia\Condition\Operators; +use Thelia\Exception\InvalidConditionOperatorException; use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; -use Thelia\Type\FloatType; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * Rule AvailableForTotalAmount + * Condition AvailableForTotalAmount * Check if a Checkout total amount match criteria * - * @package Constraint + * @package Condition * @author Guillaume MOREL * */ -class AvailableForTotalAmountManager extends CouponRuleAbstract +class MatchForTotalAmountManager extends ConditionManagerAbstract { - /** Rule 1st parameter : price */ + /** Condition 1st parameter : price */ CONST INPUT1 = 'price'; - /** Rule 1st parameter : currency */ + /** Condition 1st parameter : currency */ CONST INPUT2 = 'currency'; /** @var string Service Id from Resources/config.xml */ @@ -101,7 +96,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract * @param string $currencyOperator Currency Operator ex = * @param string $currencyValue Currency set to meet condition * - * @throws \InvalidArgumentException + * @throws \Thelia\Exception\InvalidConditionOperatorException * @return $this */ protected function setValidators($priceOperator, $priceValue, $currencyOperator, $currencyValue) @@ -111,7 +106,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new InvalidRuleOperatorException( + throw new InvalidConditionOperatorException( get_class(), 'price' ); } @@ -121,7 +116,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT2] ); if (!$isOperator1Legit) { - throw new InvalidRuleOperatorException( + throw new InvalidConditionOperatorException( get_class(), 'price' ); } @@ -164,12 +159,12 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract return false; } - $constraint1 = $this->constraintValidator->variableOpComparison( + $constraint1 = $this->conditionValidator->variableOpComparison( $this->adapter->getCartTotalPrice(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); - $constraint2 = $this->constraintValidator->variableOpComparison( + $constraint2 = $this->conditionValidator->variableOpComparison( $this->adapter->getCheckoutCurrency(), $this->operators[self::INPUT2], $this->values[self::INPUT2] @@ -177,6 +172,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract if ($constraint1 && $constraint2) { return true; } + return false; } @@ -190,7 +186,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract return $this->translator->trans( 'Cart total amount', array(), - 'constraint' + 'condition' ); } @@ -212,7 +208,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract '%amount%' => $this->values[self::INPUT1], '%currency%' => $this->values[self::INPUT2] ), - 'constraint' + 'condition' ); return $toolTip; @@ -235,12 +231,12 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $name1 = $this->translator->trans( 'Price', array(), - 'constraint' + 'condition' ); $name2 = $this->translator->trans( 'Currency', array(), - 'constraint' + 'condition' ); return array( diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php similarity index 86% rename from core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php rename to core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php index f73d5e2be..a8e874a46 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php @@ -21,18 +21,13 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition\Implementation; use InvalidArgumentException; -use Symfony\Component\Translation\Translator; -use Thelia\Constraint\ConstraintValidator; -use Thelia\Constraint\Validator\QuantityParam; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Exception\InvalidRuleException; -use Thelia\Exception\InvalidRuleOperatorException; -use Thelia\Exception\InvalidRuleValueException; -use Thelia\Type\FloatType; +use Thelia\Condition\ConditionManagerAbstract; +use Thelia\Condition\Operators; +use Thelia\Exception\InvalidConditionOperatorException; +use Thelia\Exception\InvalidConditionValueException; /** * Created by JetBrains PhpStorm. @@ -41,13 +36,13 @@ use Thelia\Type\FloatType; * * Check a Checkout against its Product number * - * @package Constraint + * @package Condition * @author Guillaume MOREL * */ -class AvailableForXArticlesManager extends CouponRuleAbstract +class MatchForXArticlesManager extends ConditionManagerAbstract { - /** Rule 1st parameter : quantity */ + /** Condition 1st parameter : quantity */ CONST INPUT1 = 'quantity'; /** @var string Service Id from Resources/config.xml */ @@ -89,7 +84,8 @@ class AvailableForXArticlesManager extends CouponRuleAbstract * @param string $quantityOperator Quantity Operator ex < * @param int $quantityValue Quantity set to meet condition * - * @throws \InvalidArgumentException + * @throws \Thelia\Exception\InvalidConditionValueException + * @throws \Thelia\Exception\InvalidConditionOperatorException * @return $this */ protected function setValidators($quantityOperator, $quantityValue) @@ -99,13 +95,13 @@ class AvailableForXArticlesManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new InvalidRuleOperatorException( + throw new InvalidConditionOperatorException( get_class(), 'quantity' ); } if ((int) $quantityValue <= 0) { - throw new InvalidRuleValueException( + throw new InvalidConditionValueException( get_class(), 'quantity' ); } @@ -127,15 +123,16 @@ class AvailableForXArticlesManager extends CouponRuleAbstract */ public function isMatching() { - $constraint1 = $this->constraintValidator->variableOpComparison( + $condition1 = $this->conditionValidator->variableOpComparison( $this->adapter->getNbArticlesInCart(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); - if ($constraint1) { + if ($condition1) { return true; } + return false; } @@ -149,7 +146,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract return $this->translator->trans( 'Number of articles in cart', array(), - 'constraint' + 'condition' ); } @@ -170,7 +167,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract '%operator%' => $i18nOperator, '%quantity%' => $this->values[self::INPUT1] ), - 'constraint' + 'condition' ); return $toolTip; @@ -186,7 +183,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract $name1 = $this->translator->trans( 'Quantity', array(), - 'constraint' + 'condition' ); return array( @@ -200,5 +197,4 @@ class AvailableForXArticlesManager extends CouponRuleAbstract ) ); } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Constraint/Rule/Operators.php b/core/lib/Thelia/Condition/Operators.php similarity index 91% rename from core/lib/Thelia/Constraint/Rule/Operators.php rename to core/lib/Thelia/Condition/Operators.php index a6c457c75..57be8e0bf 100644 --- a/core/lib/Thelia/Constraint/Rule/Operators.php +++ b/core/lib/Thelia/Condition/Operators.php @@ -21,17 +21,16 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition; -use Symfony\Component\Translation\Translator; -use Thelia\Constraint\Validator\ComparableInterface; +use Thelia\Core\Translation\Translator; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * Represent available Operations in rule checking + * Represent available Operations in condition checking * * @package Constraint * @author Guillaume MOREL @@ -72,56 +71,56 @@ abstract class Operators $ret = $translator->trans( 'inferior to', array(), - 'constraint' + 'condition' ); break; case self::INFERIOR_OR_EQUAL: $ret = $translator->trans( 'inferior or equal to', array(), - 'constraint' + 'condition' ); break; case self::EQUAL: $ret = $translator->trans( 'equal to', array(), - 'constraint' + 'condition' ); break; case self::SUPERIOR_OR_EQUAL: $ret = $translator->trans( 'superior or equal to', array(), - 'constraint' + 'condition' ); break; case self::SUPERIOR: $ret = $translator->trans( 'superior to', array(), - 'constraint' + 'condition' ); break; case self::DIFFERENT: $ret = $translator->trans( 'different from', array(), - 'constraint' + 'condition' ); break; case self::IN: $ret = $translator->trans( 'in', array(), - 'constraint' + 'condition' ); break; case self::OUT: $ret = $translator->trans( 'not in', array(), - 'constraint' + 'condition' ); break; default: diff --git a/core/lib/Thelia/Constraint/Rule/SerializableRule.php b/core/lib/Thelia/Condition/SerializableCondition.php similarity index 79% rename from core/lib/Thelia/Constraint/Rule/SerializableRule.php rename to core/lib/Thelia/Condition/SerializableCondition.php index 011c3e261..9dbec171c 100644 --- a/core/lib/Thelia/Constraint/Rule/SerializableRule.php +++ b/core/lib/Thelia/Condition/SerializableCondition.php @@ -21,32 +21,32 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Rule; +namespace Thelia\Condition; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * A rule set by an admin ready to be serialized and stored in DataBase + * A condition set by an admin ready to be serialized and stored in DataBase * - * @package Constraint + * @package Condition * @author Guillaume MOREL * */ -class SerializableRule +class SerializableCondition { - /** @var string Rule Service id */ - public $ruleServiceId = null; + /** @var string Condition Service id */ + public $conditionServiceId = null; - /** @var array Operators set by Admin for this Rule */ + /** @var array Operators set by Admin for this Condition */ public $operators = array(); - /** @var array Values set by Admin for this Rule */ + /** @var array Values set by Admin for this Condition */ public $values = array(); /** - * Get Operators set by Admin for this Rule + * Get Operators set by Admin for this Condition * * @return array */ @@ -56,17 +56,17 @@ class SerializableRule } /** - * Get Rule Service id + * Get Condition Service id * * @return string */ - public function getRuleServiceId() + public function getConditionServiceId() { - return $this->ruleServiceId; + return $this->conditionServiceId; } /** - * Get Values set by Admin for this Rule + * Get Values set by Admin for this Condition * * @return array */ @@ -74,8 +74,4 @@ class SerializableRule { return $this->values; } - - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Constraint/ConstraintFactory.php b/core/lib/Thelia/Constraint/ConstraintFactory.php deleted file mode 100644 index e13d1d2aa..000000000 --- a/core/lib/Thelia/Constraint/ConstraintFactory.php +++ /dev/null @@ -1,174 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint; - -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Serializer\Encoder\JsonEncoder; -use Thelia\Constraint\Rule\AvailableForEveryoneManager; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\CouponRuleInterface; -use Thelia\Constraint\Rule\SerializableRule; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Coupon\CouponRuleCollection; - - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Manage how Constraint could interact - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class ConstraintFactory -{ - /** @var ContainerInterface Service Container */ - protected $container = null; - - /** @var CouponAdapterInterface Provide necessary value from Thelia*/ - protected $adapter; - - /** @var array CouponRuleCollection to process*/ - protected $rules = null; - - /** - * Constructor - * - * @param ContainerInterface $container Service container - */ - function __construct(ContainerInterface $container) - { - $this->container = $container; - $this->adapter = $container->get('thelia.adapter'); - } - - /** - * Serialize a collection of rules - * - * @param CouponRuleCollection $collection A collection of rules - * - * @return string A ready to be stored Rule collection - */ - public function serializeCouponRuleCollection(CouponRuleCollection $collection) - { - if ($collection->isEmpty()) { - /** @var CouponRuleInterface $ruleNoCondition */ - $ruleNoCondition = $this->container->get( - 'thelia.constraint.rule.available_for_everyone' - ); - $collection->add($ruleNoCondition); - } - $serializableRules = array(); - $rules = $collection->getRules(); - if ($rules !== null) { - /** @var $rule CouponRuleInterface */ - foreach ($rules as $rule) { - // Remove all rule if the "no condition" rule is found -// if ($rule->getServiceId() == 'thelia.constraint.rule.available_for_everyone') { -// return base64_encode(json_encode(array($rule->getSerializableRule()))); -// } - $serializableRules[] = $rule->getSerializableRule(); - } - } - - return base64_encode(json_encode($serializableRules)); - } - - /** - * Unserialize a collection of rules - * - * @param string $serializedRules Serialized Rules - * - * @return CouponRuleCollection Rules ready to be processed - */ - public function unserializeCouponRuleCollection($serializedRules) - { - $unserializedRules = json_decode(base64_decode($serializedRules)); - - $collection = new CouponRuleCollection(); - - if (!empty($serializedRules) && !empty($unserializedRules)) { - /** @var SerializableRule $rule */ - foreach ($unserializedRules as $rule) { - if ($this->container->has($rule->ruleServiceId)) { - /** @var CouponRuleInterface $couponRule */ - $couponRule = $this->build( - $rule->ruleServiceId, - (array) $rule->operators, - (array) $rule->values - ); - $collection->add(clone $couponRule); - } - } - } - - return $collection; - } - - - /** - * Build a Coupon Rule from form - * - * @param string $ruleServiceId Rule class name - * @param array $operators Rule Operator (<, >, = ) - * @param array $values Values setting this Rule - * - * @throws \InvalidArgumentException - * @return CouponRuleInterface Ready to use Rule or false - */ - public function build($ruleServiceId, array $operators, array $values) - { - if (!$this->container->has($ruleServiceId)) { - return false; - } - - /** @var CouponRuleInterface $rule */ - $rule = $this->container->get($ruleServiceId); - $rule->setValidatorsFromForm($operators, $values); - - return $rule; - } - - /** - * Get Coupon Rule inputs from serviceId - * - * @param string $ruleServiceId Rule class name - * - * @return array Ready to be drawn rule inputs - */ - public function getInputs($ruleServiceId) - { - if (!$this->container->has($ruleServiceId)) { - return false; - } - - /** @var CouponRuleInterface $rule */ - $rule = $this->container->get($ruleServiceId); - - return $rule->getValidators(); - } -} \ No newline at end of file From d6172f23cfdc8caa74bb3b646889db8047799b04 Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 14:51:42 +0200 Subject: [PATCH 16/27] WIP : Refactor contraint/rule becomes conditions (more generic) --- core/lib/Thelia/Action/Coupon.php | 32 +- .../lib/Thelia/Condition/ConditionFactory.php | 8 +- .../Condition/ConditionManagerInterface.php | 18 +- .../MatchForEveryoneManager.php | 2 +- .../MatchForTotalAmountManager.php | 2 +- .../MatchForXArticlesManager.php | 2 +- core/lib/Thelia/Config/Resources/config.xml | 40 +-- .../Thelia/Constraint/ConstraintValidator.php | 133 -------- .../Constraint/Rule/AvailableForCustomer.php | 178 ----------- .../Constraint/Rule/AvailableForDate.php | 59 ---- .../Constraint/Rule/AvailableForLocationX.php | 59 ---- .../Constraint/Rule/AvailableForPeriod.php | 57 ---- .../Rule/AvailableForRepeatedDate.php | 57 ---- .../Rule/AvailableForRepeatedPeriod.php | 73 ----- .../AvailableForTotalAmountForCategoryY.php | 38 --- .../Validator/ComparableInterface.php | 49 --- .../Constraint/Validator/CustomerParam.php | 158 ---------- .../Thelia/Constraint/Validator/DateParam.php | 120 ------- .../Constraint/Validator/IntegerParam.php | 121 ------- .../Constraint/Validator/IntervalParam.php | 165 ---------- .../Constraint/Validator/ModelParam.php | 115 ------- .../Constraint/Validator/PriceParam.php | 145 --------- .../Validator/RepeatedDateParam.php | 117 ------- .../Validator/RepeatedIntervalParam.php | 151 --------- .../Constraint/Validator/RepeatedParam.php | 297 ------------------ .../Validator/RuleParameterAbstract.php | 67 ---- .../Constraint/Validator/RuleValidator.php | 77 ----- .../Controller/Admin/CouponController.php | 145 +++++---- .../ConditionCreateOrUpdateEvent.php} | 94 +++--- .../Core/Event/Coupon/CouponConsumeEvent.php | 7 +- .../Coupon/CouponCreateOrUpdateEvent.php | 57 +++- core/lib/Thelia/Core/Event/TheliaEvents.php | 12 +- core/lib/Thelia/Core/Template/Loop/Coupon.php | 2 +- ...pterInterface.php => AdapterInterface.php} | 12 +- ...{CouponBaseAdapter.php => BaseAdapter.php} | 12 +- ...Collection.php => ConditionCollection.php} | 49 ++- core/lib/Thelia/Coupon/CouponFactory.php | 4 +- core/lib/Thelia/Coupon/CouponManager.php | 44 +-- core/lib/Thelia/Coupon/RuleOrganizer.php | 6 +- .../Thelia/Coupon/RuleOrganizerInterface.php | 6 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 26 +- .../Thelia/Coupon/Type/CouponInterface.php | 12 +- .../Coupon/Type/RemoveXPercentManager.php | 2 +- ... => InvalidConditionOperatorException.php} | 11 +- ...php => InvalidConditionValueException.php} | 10 +- .../Thelia/Exception/InvalidRuleException.php | 2 +- core/lib/Thelia/Model/Coupon.php | 16 +- .../Constraint/ConstraintFactoryTest.php | 12 +- .../Constraint/ConstraintValidatorTest.php | 34 +- .../AvailableForTotalAmountManagerTest.php | 18 +- .../Rule/AvailableForXArticlesManagerTest.php | 50 +-- .../Tests/Constraint/Rule/OperatorsTest.php | 36 +-- .../Validator/CustomerParamTest.php | 14 +- .../Constraint/Validator/DateParamTest.php | 10 +- .../Constraint/Validator/IntegerParamTest.php | 10 +- .../Validator/IntervalParamTest.php | 12 +- .../Constraint/Validator/PriceParamTest.php | 18 +- .../Validator/QuantityParamTest.php | 14 +- .../Validator/RepeatedDateParamTest.php | 24 +- .../Validator/RepeatedIntervalParamTest.php | 32 +- .../Tests/Coupon/CouponBaseAdapterTest.php | 12 +- .../Thelia/Tests/Coupon/CouponFactoryTest.php | 22 +- .../Thelia/Tests/Coupon/CouponManagerTest.php | 56 ++-- .../Tests/Coupon/CouponRuleCollectionTest.php | 4 +- .../Tests/Coupon/Type/RemoveXAmountTest.php | 28 +- .../Tests/Coupon/Type/RemoveXPercentTest.php | 20 +- install/faker.php | 18 +- install/import.php | 2 +- install/tax_faker.php | 2 +- templates/admin/default/assets/js/coupon.js | 9 +- templates/admin/default/assets/js/main.js | 29 +- templates/admin/default/coupon-update.html | 4 +- ...ut-ajax.html => condition-input-ajax.html} | 0 templates/admin/default/coupon/form.html | 2 +- .../casperjs/exe/31_coupons_rule.js | 8 +- 75 files changed, 582 insertions(+), 2787 deletions(-) delete mode 100644 core/lib/Thelia/Constraint/ConstraintValidator.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForDate.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForRepeatedPeriod.php delete mode 100644 core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountForCategoryY.php delete mode 100644 core/lib/Thelia/Constraint/Validator/ComparableInterface.php delete mode 100644 core/lib/Thelia/Constraint/Validator/CustomerParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/DateParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/IntegerParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/IntervalParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/ModelParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/PriceParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/RepeatedParam.php delete mode 100644 core/lib/Thelia/Constraint/Validator/RuleParameterAbstract.php delete mode 100644 core/lib/Thelia/Constraint/Validator/RuleValidator.php rename core/lib/Thelia/{Constraint/Validator/QuantityParam.php => Core/Event/Condition/ConditionCreateOrUpdateEvent.php} (56%) rename core/lib/Thelia/Coupon/{CouponAdapterInterface.php => AdapterInterface.php} (94%) rename core/lib/Thelia/Coupon/{CouponBaseAdapter.php => BaseAdapter.php} (96%) rename core/lib/Thelia/Coupon/{CouponRuleCollection.php => ConditionCollection.php} (72%) rename core/lib/Thelia/Exception/{InvalidRuleValueException.php => InvalidConditionOperatorException.php} (87%) rename core/lib/Thelia/Exception/{InvalidRuleOperatorException.php => InvalidConditionValueException.php} (87%) rename templates/admin/default/coupon/{rule-input-ajax.html => condition-input-ajax.html} (100%) diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index c1affe633..335a36340 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -23,16 +23,16 @@ namespace Thelia\Action; -use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Thelia\Constraint\ConstraintFactory; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\ConditionManagerInterface; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\HttpFoundation\Request; use Thelia\Coupon\CouponFactory; use Thelia\Coupon\CouponManager; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon as CouponModel; @@ -78,11 +78,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface * * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule */ - public function updateRule(CouponCreateOrUpdateEvent $event) + public function updateCondition(CouponCreateOrUpdateEvent $event) { $coupon = $event->getCoupon(); - $this->createOrUpdateRule($coupon, $event); + $this->createOrUpdateCondition($coupon, $event); } /** @@ -139,15 +139,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface $coupon->setDispatcher($this->getDispatcher()); // Set default rule if none found - $noConditionRule = $this->container->get('thelia.constraint.rule.available_for_everyone'); - $constraintFactory = $this->container->get('thelia.constraint.factory'); - $couponRuleCollection = new CouponRuleCollection(); + /** @var ConditionManagerInterface $noConditionRule */ + $noConditionRule = $this->container->get('thelia.condition.match_for_everyone'); + $constraintFactory = $this->container->get('thelia.condition.factory'); + $couponRuleCollection = new ConditionCollection(); $couponRuleCollection->add($noConditionRule); $defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection( $couponRuleCollection ); - $coupon->createOrUpdate( $event->getCode(), $event->getTitle(), @@ -165,8 +165,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->getLocale() ); - - $event->setCoupon($coupon); } @@ -177,15 +175,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface * @param CouponModel $coupon Model to save * @param CouponCreateOrUpdateEvent $event Event containing data */ - protected function createOrUpdateRule(CouponModel $coupon, CouponCreateOrUpdateEvent $event) + protected function createOrUpdateCondition(CouponModel $coupon, CouponCreateOrUpdateEvent $event) { $coupon->setDispatcher($this->getDispatcher()); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); + /** @var ConditionFactory $constraintFactory */ + $constraintFactory = $this->container->get('thelia.condition.factory'); - $coupon->createOrUpdateRules( - $constraintFactory->serializeCouponRuleCollection($event->getRules()), + $coupon->createOrUpdateConditions( + $constraintFactory->serializeConditionCollection($event->getConditions()), $event->getLocale() ); @@ -218,7 +216,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface TheliaEvents::COUPON_CREATE => array("create", 128), TheliaEvents::COUPON_UPDATE => array("update", 128), TheliaEvents::COUPON_CONSUME => array("consume", 128), - TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128) + TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128) ); } } diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index 8e8c37b1d..642b474e0 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -68,12 +68,12 @@ class ConditionFactory * * @return string A ready to be stored Condition collection */ - public function serializeCouponRuleCollection(ConditionCollection $collection) + public function serializeConditionCollection(ConditionCollection $collection) { if ($collection->isEmpty()) { /** @var ConditionManagerInterface $conditionNone */ $conditionNone = $this->container->get( - 'thelia.constraint.rule.available_for_everyone' + 'thelia.condition.match_for_everyone' ); $collection->add($conditionNone); } @@ -83,7 +83,7 @@ class ConditionFactory /** @var $condition ConditionManagerInterface */ foreach ($conditions as $condition) { // Remove all rule if the "no condition" condition is found -// if ($condition->getServiceId() == 'thelia.constraint.rule.available_for_everyone') { +// if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') { // return base64_encode(json_encode(array($condition->getSerializableRule()))); // } $serializableConditions[] = $condition->getSerializableCondition(); @@ -100,7 +100,7 @@ class ConditionFactory * * @return ConditionCollection Conditions ready to be processed */ - public function unserializeCouponRuleCollection($serializedConditions) + public function unserializeConditionCollection($serializedConditions) { $unserializedConditions = json_decode(base64_decode($serializedConditions)); diff --git a/core/lib/Thelia/Condition/ConditionManagerInterface.php b/core/lib/Thelia/Condition/ConditionManagerInterface.php index 37f75479f..bf7f439b3 100644 --- a/core/lib/Thelia/Condition/ConditionManagerInterface.php +++ b/core/lib/Thelia/Condition/ConditionManagerInterface.php @@ -121,15 +121,15 @@ interface ConditionManagerInterface */ public function getValidators(); -// /** -// * Populate a Rule from a form admin -// * -// * @param array $operators Rule Operator set by the Admin -// * @param array $values Rule Values set by the Admin -// * -// * @return bool -// */ -// public function populateFromForm(array$operators, array $values); + /** + * Populate a Condition from a form admin + * + * @param array $operators Condition Operator set by the Admin + * @param array $values Condition Values set by the Admin + * + * @return bool + */ + public function populateFromForm(array$operators, array $values); /** diff --git a/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php b/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php index 57a7814b9..00108a3b0 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForEveryoneManager.php @@ -40,7 +40,7 @@ use Thelia\Condition\ConditionManagerAbstract; class MatchForEveryoneManager extends ConditionManagerAbstract { /** @var string Service Id from Resources/config.xml */ - protected $serviceId = 'thelia.constraint.rule.available_for_everyone'; + protected $serviceId = 'thelia.condition.match_for_everyone'; /** @var array Available Operators (Operators::CONST) */ protected $availableOperators = array(); diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php index 87524cdc9..e56d58d6b 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php @@ -51,7 +51,7 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract CONST INPUT2 = 'currency'; /** @var string Service Id from Resources/config.xml */ - protected $serviceId = 'thelia.constraint.rule.available_for_total_amount'; + protected $serviceId = 'thelia.condition.match_for_total_amount'; /** @var array Available Operators (Operators::CONST) */ protected $availableOperators = array( diff --git a/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php index a8e874a46..05de953d0 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php @@ -46,7 +46,7 @@ class MatchForXArticlesManager extends ConditionManagerAbstract CONST INPUT1 = 'quantity'; /** @var string Service Id from Resources/config.xml */ - protected $serviceId = 'thelia.constraint.rule.available_for_x_articles'; + protected $serviceId = 'thelia.condition.match_for_x_articles'; /** @var array Available Operators (Operators::CONST) */ protected $availableOperators = array( diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 809c62a33..1060adf04 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -253,7 +253,7 @@ - + @@ -263,24 +263,6 @@ - - - - - - - - - - - - - - - - - - @@ -290,6 +272,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/core/lib/Thelia/Constraint/ConstraintValidator.php b/core/lib/Thelia/Constraint/ConstraintValidator.php deleted file mode 100644 index d3fe69a34..000000000 --- a/core/lib/Thelia/Constraint/ConstraintValidator.php +++ /dev/null @@ -1,133 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint; - -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Serializer\Encoder\JsonEncoder; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\CouponRuleInterface; -use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\CouponRuleCollection; - - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Validate Constraints - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class ConstraintValidator -{ - - /** - * Check if a Customer meets SerializableRule - * - * @param CouponRuleCollection $rules Rules to check against the Customer - * - * @return bool - */ - public function isMatching(CouponRuleCollection $rules) - { - $isMatching = true; - /** @var CouponRuleInterface $rule */ - foreach ($rules->getRules() as $rule) { - if (!$rule->isMatching()) { - $isMatching = false; - } - } - - return $isMatching; - - } - - /** - * Do variable comparison - * - * @param mixed $v1 Variable 1 - * @param string $o Operator - * @param mixed $v2 Variable 2 - * - * @throws \Exception - * @return bool - */ - public function variableOpComparison($v1, $o, $v2) { - if ($o == Operators::DIFFERENT) { - return ($v1 != $v2); - } // could put this elsewhere... -// $operators = str_split($o); -// foreach($o as $operator) { - switch ($o) { // return will exit switch, foreach loop, function - case Operators::SUPERIOR : // > - if ($v1 > $v2) { - return true; - } else { - continue; - } break; - case Operators::SUPERIOR_OR_EQUAL : // >= - if ($v1 >= $v2) { - return true; - } else { - continue; - } break; - case Operators::INFERIOR : // < - if ($v1 < $v2) { - return true; - } else { - continue; - } break; - case Operators::INFERIOR_OR_EQUAL : // <= - if ($v1 <= $v2) { - return true; - } else { - continue; - } break; - case Operators::EQUAL : // == - if ($v1 == $v2) { - return true; - } else { - continue; - } break; - case Operators::IN: - if (in_array($v1, $v2)) { // in - return true; - } else { - continue; - } break; - case Operators::OUT: - if (!in_array($v1, $v2)) { // not in - return true; - } else { - continue; - } break; - default: throw new \Exception('Unrecognized operator ' . $o); - } -// } - return false; - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php b/core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php deleted file mode 100644 index ad722eb5c..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php +++ /dev/null @@ -1,178 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -use Thelia\Constraint\Validator\CustomerParam; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Exception\InvalidRuleException; -use Thelia\Exception\InvalidRuleOperatorException; -use Thelia\Exception\InvalidRuleValueException; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForCustomer extends CouponRuleAbstract -{ - - /** Rule 1st parameter : customer id */ - CONST PARAM1 = 'customerId'; - - /** @var array Available Operators (Operators::CONST) */ - protected $availableOperators = array( - Operators::EQUAL, - ); - - /** @var RuleValidator Customer Validator */ - protected $customerValidator = null; - - /** - * Check if backoffice inputs are relevant or not - * - * @throws InvalidRuleOperatorException if Operator is not allowed - * @throws InvalidRuleValueException if Value is not allowed - * @return bool - */ - public function checkBackOfficeInput() - { - if (!isset($this->validators) - || empty($this->validators) - ||!isset($this->validators[self::PARAM1]) - ||!isset($this->validators[self::PARAM1]) - ) { - throw new InvalidRuleValueException(get_class(), self::PARAM1); - } - - /** @var RuleValidator $ruleValidator */ - $ruleValidator = $this->validators[self::PARAM1]; - /** @var CustomerParam $customer */ - $customer = $ruleValidator->getParam(); - - if (!$customer instanceof CustomerParam) { - throw new InvalidRuleValueException(get_class(), self::PARAM1); - } - - $this->checkBackOfficeInputsOperators(); - - return $this->isCustomerValid($customer->getInteger()); - } - - /** - * Generate current Rule param to be validated from adapter - * - * @return $this - */ - protected function setParametersToValidate() - { - $this->paramsToValidate = array( - self::PARAM1 => $this->adapter->getCustomer()->getId() - ); - - return $this; - } - - /** - * Check if Checkout inputs are relevant or not - * - * @throws \Thelia\Exception\InvalidRuleValueException - * @return bool - */ - public function checkCheckoutInput() - { - if (!isset($this->paramsToValidate) - || empty($this->paramsToValidate) - ||!isset($this->paramsToValidate[self::PARAM1]) - ) { - throw new InvalidRuleValueException(get_class(), self::PARAM1); - } - - $customerId = $this->paramsToValidate[self::PARAM1]; - - return $this->isCustomerValid($customerId); - } - - /** - * Check if a Customer is valid - * - * @param int $customerId Customer to check - * - * @throws InvalidRuleValueException if Value is not allowed - * @return bool - */ - protected function isCustomerValid($customerId) - { - $customerValidator = $this->customerValidator; - try { - $customerValidator->getParam()->compareTo($customerId); - } catch(\InvalidArgumentException $e) { - throw new InvalidRuleValueException(get_class(), self::PARAM1); - } - - return true; - } - - /** - * Get I18n name - * - * @return string - */ - public function getName() - { - return $this->adapter - ->getTranslator() - ->trans('Customer', null, 'constraint'); - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - /** @var CustomerParam $param */ - $param = $this->customerValidator->getParam(); - $toolTip = $this->adapter - ->getTranslator() - ->trans( - 'If customer is %fistname% %lastname% (%email%)', - array( - '%fistname%' => $param->getFirstName(), - '%lastname%' => $param->getLastName(), - '%email%' => $param->getEmail(), - ), - 'constraint' - ); - - return $toolTip; - } - - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForDate.php b/core/lib/Thelia/Constraint/Rule/AvailableForDate.php deleted file mode 100644 index 1ddfd0350..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForDate.php +++ /dev/null @@ -1,59 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForDate extends AvailableForPeriod -{ - - /** - * Check if backoffice inputs are relevant or not - * - * @return bool - */ - public function checkBackOfficeInput() - { - // TODO: Implement checkBackOfficeInput() method. - } - - /** - * Check if Checkout inputs are relevant or not - * - * @return bool - */ - public function checkCheckoutInput() - { - // TODO: Implement checkCheckoutInput() method. - } - - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php b/core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php deleted file mode 100644 index 5c3ec494c..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php +++ /dev/null @@ -1,59 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForLocationX extends CouponRuleAbstract -{ - - /** - * Check if backoffice inputs are relevant or not - * - * @return bool - */ - public function checkBackOfficeInput() - { - // TODO: Implement checkBackOfficeInput() method. - } - - /** - * Check if Checkout inputs are relevant or not - * - * @return bool - */ - public function checkCheckoutInput() - { - // TODO: Implement checkCheckoutInput() method. - } - - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php b/core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php deleted file mode 100644 index 30679a973..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php +++ /dev/null @@ -1,57 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForPeriod extends CouponRuleAbstract -{ - - /** - * Check if backoffice inputs are relevant or not - * - * @return bool - */ - public function checkBackOfficeInput() - { - // TODO: Implement checkBackOfficeInput() method. - } - - /** - * Check if Checkout inputs are relevant or not - * - * @return bool - */ - public function checkCheckoutInput() - { - // TODO: Implement checkCheckoutInput() method. - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php b/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php deleted file mode 100644 index 3449a7f5b..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php +++ /dev/null @@ -1,57 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForRepeatedDate extends AvailableForDate -{ - - /** - * Check if backoffice inputs are relevant or not - * - * @return bool - */ - public function checkBackOfficeInput() - { - // TODO: Implement checkBackOfficeInput() method. - } - - /** - * Check if Checkout inputs are relevant or not - * - * @return bool - */ - public function checkCheckoutInput() - { - // TODO: Implement checkCheckoutInput() method. - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedPeriod.php b/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedPeriod.php deleted file mode 100644 index f5bf9bafc..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForRepeatedPeriod.php +++ /dev/null @@ -1,73 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForRepeatedPeriod extends AvailableForPeriod -{ - - /** - * Generate current Rule param to be validated from adapter - * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * - * @throws \Symfony\Component\Intl\Exception\NotImplementedException - * @return $this - */ - public function setParametersToValidate(CouponAdapterInterface $adapter) - { - // @todo implement - } - - /** - * Check if backoffice inputs are relevant or not - * - * @return bool - */ - public function checkBackOfficeInput() - { - // TODO: Implement checkBackOfficeInput() method. - } - - /** - * Check if Checkout inputs are relevant or not - * - * @return bool - */ - public function checkCheckoutInput() - { - // TODO: Implement checkCheckoutInput() method. - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountForCategoryY.php b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountForCategoryY.php deleted file mode 100644 index 0f9f7f10b..000000000 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountForCategoryY.php +++ /dev/null @@ -1,38 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Rule; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForTotalAmountForCategoryY extends AvailableForTotalAmount -{ - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/ComparableInterface.php b/core/lib/Thelia/Constraint/Validator/ComparableInterface.php deleted file mode 100644 index d06187fb0..000000000 --- a/core/lib/Thelia/Constraint/Validator/ComparableInterface.php +++ /dev/null @@ -1,49 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -/** - * Comparable interface - * Allows to compare two value objects to each other for similarity. - * - * @author Benjamin Eberlei - * @author Guilherme Blanco - */ -interface ComparableInterface -{ - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @return int - */ - public function compareTo($other); -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/CustomerParam.php b/core/lib/Thelia/Constraint/Validator/CustomerParam.php deleted file mode 100644 index 5b4390ddc..000000000 --- a/core/lib/Thelia/Constraint/Validator/CustomerParam.php +++ /dev/null @@ -1,158 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use InvalidArgumentException; -use Propel\Runtime\ActiveQuery\ModelCriteria; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Model\Customer; -use Thelia\Model\CustomerQuery; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent a Customer - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class CustomerParam extends IntegerParam -{ - /** @var string Model Class name */ - protected $modelClass = '\Thelia\Model\Customer'; - - /** @var ModelCriteria */ - protected $queryBuilder = null; - - /** @var string Customer firstname */ - protected $firstName = null; - - /** @var string Customer lastname */ - protected $lastName = null; - - /** @var string Customer email */ - protected $email = null; - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param int $integer Integer - * - * @throws InvalidArgumentException - */ - public function __construct(CouponAdapterInterface $adapter, $integer) - { - $this->integer = $integer; - $this->adapter = $adapter; - - $this->queryBuilder = CustomerQuery::create(); - /** @var Customer $customer */ - $customer = $this->queryBuilder->findById($integer); - if ($customer !== null) { - $this->firstName = $customer->getFirstname(); - $this->lastName = $customer->getLastname(); - $this->email = $customer->getEmail(); - } else { - throw new \InvalidArgumentException( - 'CustomerParam can compare only existing Customers' - ); - } - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!is_integer($other) || $other < 0) { - throw new InvalidArgumentException( - 'IntegerParam can compare only positive int' - ); - } - - return parent::compareTo($other); - } - - /** - * Customer email - * - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Customer first name - * - * @return string - */ - public function getFirstName() - { - return $this->firstName; - } - - /** - * Customer last name - * - * @return string - */ - public function getLastName() - { - return $this->lastName; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans( - 'A Customer', - null, - 'constraint' - ); - } - -} diff --git a/core/lib/Thelia/Constraint/Validator/DateParam.php b/core/lib/Thelia/Constraint/Validator/DateParam.php deleted file mode 100644 index ae7eff858..000000000 --- a/core/lib/Thelia/Constraint/Validator/DateParam.php +++ /dev/null @@ -1,120 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent a DateTime - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class DateParam extends RuleParameterAbstract -{ - /** @var \DateTime Date */ - protected $dateTime = null; - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param \DateTime $dateTime DateTime - */ - public function __construct(CouponAdapterInterface $adapter, \DateTime $dateTime) - { - $this->dateTime = $dateTime; - $this->adapter = $adapter; - } - - /** - * Get DateTime - * - * @return \DateTime - */ - public function getDateTime() - { - return clone $this->dateTime; - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!$other instanceof \DateTime) { - throw new \InvalidArgumentException('DateParam can compare only DateTime'); - } - - $ret = -1; - if ($this->dateTime == $other) { - $ret = 0; - } elseif ($this->dateTime > $other) { - $ret = 1; - } else { - $ret = -1; - } - - return $ret; - } - - /** - * Get Parameter value to test against - * - * @return \Datetime - */ - public function getValue() - { - return clone $this->dateTime; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint'); - } - -} diff --git a/core/lib/Thelia/Constraint/Validator/IntegerParam.php b/core/lib/Thelia/Constraint/Validator/IntegerParam.php deleted file mode 100644 index c783655c8..000000000 --- a/core/lib/Thelia/Constraint/Validator/IntegerParam.php +++ /dev/null @@ -1,121 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent an Integer - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntegerParam extends RuleParameterAbstract -{ - /** @var int Integer to compare with */ - protected $integer = 0; - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param int $integer Integer - */ - public function __construct(CouponAdapterInterface $adapter, $integer) - { - $this->integer = $integer; - $this->adapter = $adapter; - } - - /** - * Get integer - * - * @return int - */ - public function getInteger() - { - return $this->integer; - } - - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!is_integer($other)) { - throw new \InvalidArgumentException('IntegerParam can compare only int'); - } - - $ret = -1; - if ($this->integer == $other) { - $ret = 0; - } elseif ($this->integer > $other) { - $ret = 1; - } else { - $ret = -1; - } - - return $ret; - } - - /** - * Get Parameter value to test against - * - * @return int - */ - public function getValue() - { - return $this->integer; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans('A number (ex: 42)', null, 'constraint'); - } - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/IntervalParam.php b/core/lib/Thelia/Constraint/Validator/IntervalParam.php deleted file mode 100644 index a4554760a..000000000 --- a/core/lib/Thelia/Constraint/Validator/IntervalParam.php +++ /dev/null @@ -1,165 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent an DateTime period - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntervalParam extends RuleParameterAbstract -{ - /** @var \DatePeriod Date period */ - protected $datePeriod = null; - - /** @var \DateTime Start date */ - protected $start = null; - - /** @var \DateInterval Interval date */ - protected $interval = null; - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param \DateTime $start Start interval - * @param \DateInterval $interval Period - */ - public function __construct(CouponAdapterInterface $adapter, \DateTime $start, \DateInterval $interval) - { - $this->datePeriod = new \DatePeriod($start, $interval, 1); - $this->adapter = $adapter; - - $this->start = $start; - $this->interval = $interval; - } - - /** - * Get Interval - * - * @return \DateInterval - */ - public function getInterval() - { - return $this->interval; - } - - /** - * Get start date - * - * @return \DateTime - */ - public function getStart() - { - return $this->start; - } - - - - /** - * Get DatePeriod - * - * @return \DatePeriod - */ - public function getDatePeriod() - { - return clone $this->datePeriod; - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!$other instanceof \DateTime) { - throw new \InvalidArgumentException('IntervalParam can compare only DateTime'); - } - - /** @var \DateTime Start Date */ - $startDate = null; - /** @var \DateTime End Date */ - $endDate = null; - - foreach ($this->datePeriod as $key => $value) { - if ($key == 0) { - $startDate = $value; - } - if ($key == 1) { - $endDate = $value; - } - } - - $ret = -1; - if ($startDate <= $other && $other <= $endDate) { - $ret = 0; - } elseif ($startDate > $other) { - $ret = 1; - } else { - $ret = -1; - } - - return $ret; - } - - /** - * Get Parameter value to test against - * - * @return \DatePeriod - */ - public function getValue() - { - return clone $this->datePeriod; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans('An interval between two dates', null, 'constraint'); - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/ModelParam.php b/core/lib/Thelia/Constraint/Validator/ModelParam.php deleted file mode 100644 index 7ff4567b8..000000000 --- a/core/lib/Thelia/Constraint/Validator/ModelParam.php +++ /dev/null @@ -1,115 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use InvalidArgumentException; -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent a Model - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class ModelParam extends IntegerParam -{ - /** @var string Model Class name */ - protected $modelClass = null; - - /** @var ModelCriteria */ - protected $queryBuilder = null; - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param int $integer Integer - * @param string $modelClass Model class name - * - * @throws InvalidArgumentException - */ - public function __construct(CouponAdapterInterface $adapter, $integer, $modelClass) - { - if ($integer < 0) { - $integer = 0; - } - $this->integer = $integer; - $this->adapter = $adapter; - - $this->modelClass = $modelClass; - $queryClassName = $modelClass . 'Query'; - try { - $this->queryBuilder = $queryClassName::create(); - } catch (\Exception $e) { - throw new InvalidArgumentException('ModelParam can only compare Models'); - } - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!is_integer($other) || $other < 0) { - throw new InvalidArgumentException( - 'IntegerParam can compare only positive int' - ); - } - - return parent::compareTo($other); - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans( - 'A Model', - null, - 'constraint' - ); - } - -} diff --git a/core/lib/Thelia/Constraint/Validator/PriceParam.php b/core/lib/Thelia/Constraint/Validator/PriceParam.php deleted file mode 100644 index e965d6aba..000000000 --- a/core/lib/Thelia/Constraint/Validator/PriceParam.php +++ /dev/null @@ -1,145 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent a Price - * Positive value with currency - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class PriceParam extends RuleParameterAbstract -{ - /** @var float Positive Float to compare with */ - protected $price = null; - - /** @var string Currency Code ISO 4217 EUR|USD|GBP */ - protected $currency = null; - - /** - * Constructor - * - * @param Translator $translator Service translator - * @param float $price Positive float - * @param string $currency Currency Code ISO 4217 EUR|USD|GBP - */ - public function __construct(Translator $translator, $price, $currency) - { - $this->price = $price; - $this->currency = $currency; - $this->translator = $translator; - } - - /** - * Get currency code - * - * @return string - */ - public function getCurrency() - { - return $this->currency; - } - - /** - * Get price - * - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!is_float($other)) { - throw new \InvalidArgumentException( - 'PriceParam can compare only positive float' - ); - } - - $epsilon = 0.00001; - - $ret = -1; - if (abs($this->price - $other) < $epsilon) { - $ret = 0; - } elseif ($this->price > $other) { - $ret = 1; - } else { - $ret = -1; - } - - return $ret; - } - - /** - * Get Parameter value to test against - * - * @return float - */ - public function getValue() - { - return $this->price; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->translator - ->trans( - 'A price in %currency% (ex: 14.50)', - array( - '%currency%' => $this->currency - ), - 'constraint' - ); - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php b/core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php deleted file mode 100644 index 0e8a558cf..000000000 --- a/core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php +++ /dev/null @@ -1,117 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent A repeated Date across the time - * Ex : - * A date repeated every 1 months 5 times - * ---------*---*---*---*---*---*---------------------------> time - * 1 2 3 4 5 6 - * 1 : $this->from Start date of the repetition - * *--- : $this->interval Duration of a whole cycle - * x5 : $this->recurrences How many repeated cycle, 1st excluded - * x6 : How many occurrence - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedDateParam extends RepeatedParam -{ - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - */ - public function __construct(CouponAdapterInterface $adapter) - { - $this->defaultConstructor(); - $this->adapter = $adapter; - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!$other instanceof \DateTime) { - throw new \InvalidArgumentException('RepeatedDateParam can compare only DateTime'); - } - - $ret = -1; - $dates = array(); - /** @var $value \DateTime */ - foreach ($this->datePeriod as $value) { - $dates[$value->getTimestamp()] = $value; - } - - foreach ($dates as $date) { - if ($date == $other) { - return 0; - } - } - - return $ret; - } - - /** - * Get Parameter value to test against - * - * @return \DatePeriod - */ - public function getValue() - { - return clone $this->datePeriod; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint'); - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php b/core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php deleted file mode 100644 index e37cd3b45..000000000 --- a/core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php +++ /dev/null @@ -1,151 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Coupon\CouponAdapterInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Represent A repeated DateInterval across the time - * Ex : - * A duration of 1 month repeated every 2 months 5 times - * ---------****----****----****----****----****----****-----------------> time - * 1 2 3 4 5 6 - * 1 : $this->from Start date of the repetition - * ****---- : $this->interval Duration of a whole cycle - * x5 : $this->recurrences How many repeated cycle, 1st excluded - * x6 : How many occurrence - * **** : $this->durationInDays Duration of a period - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedIntervalParam extends RepeatedParam -{ - - /** @var int duration of the param */ - protected $durationInDays = 1; - - /** - * Get how many day a Param is lasting - * - * @return int - */ - public function getDurationInDays() - { - return $this->durationInDays; - } - - /** - * Set how many day a Param is lasting - * - * @param int $durationInDays How many day a Param is lasting - * - * @return $this - */ - public function setDurationInDays($durationInDays = 1) - { - $this->durationInDays = $durationInDays; - - return $this; - } - - /** - * Constructor - * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - */ - public function __construct(CouponAdapterInterface $adapter) - { - $this->defaultConstructor(); - $this->adapter = $adapter; - } - - /** - * Compare the current object to the passed $other. - * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int - */ - public function compareTo($other) - { - if (!$other instanceof \DateTime) { - throw new \InvalidArgumentException('RepeatedIntervalParam can compare only DateTime'); - } - - $ret = -1; - $dates = array(); - /** @var $value \DateTime */ - foreach ($this->datePeriod as $value) { - $dates[$value->getTimestamp()]['startDate'] = $value; - $endDate = new \DateTime(); - $dates[$value->getTimestamp()]['endDate'] = $endDate->setTimestamp( - $value->getTimestamp() + ($this->durationInDays * 60 *60 *24) - ); - } - - foreach ($dates as $date) { - if ($date['startDate'] <= $other && $other <= $date['endDate']) { - return 0; - } - } - - return $ret; - - } - - /** - * Get Parameter value to test against - * - * @return \DatePeriod - */ - public function getValue() - { - return clone $this->datePeriod; - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return $this->adapter - ->getTranslator() - ->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint'); - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/RepeatedParam.php b/core/lib/Thelia/Constraint/Validator/RepeatedParam.php deleted file mode 100644 index 1188e4fbb..000000000 --- a/core/lib/Thelia/Constraint/Validator/RepeatedParam.php +++ /dev/null @@ -1,297 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use DateInterval; -use DatePeriod; -use DateTime; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Allow to set the way a parameter can be repeated across the time - * - * @package Constraint - * @author Guillaume MOREL - * - */ -abstract class RepeatedParam extends RuleParameterAbstract -{ - /** @var DateTime The start date of the period. */ - protected $from = null; - - /** @var DateInterval The interval between recurrences within the period. */ - protected $interval = null; - - /** @var int Nb time the object will be repeated (1st occurrence excluded). */ - protected $recurrences = null; - - /** @var DatePeriod dates recurring at regular intervals, over a given period */ - protected $datePeriod = null; - - /** @var int Frequency the object will be repeated */ - protected $frequency = null; - - /** @var int $nbRepetition Time the object will be repeated */ - protected $nbRepetition = null; - - /** - * Get frequency - * - * @return int - */ - public function getFrequency() - { - return $this->frequency; - } - - /** - * Get Interval - * - * @return \DateInterval - */ - public function getInterval() - { - return $this->interval; - } - - /** - * Get number of time it will be repeated - * - * @return int - */ - public function getNbRepetition() - { - return $this->nbRepetition; - } - - /** - * Get number of recurrences - * - * @return int - */ - public function getRecurrences() - { - return $this->recurrences; - } - - /** - * Generate default repetition - * Every 1 week 100 times from now - * - * @return $this - */ - protected function defaultConstructor() - { - $this->from = new \DateTime(); - $this->interval = new \DateInterval('P1W'); // 1 week - $this->recurrences = 100; - $this->generateDatePeriod(); - - return $this; - } - - /** - * Generate DatePeriod from class attributes - * Will repeat every DatePeriod - * - * @return $this - */ - protected function generateDatePeriod() - { - $this->datePeriod = new DatePeriod( - $this->from, - $this->interval, - $this->recurrences - ); - - return $this; - } - - /** - * Set the Object to be repeated every days - * Ex : $obj->repeatEveryDay() will occur once - * $obj->repeatEveryDay(10) will occur once - * $obj->repeatEveryDay(10, 0) will occur once - * $obj->repeatEveryDay(10, 4) will occur every 10 days 5 times - * - * @param int $frequency Frequency the object will be repeated - * @param int $nbRepetition Time the object will be repeated - * - * @return $this - */ - public function repeatEveryDay($frequency = 1, $nbRepetition = 0) - { - $this->_repeatEveryPeriod($period = 'D', $frequency, $nbRepetition); - - return $this; - } - - /** - * Set the Object to be repeated every week - * Ex : $obj->repeatEveryWeek() will occur once - * $obj->repeatEveryWeek(10) will occur once - * $obj->repeatEveryWeek(10, 0) will occur once - * $obj->repeatEveryWeek(10, 4) will occur every 10 weeks (70days) 5 times - * - * @param int $frequency Frequency the object will be repeated - * @param int $nbRepetition Time the object will be repeated - * - * @return $this - */ - public function repeatEveryWeek($frequency = 1, $nbRepetition = 0) - { - $this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition); - - return $this; - } - - /** - * Set the Object to be repeated every month - * Ex : $obj->repeatEveryWeek() will occur once - * $obj->repeatEveryWeek(10) will occur once - * $obj->repeatEveryWeek(10, 0) will occur once - * $obj->repeatEveryWeek(10, 4) will occur every 10 month (70days) 5times - * - * @param int $frequency Frequency the object will be repeated - * @param int $nbRepetition Time the object will be repeated - * - * @return $this - */ - public function repeatEveryMonth($frequency = 1, $nbRepetition = 0) - { - $this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition); - - return $this; - } - - /** - * Set the Object to be repeated every year - * Ex : $obj->repeatEveryWeek() will occur once - * $obj->repeatEveryWeek(10) will occur once - * $obj->repeatEveryWeek(10, 0) will occur once - * $obj->repeatEveryWeek(10, 4) will occur every 10 year 5 times - * - * @param int $frequency Frequency the object will be repeated - * @param int $nbRepetition Time the object will be repeated - * - * @return $this - */ - public function repeatEveryYear($frequency = 1, $nbRepetition = 0) - { - $this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition); - - return $this; - } - - /** - * Set the Object to be repeated every Period - * Ex : $obj->repeatEveryPeriod('D') will occur once - * $obj->repeatEveryPeriod('W', 10) will occur once - * $obj->repeatEveryPeriod('W', 10, 0) will occur once - * $obj->repeatEveryPeriod('M', 10, 4) will occur every 10 month 5 times - * - * @param string $period Period Y|M||D|W - * @param int $frequency Frequency the object will be repeated - * @param int $nbRepetition Time the object will be repeated - * - * @return $this - */ - private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = 0) - { - if (is_numeric($frequency) && $frequency > 0) { - $this->interval = new \DateInterval('P' . $frequency . $period); - } - - if (is_numeric($nbRepetition) && $nbRepetition >= 0) { - $this->recurrences = $nbRepetition; - } - - $this->generateDatePeriod(); - - return $this; - } - - - - /** - * Set Start time - * - * @param \DateTime $from Start time - * - * @return $this - */ - public function setFrom($from) - { - $this->from = $from; - - return $this; - } - - /** - * Get Start time - * - * @return \DateTime - */ - public function getFrom() - { - return clone $this->from; - } - - /** - * Set DatePeriod - * - * @param DatePeriod $datePeriod DatePeriod - * - * @return $this - */ - public function setDatePeriod(DatePeriod $datePeriod) - { - $this->datePeriod = $datePeriod; - - return $this; - } - - /** - * Get date DatePeriod - * - * @return \DatePeriod - */ - public function getDatePeriod() - { - return clone $this->datePeriod; - } - - /** - * Get Parameter value to test against - * - * @return \DatePeriod - */ - public function getValue() - { - return clone $this->datePeriod; - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/RuleParameterAbstract.php b/core/lib/Thelia/Constraint/Validator/RuleParameterAbstract.php deleted file mode 100644 index 2be4c581f..000000000 --- a/core/lib/Thelia/Constraint/Validator/RuleParameterAbstract.php +++ /dev/null @@ -1,67 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Exception\NotImplementedException; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Get a Param value - * - * @package Constraint - * @author Guillaume MOREL - * - */ -abstract class RuleParameterAbstract implements ComparableInterface -{ - /** @var Translator Service Translator */ - protected $translator = null; - - /** - * Get Parameter value to test against - * - * @return mixed - */ - public function getValue() - { - return new NotImplementedException(); - } - - /** - * Get I18n tooltip - * - * @return string - */ - public function getToolTip() - { - return new NotImplementedException(); - } - - -} \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Validator/RuleValidator.php b/core/lib/Thelia/Constraint/Validator/RuleValidator.php deleted file mode 100644 index 9b0093bc9..000000000 --- a/core/lib/Thelia/Constraint/Validator/RuleValidator.php +++ /dev/null @@ -1,77 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint\Validator; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Allow to validate parameters - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RuleValidator -{ - /** @var string Operator ex: Operators::INFERIOR */ - protected $operator = null; - - /** @var ComparableInterface Validator */ - protected $param = null; - - /** - * Constructor - * - * @param string $operator Operator ex: Operators::INFERIOR - * @param ComparableInterface $param Validator ex: PriceParam - */ - function __construct($operator, ComparableInterface $param) - { - $this->operator = $operator; - $this->param = $param; - } - - /** - * Get Validator Operator - * - * @return string - */ - public function getOperator() - { - return $this->operator; - } - - /** - * Get Validator Param - * - * @return ComparableInterface - */ - public function getParam() - { - return $this->param; - } - -} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 1c7b1c603..f1882920e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -25,33 +25,22 @@ namespace Thelia\Controller\Admin; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Router; -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\ConstraintFactoryTest; -use Thelia\Constraint\Rule\AvailableForTotalAmount; -use Thelia\Constraint\Rule\CouponRuleInterface; -use Thelia\Constraint\Validator\PriceParam; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\ConditionManagerInterface; +use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; -use Thelia\Core\Event\Coupon\CouponCreateEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; -use Thelia\Core\Event\Coupon\CouponEvent; use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\HttpFoundation\Session\Session; -use Thelia\Core\Security\Exception\AuthenticationException; -use Thelia\Core\Security\Exception\AuthorizationException; use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Coupon\CouponFactory; use Thelia\Coupon\CouponManager; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\Type\CouponInterface; use Thelia\Form\CouponCreationForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Log\Tlog; use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; -use Thelia\Model\CurrencyQuery; use Thelia\Model\Lang; -use Thelia\Model\LangQuery; use Thelia\Tools\I18n; /** @@ -189,8 +178,9 @@ class CouponController extends BaseAdminController /** @var Coupon $coupon */ $coupon = CouponQuery::create()->findPk($couponId); - if (!$coupon) { - $this->pageNotFound(); + if (null === $coupon) { + return $this->pageNotFound(); + } // Parameters given to the template @@ -210,12 +200,12 @@ class CouponController extends BaseAdminController 'updated', 'update' ); - } else { // Display - + } else { + // Display // Prepare the data that will hydrate the form - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); - $rules = $constraintFactory->unserializeCouponRuleCollection( + /** @var ConditionFactory $constraintFactory */ + $constraintFactory = $this->container->get('thelia.condition.factory'); + $conditions = $constraintFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); @@ -232,23 +222,23 @@ class CouponController extends BaseAdminController 'isCumulative' => ($coupon->getIsCumulative() == 1), 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), 'maxUsage' => $coupon->getMaxUsage(), - 'rules' => $rules, + 'rules' => $conditions, 'locale' => $coupon->getLocale(), ); $args['rulesObject'] = array(); - /** @var CouponRuleInterface $rule */ - foreach ($rules->getRules() as $rule) { + /** @var ConditionManagerInterface $condition */ + foreach ($conditions->getConditions() as $condition) { $args['rulesObject'][] = array( - 'serviceId' => $rule->getServiceId(), - 'name' => $rule->getName(), - 'tooltip' => $rule->getToolTip(), - 'validators' => $rule->getValidators() + 'serviceId' => $condition->getServiceId(), + 'name' => $condition->getName(), + 'tooltip' => $condition->getToolTip(), + 'validators' => $condition->getValidators() ); } - $args['rules'] = $this->cleanRuleForTemplate($rules); + $args['rules'] = $this->cleanConditionForTemplate($conditions); // Setup the object form $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data); @@ -258,7 +248,7 @@ class CouponController extends BaseAdminController } $args['couponCode'] = $coupon->getCode(); $args['availableCoupons'] = $this->getAvailableCoupons(); - $args['availableRules'] = $this->getAvailableRules(); + $args['availableConditions'] = $this->getAvailableConditions(); $args['urlAjaxGetRuleInput'] = $this->getRoute( 'admin.coupon.rule.input', array('ruleId' => 'ruleId'), @@ -289,16 +279,16 @@ class CouponController extends BaseAdminController $this->checkXmlHttpRequest(); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); - $inputs = $constraintFactory->getInputs($ruleId); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $inputs = $conditionFactory->getInputs($ruleId); if ($inputs === null) { return $this->pageNotFound(); } return $this->render( - 'coupon/rule-input-ajax', + 'coupon/condition-input-ajax', array( 'ruleId' => $ruleId, 'inputs' => $inputs @@ -328,45 +318,45 @@ class CouponController extends BaseAdminController return $this->pageNotFound(); } - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); - $rulesReceived = json_decode($this->getRequest()->get('rules')); - foreach ($rulesReceived as $ruleReceived) { - $rule = $constraintFactory->build( - $ruleReceived->serviceId, - (array) $ruleReceived->operators, - (array) $ruleReceived->values + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditionsReceived = json_decode($this->getRequest()->get('rules')); + foreach ($conditionsReceived as $conditionReceived) { + $rule = $conditionFactory->build( + $conditionReceived->serviceId, + (array) $conditionReceived->operators, + (array) $conditionReceived->values ); $rules->add(clone $rule); } - $coupon->setSerializedRules( - $constraintFactory->serializeCouponRuleCollection($rules) - ); +// $coupon->setSerializedRules( +// $constraintFactory->serializeCouponRuleCollection($rules) +// ); - $couponEvent = new CouponCreateOrUpdateEvent( - $coupon->getCode(), $coupon->getTitle(), $coupon->getAmount(), $coupon->getType(), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), $coupon->getExpirationDate(), $coupon->getIsAvailableOnSpecialOffers(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getMaxUsage(), $coupon->getLocale() + $conditionEvent = new ConditionCreateOrUpdateEvent( + $rules ); - $couponEvent->setCoupon($coupon); + $conditionEvent->setCouponModel($coupon); - $eventToDispatch = TheliaEvents::COUPON_RULE_UPDATE; + $eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE; // Dispatch Event to the Action $this->dispatch( $eventToDispatch, - $couponEvent + $conditionEvent ); $this->adminLogAppend( sprintf( 'Coupon %s (ID %s) rules updated', - $couponEvent->getTitle(), - $couponEvent->getCoupon()->getId() + $conditionEvent->getCouponModel()->getTitle(), + $conditionEvent->getCouponModel()->getServiceId() ) ); - $cleanedRules = $this->cleanRuleForTemplate($rules); + $cleanedRules = $this->cleanConditionForTemplate($rules); return $this->render( 'coupon/rules', @@ -384,6 +374,8 @@ class CouponController extends BaseAdminController * * @param string $couponCode Coupon code * + * @todo remove (event dispatcher testing purpose) + * */ public function consumeAction($couponCode) { @@ -421,7 +413,7 @@ class CouponController extends BaseAdminController $couponBeingCreated->setIsEnabled($data['isEnabled']); $couponBeingCreated->setExpirationDate($data['expirationDate']); $couponBeingCreated->setSerializedRules( - new CouponRuleCollection( + new ConditionCollection( array() ) ); @@ -537,22 +529,22 @@ class CouponController extends BaseAdminController * * @return array */ - protected function getAvailableRules() + protected function getAvailableConditions() { /** @var CouponManager $couponManager */ $couponManager = $this->container->get('thelia.coupon.manager'); - $availableRules = $couponManager->getAvailableRules(); - $cleanedRules = array(); - /** @var CouponRuleInterface $availableRule */ - foreach ($availableRules as $availableRule) { - $rule = array(); - $rule['serviceId'] = $availableRule->getServiceId(); - $rule['name'] = $availableRule->getName(); - $rule['toolTip'] = $availableRule->getToolTip(); - $cleanedRules[] = $rule; + $availableConditions = $couponManager->getAvailableConditions(); + $cleanedConditions = array(); + /** @var ConditionManagerInterface $availableCondition */ + foreach ($availableConditions as $availableCondition) { + $condition = array(); + $condition['serviceId'] = $availableCondition->getServiceId(); + $condition['name'] = $availableCondition->getName(); + $condition['toolTip'] = $availableCondition->getToolTip(); + $cleanedConditions[] = $condition; } - return $cleanedRules; + return $cleanedConditions; } /** @@ -579,18 +571,21 @@ class CouponController extends BaseAdminController } /** - * @param $rules + * Clean rule for template + * + * @param ConditionCollection $conditions Condition collection + * * @return array */ - protected function cleanRuleForTemplate($rules) + protected function cleanConditionForTemplate(ConditionCollection $conditions) { - $cleanedRules = array(); - /** @var $rule CouponRuleInterface */ - foreach ($rules->getRules() as $rule) { - $cleanedRules[] = $rule->getToolTip(); + $cleanedConditions = array(); + /** @var $condition ConditionManagerInterface */ + foreach ($conditions->getConditions() as $condition) { + $cleanedConditions[] = $condition->getToolTip(); } - return $cleanedRules; + return $cleanedConditions; } // /** @@ -604,7 +599,7 @@ class CouponController extends BaseAdminController // */ // protected function validateRulesCreation($type, $operator, $values) // { -// /** @var CouponAdapterInterface $adapter */ +// /** @var AdapterInterface $adapter */ // $adapter = $this->container->get('thelia.adapter'); // $validator = new PriceParam() // try { diff --git a/core/lib/Thelia/Constraint/Validator/QuantityParam.php b/core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php similarity index 56% rename from core/lib/Thelia/Constraint/Validator/QuantityParam.php rename to core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php index ac6fcf851..58fdb10fe 100644 --- a/core/lib/Thelia/Constraint/Validator/QuantityParam.php +++ b/core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php @@ -21,76 +21,86 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint\Validator; +namespace Thelia\Core\Event\Condition; -use Thelia\Coupon\CouponAdapterInterface; +use Thelia\Core\Event\ActionEvent; +use Thelia\Coupon\ConditionCollection; +use Thelia\Coupon\Type\CouponInterface; /** * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM + * Date: 8/29/13 + * Time: 3:45 PM * - * Represent a Quantity + * Occurring when a Condition is created or updated * - * @package Constraint + * @package Coupon * @author Guillaume MOREL * */ -class QuantityParam extends IntegerParam +class ConditionCreateOrUpdateEvent extends ActionEvent { + /** @var ConditionCollection Array of ConditionManagerInterface */ + protected $conditions = null; + + /** @var CouponInterface Coupon model associated with this conditions */ + protected $couponModel = null; /** * Constructor * - * @param CouponAdapterInterface $adapter Provide necessary value from Thelia - * @param int $integer Integer + * @param ConditionCollection $conditions Array of ConditionManagerInterface */ - public function __construct(CouponAdapterInterface $adapter, $integer) + public function __construct(ConditionCollection $conditions) { - $this->integer = $integer; - $this->adapter = $adapter; + $this->conditions = $conditions; } /** - * Compare the current object to the passed $other. + * Get Conditions * - * Returns 0 if they are semantically equal, 1 if the other object - * is less than the current one, or -1 if its more than the current one. - * - * This method should not check for identity using ===, only for semantically equality for example - * when two different DateTime instances point to the exact same Date + TZ. - * - * @param mixed $other Object - * - * @throws \InvalidArgumentException - * @return int + * @return null|ConditionCollection Array of ConditionManagerInterface */ - public function compareTo($other) + public function getConditions() { - if (!is_integer($other) || $other < 0) { - throw new \InvalidArgumentException( - 'IntegerParam can compare only positive int' - ); - } - - return parent::compareTo($other); + return $this->conditions; } - /** - * Get I18n tooltip + * Set Conditions * - * @return string + * @param ConditionCollection $conditions Array of ConditionManagerInterface + * + * @return $this */ - public function getToolTip() + public function setConditions(ConditionCollection $conditions) { - return $this->adapter - ->getTranslator() - ->trans( - 'A positive quantity (ex: 42)', - null, - 'constraint' - ); + $this->conditions = $conditions; + + return $this; } + /** + * Set Coupon Model associated to this condition + * + * @param CouponInterface $couponModel Coupon Model + * + * @return $this + */ + public function setCouponModel($couponModel) + { + $this->couponModel = $couponModel; + + return $this; + } + + /** + * Get Coupon Model associated to this condition + * + * @return null|CouponInterface + */ + public function getCouponModel() + { + return $this->couponModel; + } } diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php index df5cef7a9..ace8cb0b7 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php @@ -23,8 +23,6 @@ namespace Thelia\Core\Event\Coupon; use Thelia\Core\Event\ActionEvent; -use Thelia\Coupon\CouponRuleCollection; -use Thelia\Model\Coupon; /** * Created by JetBrains PhpStorm. @@ -56,7 +54,7 @@ class CouponConsumeEvent extends ActionEvent * @param bool $isValid If Coupon is valid or * if Customer meets coupon conditions */ - function __construct($code, $discount = null, $isValid = null) + public function __construct($code, $discount = null, $isValid = null) { $this->code = $code; $this->discount = $discount; @@ -136,7 +134,4 @@ class CouponConsumeEvent extends ActionEvent return $this->isValid; } - - - } diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 4b85065dc..3dfca3d4a 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Event\Coupon; use Thelia\Core\Event\ActionEvent; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; use Thelia\Model\Coupon; /** @@ -39,8 +39,8 @@ use Thelia\Model\Coupon; */ class CouponCreateOrUpdateEvent extends ActionEvent { - /** @var CouponRuleCollection Array of CouponRuleInterface */ - protected $rules = null; + /** @var ConditionCollection Array of ConditionManagerInterface */ + protected $conditions = null; /** @var string Coupon code (ex: XMAS) */ protected $code = null; @@ -87,23 +87,24 @@ class CouponCreateOrUpdateEvent extends ActionEvent /** * Constructor * - * @param string $code Coupon Code - * @param string $title Coupon title - * @param float $amount Amount removed from the Total Checkout - * @param string $type Coupon type - * @param string $shortDescription Coupon short description - * @param string $description Coupon description - * @param boolean $isEnabled Enable/Disable + * @param string $code Coupon Code + * @param string $title Coupon title + * @param float $amount Amount removed from the Total Checkout + * @param string $type Coupon type + * @param string $shortDescription Coupon short description + * @param string $description Coupon description + * @param bool $isEnabled Enable/Disable * @param \DateTime $expirationDate Coupon expiration date - * @param boolean $isAvailableOnSpecialOffers Is available on special offers - * @param boolean $isCumulative Is cumulative - * @param boolean $isRemovingPostage Is removing Postage - * @param int $maxUsage Coupon quantity - * @param string $locale Coupon Language code ISO (ex: fr_FR) + * @param boolean $isAvailableOnSpecialOffers Is available on special offers + * @param boolean $isCumulative Is cumulative + * @param boolean $isRemovingPostage Is removing Postage + * @param int $maxUsage Coupon quantity + * @param string $locale Coupon Language code ISO (ex: fr_FR) */ public function __construct( $code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale - ) { + ) + { $this->amount = $amount; $this->code = $code; $this->description = $description; @@ -276,4 +277,28 @@ class CouponCreateOrUpdateEvent extends ActionEvent return $this->coupon; } + /** + * Get Rules + * + * @return null|ConditionCollection Array of ConditionManagerInterface + */ + public function getConditions() + { + return $this->conditions; + } + + /** + * set Rules + * + * @param ConditionCollection $rules Array of ConditionManagerInterface + * + * @return $this + */ + public function setConditions(ConditionCollection $rules) + { + $this->conditions = $rules; + + return $this; + } + } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index ee49d239b..478e0d945 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -365,19 +365,19 @@ final class TheliaEvents const AFTER_CONSUME_COUPON = "action.after_consume_coupon"; /** - * Sent when attempting to update Coupon Rule + * Sent when attempting to update Coupon Condition */ - const COUPON_RULE_UPDATE = "action.update_coupon_rule"; + const COUPON_CONDITION_UPDATE = "action.update_coupon_condition"; /** - * Sent just before an attempt to update a Coupon Rule + * Sent just before an attempt to update a Coupon Condition */ - const BEFORE_COUPON_RULE_UPDATE = "action.before_update_coupon_rule"; + const BEFORE_COUPON_CONDITION_UPDATE = "action.before_update_coupon_condition"; /** - * Sent just after an attempt to update a Coupon Rule + * Sent just after an attempt to update a Coupon Condition */ - const AFTER_COUPON_RULE_UPDATE = "action.after_update_coupon_rule"; + const AFTER_COUPON_CONDITION_UPDATE = "action.after_update_coupon_condition"; // -- Configuration management --------------------------------------------- diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 9b720ef13..16c20c4e8 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -95,7 +95,7 @@ class Coupon extends BaseI18nLoop $loopResult = new LoopResult(); /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); + $constraintFactory = $this->container->get('thelia.condition.factory'); /** @var Request $request */ $request = $this->container->get('request'); diff --git a/core/lib/Thelia/Coupon/CouponAdapterInterface.php b/core/lib/Thelia/Coupon/AdapterInterface.php similarity index 94% rename from core/lib/Thelia/Coupon/CouponAdapterInterface.php rename to core/lib/Thelia/Coupon/AdapterInterface.php index 413fc3df6..4ca2b67aa 100644 --- a/core/lib/Thelia/Coupon/CouponAdapterInterface.php +++ b/core/lib/Thelia/Coupon/AdapterInterface.php @@ -27,6 +27,8 @@ use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Condition\ConditionEvaluator; +use Thelia\Core\HttpFoundation\Request; use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; @@ -35,13 +37,13 @@ use Thelia\Model\Coupon; * Date: 8/19/13 * Time: 3:24 PM * - * Allow a CouponManager class to be fed with relevant Thelia data + * Allow to assist in getting relevant data on the current application state * * @package Coupon * @author Guillaume MOREL * */ -interface CouponAdapterInterface +interface AdapterInterface { /** @@ -163,11 +165,11 @@ interface CouponAdapterInterface public function getRequest(); /** - * Return Constraint Validator + * Return Condition Validator * - * @return ConstraintValidator + * @return ConditionEvaluator */ - public function getConstraintValidator(); + public function getConditionValidator(); /** * Return all available currencies diff --git a/core/lib/Thelia/Coupon/CouponBaseAdapter.php b/core/lib/Thelia/Coupon/BaseAdapter.php similarity index 96% rename from core/lib/Thelia/Coupon/CouponBaseAdapter.php rename to core/lib/Thelia/Coupon/BaseAdapter.php index 083d1843d..6963ef0d6 100644 --- a/core/lib/Thelia/Coupon/CouponBaseAdapter.php +++ b/core/lib/Thelia/Coupon/BaseAdapter.php @@ -27,7 +27,7 @@ use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; -use Thelia\Constraint\ConstraintValidator; +use Thelia\Constraint\ConditionValidator; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Security\SecurityContext; use Thelia\Coupon\Type\CouponInterface; @@ -43,12 +43,14 @@ use Thelia\Model\LangQuery; * Date: 8/19/13 * Time: 3:24 PM * + * Allow to assist in getting relevant data on the current application state + * * @package Coupon * @author Guillaume MOREL * @todo implements * */ -class CouponBaseAdapter implements CouponAdapterInterface +class BaseAdapter implements AdapterInterface { use CartTrait { CartTrait::getCart as getCartFromTrait; @@ -262,11 +264,11 @@ class CouponBaseAdapter implements CouponAdapterInterface /** * Return Constraint Validator * - * @return ConstraintValidator + * @return ConditionValidator */ - public function getConstraintValidator() + public function getConditionValidator() { - return $this->container->get('thelia.constraint.validator'); + return $this->container->get('thelia.condition.validator'); } diff --git a/core/lib/Thelia/Coupon/CouponRuleCollection.php b/core/lib/Thelia/Coupon/ConditionCollection.php similarity index 72% rename from core/lib/Thelia/Coupon/CouponRuleCollection.php rename to core/lib/Thelia/Coupon/ConditionCollection.php index 29bf170e9..21e694aef 100644 --- a/core/lib/Thelia/Coupon/CouponRuleCollection.php +++ b/core/lib/Thelia/Coupon/ConditionCollection.php @@ -24,6 +24,7 @@ namespace Thelia\Coupon; use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\Condition\ConditionManagerInterface; use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Constraint\Rule\SerializableRule; @@ -32,70 +33,62 @@ use Thelia\Constraint\Rule\SerializableRule; * Date: 8/19/13 * Time: 3:24 PM * - * Manage a set of CouponRuleInterface + * Manage a set of ConditionManagerInterface * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ -class CouponRuleCollection +class ConditionCollection { - /** @var array Array of CouponRuleInterface */ - protected $rules = array(); + /** @var array Array of ConditionManagerInterface */ + protected $conditions = array(); /** - * Constructor + * Get Conditions + * + * @return array Array of ConditionManagerInterface */ - function __construct() + public function getConditions() { - + return $this->conditions; } /** - * Get Rules + * Add a ConditionManagerInterface to the Collection * - * @return array Array of CouponRuleInterface - */ - public function getRules() - { - return $this->rules; - } - - /** - * Add a CouponRuleInterface to the Collection - * - * @param CouponRuleInterface $rule Rule + * @param ConditionManagerInterface $condition Condition * * @return $this */ - public function add(CouponRuleInterface $rule) + public function add(ConditionManagerInterface $condition) { - $this->rules[] = $rule; + $this->conditions[] = $condition; return $this; } /** - * Check if there is at least one rule in the collection + * Check if there is at least one condition in the collection * * @return bool */ public function isEmpty() { - return (empty($this->rules)); + return (empty($this->conditions)); } /** - * Allow to compare 2 set of rules + * Allow to compare 2 set of conditions * * @return string Jsoned data */ public function __toString() { $arrayToSerialize = array(); - /** @var CouponRuleInterface $rule */ - foreach ($this->getRules() as $rule) { - $arrayToSerialize[] = $rule->getSerializableRule(); + /** @var ConditionManagerInterface $condition */ + foreach ($this->getConditions() as $condition) { + $arrayToSerialize[] = $condition->getSerializableCondition(); } return json_encode($arrayToSerialize); diff --git a/core/lib/Thelia/Coupon/CouponFactory.php b/core/lib/Thelia/Coupon/CouponFactory.php index 2f0c799a8..64c0058b4 100644 --- a/core/lib/Thelia/Coupon/CouponFactory.php +++ b/core/lib/Thelia/Coupon/CouponFactory.php @@ -49,7 +49,7 @@ class CouponFactory /** @var ContainerInterface Service Container */ protected $container = null; - /** @var CouponAdapterInterface Provide necessary value from Thelia*/ + /** @var AdapterInterface Provide necessary value from Thelia*/ protected $adapter; /** @@ -131,7 +131,7 @@ class CouponFactory ); /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.constraint.factory'); + $constraintFactory = $this->container->get('thelia.condition.factory'); $rules = $constraintFactory->unserializeCouponRuleCollection( $model->getSerializedRules() ); diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php index d8575c3e6..c4ba661be 100644 --- a/core/lib/Thelia/Coupon/CouponManager.php +++ b/core/lib/Thelia/Coupon/CouponManager.php @@ -24,7 +24,7 @@ namespace Thelia\Coupon; use Symfony\Component\DependencyInjection\ContainerInterface; -use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Condition\ConditionManagerInterface; use Thelia\Coupon\Type\CouponInterface; /** @@ -40,7 +40,7 @@ use Thelia\Coupon\Type\CouponInterface; */ class CouponManager { - /** @var CouponAdapterInterface Provides necessary value from Thelia */ + /** @var AdapterInterface Provides necessary value from Thelia */ protected $adapter = null; /** @var ContainerInterface Service Container */ @@ -52,15 +52,15 @@ class CouponManager /** @var array Available Coupons (Services) */ protected $availableCoupons = array(); - /** @var array Available Rules (Services) */ - protected $availableRules = array(); + /** @var array Available Conditions (Services) */ + protected $availableConditions = array(); /** * Constructor * * @param ContainerInterface $container Service container */ - function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container) { $this->container = $container; $this->adapter = $container->get('thelia.adapter'); @@ -191,29 +191,29 @@ class CouponManager } /** - * Build a CouponRuleInterface from data coming from a form + * Build a ConditionManagerInterface from data coming from a form * - * @param string $ruleServiceId Rule service id you want to instantiate - * @param array $operators Rule Operator set by the Admin - * @param array $values Rule Values set by the Admin + * @param string $conditionServiceId Condition service id you want to instantiate + * @param array $operators Condition Operator set by the Admin + * @param array $values Condition Values set by the Admin * - * @return CouponRuleInterface + * @return ConditionManagerInterface */ - public function buildRuleFromForm($ruleServiceId, array $operators, array $values) + public function buildRuleFromForm($conditionServiceId, array $operators, array $values) { - $rule = false; + $condition = false; try { - if ($this->container->has($ruleServiceId)) { - /** @var CouponRuleInterface $rule */ - $rule = $this->container->get($ruleServiceId); - $rule->populateFromForm($operators, $values); + if ($this->container->has($conditionServiceId)) { + /** @var ConditionManagerInterface $condition */ + $condition = $this->container->get($conditionServiceId); + $condition->populateFromForm($operators, $values); } } catch (\InvalidArgumentException $e) { } - return $rule; + return $condition; } /** @@ -239,11 +239,11 @@ class CouponManager /** * Add an available ConstraintManager (Services) * - * @param CouponRuleInterface $rule CouponRuleInterface + * @param ConditionManagerInterface $condition ConditionManagerInterface */ - public function addAvailableRule(CouponRuleInterface $rule) + public function addAvailableRule(ConditionManagerInterface $condition) { - $this->availableRules[] = $rule; + $this->availableConditions[] = $condition; } /** @@ -251,8 +251,8 @@ class CouponManager * * @return array */ - public function getAvailableRules() + public function getAvailableConditions() { - return $this->availableRules; + return $this->availableConditions; } } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/RuleOrganizer.php b/core/lib/Thelia/Coupon/RuleOrganizer.php index 4c16ea1ff..4c95fb7c4 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizer.php +++ b/core/lib/Thelia/Coupon/RuleOrganizer.php @@ -37,11 +37,11 @@ namespace Thelia\Coupon; class RuleOrganizer implements RuleOrganizerInterface { /** - * Organize CouponRuleInterface + * Organize ConditionManagerInterface * - * @param array $rules Array of CouponRuleInterface + * @param array $rules Array of ConditionManagerInterface * - * @return array Array of CouponRuleInterface sorted + * @return array Array of ConditionManagerInterface sorted */ public function organize(array $rules) { diff --git a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php index b8b222028..37a3334f3 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php +++ b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php @@ -37,11 +37,11 @@ namespace Thelia\Coupon; interface RuleOrganizerInterface { /** - * Organize CouponRuleInterface + * Organize ConditionManagerInterface * - * @param array $rules Array of CouponRuleInterface + * @param array $rules Array of ConditionManagerInterface * - * @return array Array of CouponRuleInterface sorted + * @return array Array of ConditionManagerInterface sorted */ public function organize(array $rules); } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index 45e1427f1..ef5e17a27 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -25,10 +25,10 @@ namespace Thelia\Coupon\Type; use Symfony\Component\Intl\Exception\NotImplementedException; use Thelia\Constraint\ConstraintManager; -use Thelia\Constraint\ConstraintValidator; +use Thelia\Constraint\ConditionValidator; use Thelia\Core\Translation\Translator; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\AdapterInterface; +use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\RuleOrganizerInterface; use Thelia\Exception\InvalidRuleException; @@ -45,7 +45,7 @@ use Thelia\Exception\InvalidRuleException; */ abstract class CouponAbstract implements CouponInterface { - /** @var CouponAdapterInterface Provide necessary value from Thelia */ + /** @var AdapterInterface Provide necessary value from Thelia */ protected $adapter = null; /** @var Translator Service Translator */ @@ -54,10 +54,10 @@ abstract class CouponAbstract implements CouponInterface /** @var RuleOrganizerInterface */ protected $organizer = null; - /** @var CouponRuleCollection Array of CouponRuleInterface */ + /** @var ConditionCollection Array of ConditionManagerInterface */ protected $rules = null; - /** @var ConstraintValidator Constraint validator */ + /** @var ConditionValidator Constraint validator */ protected $constraintValidator = null; @@ -106,13 +106,13 @@ abstract class CouponAbstract implements CouponInterface /** * Constructor * - * @param CouponAdapterInterface $adapter Service adapter + * @param AdapterInterface $adapter Service adapter */ - function __construct(CouponAdapterInterface $adapter) + function __construct(AdapterInterface $adapter) { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->constraintValidator = $adapter->getConstraintValidator(); + $this->constraintValidator = $adapter->getConditionValidator(); } /** @@ -205,7 +205,7 @@ abstract class CouponAbstract implements CouponInterface /** * Return condition to validate the Coupon or not * - * @return CouponRuleCollection + * @return ConditionCollection */ public function getRules() { @@ -216,12 +216,12 @@ abstract class CouponAbstract implements CouponInterface * Replace the existing Rules by those given in parameter * If one Rule is badly implemented, no Rule will be added * - * @param CouponRuleCollection $rules CouponRuleInterface to add + * @param ConditionCollection $rules ConditionManagerInterface to add * * @return $this * @throws \Thelia\Exception\InvalidRuleException */ - public function setRules(CouponRuleCollection $rules) + public function setRules(ConditionCollection $rules) { $this->rules = $rules; @@ -301,7 +301,7 @@ abstract class CouponAbstract implements CouponInterface /** * Check if the current Coupon is matching its conditions (Rules) - * Thelia variables are given by the CouponAdapterInterface + * Thelia variables are given by the AdapterInterface * * @return bool */ diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index be76c1878..d8ef41f43 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -23,8 +23,8 @@ namespace Thelia\Coupon\Type; -use Thelia\Coupon\CouponAdapterInterface; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\AdapterInterface; +use Thelia\Coupon\ConditionCollection; /** * Created by JetBrains PhpStorm. @@ -140,7 +140,7 @@ interface CouponInterface /** * Return condition to validate the Coupon or not * - * @return CouponRuleCollection A set of CouponRuleInterface + * @return ConditionCollection A set of ConditionManagerInterface */ public function getRules(); @@ -148,12 +148,12 @@ interface CouponInterface * Replace the existing Rules by those given in parameter * If one Rule is badly implemented, no Rule will be added * - * @param CouponRuleCollection $rules CouponRuleInterface to add + * @param ConditionCollection $rules ConditionManagerInterface to add * * @return $this * @throws \Thelia\Exception\InvalidRuleException */ - public function setRules(CouponRuleCollection $rules); + public function setRules(ConditionCollection $rules); /** * Return Coupon expiration date @@ -209,7 +209,7 @@ interface CouponInterface /** * Check if the current Coupon is matching its conditions (Rules) - * Thelia variables are given by the CouponAdapterInterface + * Thelia variables are given by the AdapterInterface * * @return bool */ diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php index c200c620e..be6b65aea 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php @@ -23,7 +23,7 @@ namespace Thelia\Coupon\Type; -use Thelia\Coupon\CouponAdapterInterface; +use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\Type\CouponAbstract; use Thelia\Exception\MissingAdapterException; diff --git a/core/lib/Thelia/Exception/InvalidRuleValueException.php b/core/lib/Thelia/Exception/InvalidConditionOperatorException.php similarity index 87% rename from core/lib/Thelia/Exception/InvalidRuleValueException.php rename to core/lib/Thelia/Exception/InvalidConditionOperatorException.php index 2f16f32f1..eaef6b9fc 100644 --- a/core/lib/Thelia/Exception/InvalidRuleValueException.php +++ b/core/lib/Thelia/Exception/InvalidConditionOperatorException.php @@ -30,24 +30,23 @@ use Thelia\Log\Tlog; * Date: 8/19/13 * Time: 3:24 PM * - * Thrown when a Rule receive an invalid Parameter + * Thrown when a Condition receive an invalid Operator * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ -class InvalidRuleValueException extends \RuntimeException +class InvalidConditionOperatorException extends \RuntimeException { /** - * InvalidRuleValueException thrown when a Rule is given a bad Parameter + * InvalidConditionOperatorException thrown when a Condition is given a bad Operator * * @param string $className Class name * @param string $parameter array key parameter */ public function __construct($className, $parameter) { - - $message = 'Invalid Parameter for Rule ' . $className . ' on parameter ' . $parameter; + $message = 'Invalid Operator for Condition ' . $className . ' on parameter ' . $parameter; Tlog::getInstance()->addError($message); parent::__construct($message); diff --git a/core/lib/Thelia/Exception/InvalidRuleOperatorException.php b/core/lib/Thelia/Exception/InvalidConditionValueException.php similarity index 87% rename from core/lib/Thelia/Exception/InvalidRuleOperatorException.php rename to core/lib/Thelia/Exception/InvalidConditionValueException.php index d40c723c2..46e3d3628 100644 --- a/core/lib/Thelia/Exception/InvalidRuleOperatorException.php +++ b/core/lib/Thelia/Exception/InvalidConditionValueException.php @@ -30,16 +30,16 @@ use Thelia\Log\Tlog; * Date: 8/19/13 * Time: 3:24 PM * - * Thrown when a Rule receive an invalid Operator + * Thrown when a Condition receives an invalid Parameter * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ -class InvalidRuleOperatorException extends \RuntimeException +class InvalidConditionValueException extends \RuntimeException { /** - * InvalidRuleOperatorException thrown when a Rule is given a bad Operator + * InvalidConditionValueException thrown when a Condition is given a bad Parameter * * @param string $className Class name * @param string $parameter array key parameter @@ -47,7 +47,7 @@ class InvalidRuleOperatorException extends \RuntimeException public function __construct($className, $parameter) { - $message = 'Invalid Operator for Rule ' . $className . ' on parameter ' . $parameter; + $message = 'Invalid Parameter for Condition ' . $className . ' on parameter ' . $parameter; Tlog::getInstance()->addError($message); parent::__construct($message); diff --git a/core/lib/Thelia/Exception/InvalidRuleException.php b/core/lib/Thelia/Exception/InvalidRuleException.php index a891ded4a..f2eb48a84 100644 --- a/core/lib/Thelia/Exception/InvalidRuleException.php +++ b/core/lib/Thelia/Exception/InvalidRuleException.php @@ -39,7 +39,7 @@ use Thelia\Log\Tlog; class InvalidRuleException extends \RuntimeException { /** - * InvalidRuleOperatorException thrown when a Rule is badly implemented + * InvalidConditionOperatorException thrown when a Rule is badly implemented * * @param string $className Class name */ diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index d25c48354..8bd81b245 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -25,7 +25,7 @@ namespace Thelia\Model; use Propel\Runtime\Propel; use Thelia\Constraint\Rule\CouponRuleInterface; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; use Thelia\Model\Base\Coupon as BaseCoupon; use Thelia\Model\Map\CouponTableMap; @@ -106,16 +106,16 @@ class Coupon extends BaseCoupon } /** - * Create or Update this coupon rule + * Create or Update this coupon condition * - * @param string $serializableRules Serialized rules ready to be saved - * @param string $locale Coupon Language code ISO (ex: fr_FR) + * @param string $serializableConditions Serialized conditions ready to be saved + * @param string $locale Coupon Language code ISO (ex: fr_FR) * * @throws \Exception */ - function createOrUpdateRules($serializableRules, $locale) + public function createOrUpdateConditions($serializableConditions, $locale) { - $this->setSerializedRules($serializableRules); + $this->setSerializedRules($serializableConditions); // Set object language (i18n) if (!is_null($locale)) { @@ -127,13 +127,9 @@ class Coupon extends BaseCoupon try { $this->save($con); $con->commit(); - } catch(\Exception $e) { $con->rollback(); throw $e; } } - - - } diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php index ccc04fbfc..f7f2b131a 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php +++ b/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php @@ -27,8 +27,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\CouponBaseAdapter; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\BaseAdapter; +use Thelia\Coupon\ConditionCollection; /** * Created by JetBrains PhpStorm. @@ -169,7 +169,7 @@ class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase ); $rule2->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $rules->add($rule2); @@ -209,10 +209,10 @@ class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase $rule1 = new AvailableForTotalAmountManager($stubAdapter); $rule2 = new AvailableForXArticlesManager($stubAdapter); - $adapter = new CouponBaseAdapter($container); + $adapter = new BaseAdapter($container); - $container->set('thelia.constraint.rule.available_for_total_amount', $rule1); - $container->set('thelia.constraint.rule.available_for_x_articles', $rule2); + $container->set('thelia.condition.match_for_total_amount', $rule1); + $container->set('thelia.condition.match_for_x_articles', $rule2); $container->set('thelia.adapter', $adapter); return $container; diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php index 68818a092..e3e83eb2b 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php +++ b/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php @@ -27,15 +27,15 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\CouponBaseAdapter; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\BaseAdapter; +use Thelia\Coupon\ConditionCollection; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test ConstraintValidator Class + * Unit Test ConditionEvaluator Class * * @package Constraint * @author Guillaume MOREL @@ -54,7 +54,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess1Rules() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -79,7 +79,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase AvailableForTotalAmountManager::INPUT2 => 'EUR'); $rule1->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $isValid = $ConstraintValidator->isMatching($rules); @@ -91,7 +91,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail1Rules() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -116,7 +116,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase AvailableForTotalAmountManager::INPUT2 => 'EUR'); $rule1->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $isValid = $ConstraintValidator->isMatching($rules); @@ -128,7 +128,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess2Rules() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -165,7 +165,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ); $rule2->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $rules->add($rule2); @@ -178,7 +178,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail2Rules() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -215,7 +215,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ); $rule2->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $rules->add($rule2); @@ -228,7 +228,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testVariableOpComparisonSuccess() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $expected = true; $actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); @@ -264,7 +264,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testVariableOpComparisonFail() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $expected = false; $actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); @@ -297,7 +297,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase */ public function testVariableOpComparisonException() { - $ConstraintValidator = new ConstraintValidator(); + $ConstraintValidator = new ConditionValidator(); $expected = true; $actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1); $this->assertEquals($expected, $actual); @@ -327,10 +327,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase $rule1 = new AvailableForTotalAmountManager($stubAdapter); $rule2 = new AvailableForXArticlesManager($stubAdapter); - $adapter = new CouponBaseAdapter($container); + $adapter = new BaseAdapter($container); - $container->set('thelia.constraint.rule.available_for_total_amount', $rule1); - $container->set('thelia.constraint.rule.available_for_x_articles', $rule2); + $container->set('thelia.condition.match_for_total_amount', $rule1); + $container->set('thelia.condition.match_for_x_articles', $rule2); $container->set('thelia.adapter', $adapter); return $container; diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php index a883a0712..53cf39a9b 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php @@ -23,10 +23,10 @@ namespace Thelia\Coupon; -use Thelia\Constraint\ConstraintValidator; +use Thelia\Constraint\ConditionValidator; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\Operators; -use Thelia\Exception\InvalidRuleValueException; +use Thelia\Exception\InvalidConditionValueException; use Thelia\Model\Currency; /** @@ -34,7 +34,7 @@ use Thelia\Model\Currency; * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test AvailableForTotalAmountManager Class + * Unit Test MatchForTotalAmountManager Class * * @package Constraint * @author Guillaume MOREL @@ -42,7 +42,7 @@ use Thelia\Model\Currency; */ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase { - /** @var CouponAdapterInterface $stubTheliaAdapter */ + /** @var AdapterInterface $stubTheliaAdapter */ protected $stubTheliaAdapter = null; /** @@ -69,7 +69,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $currency1 = new Currency(); $currency1->setCode('EUR'); @@ -95,7 +95,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleOperatorException + * @expectedException \Thelia\Exception\InvalidConditionOperatorException * */ public function testInValidBackOfficeInputOperator() @@ -123,7 +123,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleOperatorException + * @expectedException \Thelia\Exception\InvalidConditionOperatorException * */ public function testInValidBackOfficeInputOperator2() @@ -151,7 +151,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleValueException + * @expectedException \Thelia\Exception\InvalidConditionValueException * */ public function testInValidBackOfficeInputValue() @@ -179,7 +179,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleValueException + * @expectedException \Thelia\Exception\InvalidConditionValueException * */ public function testInValidBackOfficeInputValue2() diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php index 4937826b6..468a813c2 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php @@ -23,7 +23,7 @@ namespace Thelia\Coupon; -use Thelia\Constraint\ConstraintValidator; +use Thelia\Constraint\ConditionValidator; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; use Thelia\Constraint\Rule\SerializableRule; @@ -33,7 +33,7 @@ use Thelia\Constraint\Rule\SerializableRule; * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test AvailableForXArticlesManager Class + * Unit Test MatchForXArticlesManager Class * * @package Constraint * @author Guillaume MOREL @@ -42,7 +42,7 @@ use Thelia\Constraint\Rule\SerializableRule; class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ +// /** @var AdapterInterface $stubTheliaAdapter */ // protected $stubTheliaAdapter = null; /** @@ -58,7 +58,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleOperatorException + * @expectedException \Thelia\Exception\InvalidConditionOperatorException */ public function testInValidBackOfficeInputOperator() { @@ -71,7 +71,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -93,7 +93,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase * Check if validity test on BackOffice inputs are working * * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators - * @expectedException \Thelia\Exception\InvalidRuleValueException + * @expectedException \Thelia\Exception\InvalidConditionValueException */ public function testInValidBackOfficeInputValue() { @@ -106,7 +106,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -141,7 +141,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -176,7 +176,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -211,7 +211,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -246,7 +246,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -281,7 +281,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -316,7 +316,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -351,7 +351,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -386,7 +386,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -421,7 +421,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -456,7 +456,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -491,7 +491,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -526,7 +526,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -555,7 +555,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -590,7 +590,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) ->method('getConstraintValidator') - ->will($this->returnValue(new ConstraintValidator())); + ->will($this->returnValue(new ConditionValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -618,7 +618,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase // public function testGetValidators() // { -// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') // ->disableOriginalConstructor() // ->getMock(); // @@ -626,12 +626,12 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase // ->method('getNbArticlesInCart') // ->will($this->returnValue(4)); // -// $rule1 = new AvailableForXArticlesManager($stubAdapter); +// $rule1 = new MatchForXArticlesManager($stubAdapter); // $operators = array( -// AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR +// MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR // ); // $values = array( -// AvailableForXArticlesManager::INPUT1 => 4 +// MatchForXArticlesManager::INPUT1 => 4 // ); // $rule1->setValidatorsFromForm($operators, $values); // diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php index 6cdcb3430..ef9340dac 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php @@ -110,7 +110,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // */ // public function testOperatorInferiorValidBefore() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // Given // $a = 11; // $operator = Operators::INFERIOR; @@ -131,7 +131,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInferiorInvalidEquals() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::INFERIOR; // $b = new QuantityParam($adapter, 12); @@ -151,7 +151,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInferiorInvalidAfter() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 13; // $operator = Operators::INFERIOR; // $b = new QuantityParam($adapter, 12); @@ -171,7 +171,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInferiorOrEqualValidEqual() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 11; // $operator = Operators::INFERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 11); @@ -191,7 +191,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInferiorOrEqualValidBefore() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 10; // $operator = Operators::INFERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 11); @@ -211,7 +211,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInferiorOrEqualInValidAfter() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::INFERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 11); @@ -231,7 +231,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorEqualValidEqual() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::EQUAL; // $b = new QuantityParam($adapter, 12); @@ -251,7 +251,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorEqualInValidBefore() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 11; // $operator = Operators::EQUAL; // $b = new QuantityParam($adapter, 12); @@ -271,7 +271,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorEqualInValidAfter() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 13; // $operator = Operators::EQUAL; // $b = new QuantityParam($adapter, 12); @@ -291,7 +291,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorOrEqualValidEqual() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 13; // $operator = Operators::SUPERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 13); @@ -311,7 +311,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorOrEqualAfter() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 14; // $operator = Operators::SUPERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 13); @@ -331,7 +331,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorOrEqualInvalidBefore() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::SUPERIOR_OR_EQUAL; // $b = new QuantityParam($adapter, 13); @@ -351,7 +351,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorValidAfter() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 13; // $operator = Operators::SUPERIOR; // $b = new QuantityParam($adapter, 12); @@ -371,7 +371,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorInvalidEqual() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::SUPERIOR; // $b = new QuantityParam($adapter, 12); @@ -391,7 +391,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorSuperiorInvalidBefore() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 11; // $operator = Operators::SUPERIOR; // $b = new QuantityParam($adapter, 12); @@ -411,7 +411,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorDifferentValid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = Operators::DIFFERENT; // $b = new QuantityParam($adapter, 11); @@ -431,7 +431,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorDifferentInvalidEquals() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 11; // $operator = Operators::DIFFERENT; // $b = new QuantityParam($adapter, 11); @@ -451,7 +451,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase // public function testOperatorInValid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $a = 12; // $operator = 'X'; // $b = new QuantityParam($adapter, 11); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php index db281bcc5..d78faacd0 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php @@ -50,7 +50,7 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase ); } -// /** @var CouponAdapterInterface $stubTheliaAdapter */ +// /** @var AdapterInterface $stubTheliaAdapter */ // protected $stubTheliaAdapter = null; // // /** @@ -59,16 +59,16 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase // */ // protected function setUp() // { -// /** @var CouponAdapterInterface $stubTheliaAdapter */ +// /** @var AdapterInterface $stubTheliaAdapter */ // $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); // } // // /** -// * Generate valid CouponBaseAdapter +// * Generate valid BaseAdapter // * // * @param int $customerId Customer id // * -// * @return CouponAdapterInterface +// * @return AdapterInterface // */ // protected function generateValidCouponBaseAdapterMock($customerId = 4521) // { @@ -78,9 +78,9 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase // $customer->setLastname('Lastname'); // $customer->setEmail('em@il.com'); // -// /** @var CouponAdapterInterface $stubTheliaAdapter */ +// /** @var AdapterInterface $stubTheliaAdapter */ // $stubTheliaAdapter = $this->getMock( -// 'Thelia\Coupon\CouponBaseAdapter', +// 'Thelia\Coupon\BaseAdapter', // array('getCustomer'), // array() // ); @@ -140,7 +140,7 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase //// */ //// public function isSerializableTest() //// { -//// $adapter = new CouponBaseAdapter(); +//// $adapter = new BaseAdapter(); //// $intValidator = 42; //// $intToValidate = -1; //// diff --git a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php index 53a5c70eb..9fa382317 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php @@ -62,7 +62,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-07"); // @@ -80,7 +80,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-08"); // @@ -98,7 +98,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-09"); // @@ -115,7 +115,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidator = new \DateTime("2012-07-08"); // $dateToValidate = 1377012588; // @@ -130,7 +130,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidator = new \DateTime("2012-07-08"); // // $param = new DateParam($adapter, $dateValidator); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php index edf71b138..3761a2a11 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php @@ -62,7 +62,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorInteger() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 41; // @@ -80,7 +80,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsInteger() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 42; // @@ -98,7 +98,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorInteger() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 43; // @@ -115,7 +115,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = '42'; // @@ -132,7 +132,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // // $param = new IntegerParam($adapter, $intValidator); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php index e98c5f719..ce59875cc 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php @@ -62,7 +62,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // $dateToValidate = new \DateTime("2012-07-07"); @@ -81,7 +81,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // $dateToValidate = new \DateTime("2012-07-08"); @@ -103,7 +103,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDate2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // $dateToValidate = new \DateTime("2012-08-08"); @@ -122,7 +122,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // $dateToValidate = new \DateTime("2012-08-09"); @@ -140,7 +140,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // $dateToValidate = 1377012588; @@ -156,7 +156,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $dateValidatorStart = new \DateTime("2012-07-08"); // $dateValidatorInterval = new \DateInterval("P1M"); //1month // diff --git a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php index 4eb04a77e..892800f50 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php @@ -62,7 +62,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorPrice() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = 1.00; @@ -81,7 +81,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorPrice2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = 42.49; @@ -100,7 +100,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsPrice() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = 42.50; @@ -119,7 +119,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorPrice() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = 42.51; @@ -137,7 +137,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = '42.50'; @@ -155,7 +155,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = -1; @@ -173,7 +173,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException3() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // // $priceValidator = 42.50; // $priceToValidate = 0; @@ -191,7 +191,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException4() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $priceValidator = 42.50; // $priceToValidate = 1; // @@ -208,7 +208,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $priceValidator = 42.50; // // $param = new PriceParam($adapter, $priceValidator, 'GBP'); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php index 806cedf8d..4c2155ee8 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php @@ -62,7 +62,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorQuantity() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 0; // @@ -80,7 +80,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorQuantity2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 41; // @@ -98,7 +98,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsQuantity() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 42; // @@ -116,7 +116,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorQuantity() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = 43; // @@ -133,7 +133,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = '42'; // @@ -150,7 +150,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = -1; // @@ -167,7 +167,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $intValidator = 42; // $intToValidate = -1; // diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php index be03743d3..8e2d344b8 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php @@ -62,7 +62,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-07"); // @@ -82,7 +82,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-08"); // @@ -102,7 +102,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-08-08"); // @@ -122,7 +122,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-09-08"); // @@ -142,7 +142,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2013-05-08"); // @@ -162,7 +162,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-11-08"); // @@ -182,7 +182,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2013-03-08"); // @@ -202,7 +202,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-08-08"); // @@ -222,7 +222,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-12-08"); // @@ -242,7 +242,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorDateRepeatEveryFourMonthTwoTimes() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2013-03-09"); // @@ -261,7 +261,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = 1377012588; // @@ -278,7 +278,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // // $param = new RepeatedDateParam($adapter); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php index c5565a322..bf138da93 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php @@ -61,7 +61,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInferiorDate() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-07"); // $duration = 10; @@ -84,7 +84,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-08"); // $duration = 10; @@ -106,7 +106,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-13"); // $duration = 10; @@ -128,7 +128,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-07-18"); // $duration = 10; @@ -150,7 +150,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-08-08"); // $dateToValidate = new \DateTime("2012-08-08"); // $duration = 10; @@ -172,7 +172,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-08-08"); // $dateToValidate = new \DateTime("2012-08-13"); // $duration = 10; @@ -194,7 +194,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-08-08"); // $dateToValidate = new \DateTime("2012-08-18"); // $duration = 10; @@ -216,7 +216,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-10-08"); // $duration = 10; @@ -238,7 +238,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-10-13"); // $duration = 10; @@ -260,7 +260,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-10-18"); // $duration = 10; @@ -282,7 +282,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-07-19"); // $duration = 10; @@ -304,7 +304,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-08-01"); // $duration = 10; @@ -327,7 +327,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-10-08"); // $dateToValidate = new \DateTime("2012-08-07"); // $duration = 10; @@ -351,7 +351,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testSuperiorDateRepeatEveryMonthFourTime() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = new \DateTime("2012-10-19"); // $duration = 10; @@ -372,7 +372,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function testInvalidArgumentException() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = 1377012588; // $duration = 10; @@ -391,7 +391,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase // */ // public function isSerializableTest() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $startDateValidator = new \DateTime("2012-07-08"); // $dateToValidate = 1377012588; // $duration = 10; diff --git a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php index 45f097a77..438a025de 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php @@ -28,7 +28,7 @@ namespace Thelia\Coupon; * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test CouponBaseAdapter Class + * Unit Test BaseAdapter Class * * @package Coupon * @author Guillaume MOREL @@ -44,7 +44,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase ); } // /** -// * @var CouponBaseAdapter +// * @var BaseAdapter // */ // protected $object; // @@ -54,7 +54,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase // */ // protected function setUp() // { -// $this->object = new CouponBaseAdapter; +// $this->object = new BaseAdapter; // } // // /** @@ -66,7 +66,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase // } // // /** -// * @covers Thelia\Coupon\CouponBaseAdapter::getCart +// * @covers Thelia\Coupon\BaseAdapter::getCart // * @todo Implement testGetCart(). // */ // public function testGetCart() @@ -78,7 +78,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase // } // // /** -// * @covers Thelia\Coupon\CouponBaseAdapter::getDeliveryAddress +// * @covers Thelia\Coupon\BaseAdapter::getDeliveryAddress // * @todo Implement testGetDeliveryAddress(). // */ // public function testGetDeliveryAddress() @@ -90,7 +90,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase // } // // /** -// * @covers Thelia\Coupon\CouponBaseAdapter::getCustomer +// * @covers Thelia\Coupon\BaseAdapter::getCustomer // * @todo Implement testGetCustomer(). // */ // public function testGetCustomer() diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index 261f0e100..3d609c497 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -74,7 +74,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // * @param bool $isUsed If Coupon has been used yet // * @param bool $isEnabled If Coupon is enabled // * @param \DateTime $expirationDate When Coupon expires -// * @param CouponRuleCollection $rules Coupon rules +// * @param ConditionCollection $rules Coupon rules // * @param bool $isCumulative If Coupon is cumulative // * @param bool $isRemovingPostage If Coupon is removing postage // * @@ -109,9 +109,9 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // $isRemovingPostage // ); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\CouponBaseAdapter', +// 'Thelia\Coupon\BaseAdapter', // array('findOneCouponByCode'), // array() // ); @@ -135,7 +135,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // $date = new \DateTime(); // $date->setTimestamp(strtotime("today - 2 months")); // -// /** @var CouponAdapterInterface $mockAdapter */ +// /** @var AdapterInterface $mockAdapter */ // $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date); // $couponFactory = new CouponFactory($mockAdapter); // $coupon = $couponFactory->buildCouponFromCode('XMAS1'); @@ -151,7 +151,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // { // $date = new \DateTime(); // -// /** @var CouponAdapterInterface $mockAdapter */ +// /** @var AdapterInterface $mockAdapter */ // $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date); // $couponFactory = new CouponFactory($mockAdapter); // $coupon = $couponFactory->buildCouponFromCode('XMAS1'); @@ -165,8 +165,8 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // */ // public function testBuildCouponFromCodeWithoutRule() // { -// /** @var CouponAdapterInterface $mockAdapter */ -// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, null, new CouponRuleCollection(array())); +// /** @var AdapterInterface $mockAdapter */ +// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, null, new ConditionCollection(array())); // $couponFactory = new CouponFactory($mockAdapter); // $coupon = $couponFactory->buildCouponFromCode('XMAS1'); // } @@ -178,7 +178,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // */ // public function testBuildCouponFromCode() // { -// /** @var CouponAdapterInterface $mockAdapter */ +// /** @var AdapterInterface $mockAdapter */ // $mockAdapter = $this->generateCouponModelMock(); // $couponFactory = new CouponFactory($mockAdapter); // /** @var CouponInterface $coupon */ @@ -206,7 +206,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // /** // * Generate valid CouponRuleInterfaces // * -// * @return CouponRuleCollection Set of CouponRuleInterface +// * @return ConditionCollection Set of ConditionManagerInterface // */ // protected function generateValidRules() // { @@ -230,7 +230,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase //// ) //// ) //// ); -//// $rules = new CouponRuleCollection(array($rule1, $rule2)); +//// $rules = new ConditionCollection(array($rule1, $rule2)); //// //// return $rules; // } @@ -247,7 +247,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // * @param bool $isUsed If Coupon has been used yet // * @param bool $isEnabled If Coupon is enabled // * @param \DateTime $expirationDate When Coupon expires -// * @param CouponRuleCollection $rules Coupon rules +// * @param ConditionCollection $rules Coupon rules // * @param bool $isCumulative If Coupon is cumulative // * @param bool $isRemovingPostage If Coupon is removing postage // * diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php index d0662442a..1d1ba7c72 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php @@ -88,7 +88,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // /** @var CouponInterface $coupon */ // $coupon = self::generateValidCoupon(); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); // // $couponManager = new CouponManager($stubCouponBaseAdapter); @@ -108,7 +108,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // */ // public function testGetDiscountTwoCoupon() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $cartTotalPrice = 100.00; // $checkoutTotalPrice = 120.00; // @@ -124,11 +124,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // ) // ) // ); -// $rules = new CouponRuleCollection(array($rule1)); +// $rules = new ConditionCollection(array($rule1)); // /** @var CouponInterface $coupon2 */ // $coupon2 = $this->generateValidCoupon('XMAS2', null, null, null, 15.00, null, null, $rules); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon1, $coupon2), $cartTotalPrice, $checkoutTotalPrice); // // $couponManager = new CouponManager($stubCouponBaseAdapter); @@ -148,7 +148,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // */ // public function testGetDiscountAlwaysInferiorToPrice() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $cartTotalPrice = 21.00; // $checkoutTotalPrice = 26.00; // @@ -162,11 +162,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // ) // ) // ); -// $rules = new CouponRuleCollection(array($rule1)); +// $rules = new ConditionCollection(array($rule1)); // /** @var CouponInterface $coupon */ // $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); // // $couponManager = new CouponManager($stubCouponBaseAdapter); @@ -185,7 +185,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // */ // public function testIsCouponRemovingPostage() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $cartTotalPrice = 21.00; // $checkoutTotalPrice = 27.00; // @@ -199,11 +199,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // ) // ) // ); -// $rules = new CouponRuleCollection(array($rule1)); +// $rules = new ConditionCollection(array($rule1)); // /** @var CouponInterface $coupon */ // $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules, null, true); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); // // $couponManager = new CouponManager($stubCouponBaseAdapter); @@ -231,7 +231,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // // $coupons = array($couponCumulative1); // -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -264,7 +264,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative1 = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true); // // $coupons = array($couponCumulative1); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -299,7 +299,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -334,7 +334,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -369,7 +369,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -404,7 +404,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -437,7 +437,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, new \DateTime(), null, true); // // $coupons = array($couponCumulative1); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -472,7 +472,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -507,7 +507,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -542,7 +542,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true); // // $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -581,7 +581,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, true); // // $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -620,7 +620,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, false); // // $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4); -// /** @var CouponAdapterInterface $stubCouponBaseAdapter */ +// /** @var AdapterInterface $stubCouponBaseAdapter */ // $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); // // // When @@ -641,11 +641,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // /** // * Generate valid CouponRuleInterfaces // * -// * @return array Array of CouponRuleInterface +// * @return array Array of ConditionManagerInterface // */ // public static function generateValidRules() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule1 = new AvailableForTotalAmount( // $adapter, array( // AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( @@ -666,7 +666,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // ) // ) // ); -// $rules = new CouponRuleCollection(array($rule1, $rule2)); +// $rules = new ConditionCollection(array($rule1, $rule2)); // // return $rules; // } @@ -692,7 +692,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // public function generateFakeAdapter(array $coupons, $cartTotalPrice, $checkoutTotalPrice, $postagePrice = 6.00) // { // $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\CouponBaseAdapter', +// 'Thelia\Coupon\BaseAdapter', // array( // 'getCurrentCoupons', // 'getCartTotalPrice', @@ -734,7 +734,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // * @param float $amount Coupon discount // * @param bool $isEnabled Is Coupon enabled // * @param \DateTime $expirationDate Coupon expiration date -// * @param CouponRuleCollection $rules Coupon rules +// * @param ConditionCollection $rules Coupon rules // * @param bool $isCumulative If is cumulative // * @param bool $isRemovingPostage If is removing postage // * @param bool $isAvailableOnSpecialOffers If is available on @@ -758,7 +758,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase // $isAvailableOnSpecialOffers = null, // $maxUsage = null // ) { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // if ($code === null) { // $code = self::VALID_CODE; // } diff --git a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php index 803000779..2b19ba130 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php @@ -33,7 +33,7 @@ use Thelia\Constraint\Rule\Operators; * Date: 8/19/13 * Time: 3:24 PM * - * Unit Test CouponRuleCollection Class + * Unit Test ConditionCollection Class * * @package Coupon * @author Guillaume MOREL @@ -73,7 +73,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase //// ) //// ) //// ); -//// $rules = new CouponRuleCollection(array($rule1, $rule2)); +//// $rules = new ConditionCollection(array($rule1, $rule2)); //// //// $serializedRules = base64_encode(serialize($rules)); //// $unserializedRules = unserialize(base64_decode($serializedRules)); diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index 990309f28..f3a4ff620 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -153,7 +153,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // */ // public function testGetEffect() // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // $expected = 10; @@ -186,7 +186,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); +// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); // // // Then // $expected = 3; @@ -216,7 +216,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); +// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); // } // // /** @@ -228,7 +228,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // public function testGetEffectIfTotalAmountInferiorTo400Valid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( // Operators::INFERIOR, // 400.00 @@ -236,7 +236,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 10.00; @@ -253,7 +253,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( // Operators::INFERIOR_OR_EQUAL, // 400.00 @@ -261,7 +261,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 10.00; @@ -278,7 +278,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // public function testGetEffectIfTotalAmountEqualTo400Valid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( // Operators::EQUAL, // 400.00 @@ -286,7 +286,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 10.00; @@ -303,7 +303,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( // Operators::SUPERIOR_OR_EQUAL, // 400.00 @@ -311,7 +311,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 10.00; @@ -328,7 +328,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // public function testGetEffectIfTotalAmountSuperiorTo400Valid() // { // // Given -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( // Operators::SUPERIOR, // 400.00 @@ -336,7 +336,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 10.00; @@ -365,7 +365,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // */ // protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount) // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $validators = array( // AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( // $operator, diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index b5d6529b1..4d60604f5 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -158,7 +158,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); +// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); // // // Then // $expected = 3; @@ -188,7 +188,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); +// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); // } // // /** @@ -207,7 +207,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 24.50; @@ -231,7 +231,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 24.50; @@ -255,7 +255,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 24.50; @@ -279,7 +279,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 24.50; @@ -303,7 +303,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // // // When -// $coupon->setRules(new CouponRuleCollection(array($rule0))); +// $coupon->setRules(new ConditionCollection(array($rule0))); // // // Then // $expected = 24.50; @@ -322,7 +322,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // * @param float $amount Coupon discount // * @param bool $isEnabled Is Coupon enabled // * @param \DateTime $expirationDate Coupon expiration date -// * @param CouponRuleCollection $rules Coupon rules +// * @param ConditionCollection $rules Coupon rules // * @param bool $isCumulative If is cumulative // * @param bool $isRemovingPostage If is removing postage // * @param bool $isAvailableOnSpecialOffers If is available on @@ -407,7 +407,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // */ // protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount) // { -// $adapter = new CouponBaseAdapter(); +// $adapter = new BaseAdapter(); // $validators = array( // AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( // $operator, @@ -432,7 +432,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // public function generateFakeAdapter($cartTotalPrice) // { // $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\CouponBaseAdapter', +// 'Thelia\Coupon\BaseAdapter', // array( // 'getCartTotalPrice' // ), diff --git a/install/faker.php b/install/faker.php index 5ab0e2599..7e2b6e84d 100755 --- a/install/faker.php +++ b/install/faker.php @@ -1,10 +1,10 @@ setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); $rules->add($rule2); /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.constraint.factory'); + $constraintFactory = $container->get('thelia.condition.factory'); $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon1->setSerializedRules($serializedRules); @@ -729,11 +729,11 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua AvailableForXArticlesManager::INPUT1 => 4, ); $rule1->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.constraint.factory'); + $constraintFactory = $container->get('thelia.condition.factory'); $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon2->setSerializedRules($serializedRules); @@ -765,15 +765,15 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); - $rule1 = new AvailableForEveryoneManager($adapter); + $rule1 = new MatchForEveryoneManager($adapter); $operators = array(); $values = array(); $rule1->setValidatorsFromForm($operators, $values); - $rules = new CouponRuleCollection(); + $rules = new ConditionCollection(); $rules->add($rule1); /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.constraint.factory'); + $constraintFactory = $container->get('thelia.condition.factory'); $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon3->setSerializedRules($serializedRules); diff --git a/install/import.php b/install/import.php index c5fa3572a..47313df6e 100644 --- a/install/import.php +++ b/install/import.php @@ -25,7 +25,7 @@ use Thelia\Constraint\ConstraintFactory; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; require __DIR__ . '/../core/bootstrap.php'; diff --git a/install/tax_faker.php b/install/tax_faker.php index 5d534e2ef..f967ca7a4 100755 --- a/install/tax_faker.php +++ b/install/tax_faker.php @@ -5,7 +5,7 @@ use Thelia\Constraint\Rule\AvailableForTotalAmount; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\CouponRuleCollection; +use Thelia\Coupon\ConditionCollection; use Thelia\Model\ProductImage; use Thelia\Model\CategoryImage; use Thelia\Model\FolderImage; diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 089db5ef2..a34cc0c08 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -90,12 +90,15 @@ $(function($){ // Save rules on click $.couponManager.onClickSaveRule = function() { $('#constraint-save-btn').on('click', function () { - if($('#category-rule').val() == 'thelia.constraint.rule.available_for_everyone') { - // @todo translate + modal - var r= confirm("Do you really want to set this coupon available to everyone ?"); + console.log('constraint-save-btn'); + if($('#category-rule').val() == 'thelia.condition.match_for_everyone') { +// // @todo translate + modal + var r = confirm("Do you really want to set this coupon available to everyone ?"); if (r == true) { $.couponManager.createOrUpdateRuleAjax(); } + } else { + $.couponManager.createOrUpdateRuleAjax(); } }); diff --git a/templates/admin/default/assets/js/main.js b/templates/admin/default/assets/js/main.js index 1c7c3f2be..9ca0acda4 100644 --- a/templates/admin/default/assets/js/main.js +++ b/templates/admin/default/assets/js/main.js @@ -54,23 +54,36 @@ // -- Confirm Box -- if($('[data-toggle="confirm"]').length){ - $('[data-toggle="confirm"]').click(function(e){ + $('[data-toggle="confirm"]').click(function(e){ - var $link = $(this); - var modal = $(this).data('target'); + var $this = $(this); + var $modal = $($this.data('target')); - $(modal).modal('show'); + $modal.modal('show'); - $(modal).on('shown', function () { - $('[data-confirm]').attr('href', $link.attr('href')); + $modal.on('shown', function () { + if($this.data('script')){ + + $('[data-confirm]').click(function(){ + + eval($this.data('script')); + + $modal.modal('hide'); + return false; + }); + + } + else{ + $('[data-confirm]').attr('href', $this.attr('href')); + } }); - if($(modal).is(':hidden')){ + if($modal.is(':hidden')){ e.preventDefault(); } }); - } + } // -- Mini browser -- miniBrowser = function (root, url){ diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index 8ef58f271..1a937cfc1 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -24,8 +24,6 @@ {/block} -{include file='includes/confirmation-modal.html'} - {block name="javascript-initialization"} {javascripts file='assets/bootstrap-datepicker/js/bootstrap-datepicker.js'} @@ -89,7 +87,7 @@ $('#constraint-add-operators-values').html(''); // Set the rule selector $("#category-rule option").filter(function() { - return $(this).val() == 'thelia.constraint.rule.available_for_everyone'; + return $(this).val() == 'thelia.condition.match_for_everyone'; }).prop('selected', true); $.couponManager.onClickUpdateRule(); diff --git a/templates/admin/default/coupon/rule-input-ajax.html b/templates/admin/default/coupon/condition-input-ajax.html similarity index 100% rename from templates/admin/default/coupon/rule-input-ajax.html rename to templates/admin/default/coupon/condition-input-ajax.html diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 299c6598b..2eb6487ac 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -190,7 +190,7 @@
    - + {intl l='Save this rule'} diff --git a/tests/functionnal/casperjs/exe/31_coupons_rule.js b/tests/functionnal/casperjs/exe/31_coupons_rule.js index 4b9ada4ba..f4b7b42ec 100644 --- a/tests/functionnal/casperjs/exe/31_coupons_rule.js +++ b/tests/functionnal/casperjs/exe/31_coupons_rule.js @@ -23,7 +23,7 @@ casper.start(thelia2_login_coupon_update_url, function() { // Create rule this.evaluate(function() { - $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); + $('#category-rule').val('thelia.condition.match_for_x_articles').change(); return true; }); this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected.png'); @@ -133,7 +133,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() { casper.then(function(){ // Create rule this.evaluate(function() { - $('#category-rule').val('thelia.constraint.rule.available_for_total_amount').change(); + $('#category-rule').val('thelia.condition.match_for_total_amount').change(); return true; }); this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected2.png'); @@ -234,7 +234,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() { // Test add no condition rule casper.then(function(){ this.evaluate(function() { - $('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change(); + $('#category-rule').val('thelia.condition.match_for_x_articles').change(); return true; }); }); @@ -274,7 +274,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() { casper.then(function(){ this.evaluate(function() { - $('#category-rule').val('thelia.constraint.rule.available_for_everyone').change(); + $('#category-rule').val('thelia.condition.match_for_everyone').change(); return true; }); }); From b7851b2d54baa76fce20e2b55786d40d602101b1 Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 16:36:14 +0200 Subject: [PATCH 17/27] WIP : Refactor contraint/rule becomes conditions (more generic) --- core/lib/Thelia/Action/Coupon.php | 17 +- .../lib/Thelia/Condition/ConditionFactory.php | 4 +- .../Condition/ConditionManagerAbstract.php | 6 +- .../Condition/ConditionManagerInterface.php | 18 +- .../MatchForTotalAmountManager.php | 6 +- .../Controller/Admin/CouponController.php | 40 +- core/lib/Thelia/Core/Template/Loop/Coupon.php | 22 +- core/lib/Thelia/Coupon/AdapterInterface.php | 4 +- core/lib/Thelia/Coupon/BaseAdapter.php | 5 +- core/lib/Thelia/Coupon/CouponFactory.php | 25 +- core/lib/Thelia/Coupon/RuleOrganizer.php | 6 +- .../Thelia/Coupon/RuleOrganizerInterface.php | 8 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 41 +- .../Thelia/Coupon/Type/CouponInterface.php | 6 +- .../Coupon/Type/RemoveXAmountManager.php | 1 - .../Coupon/Type/RemoveXPercentManager.php | 1 - ...tion.php => InvalidConditionException.php} | 10 +- .../Tests/Condition/ConstraintFactoryTest.php | 227 +++++++ .../ConstraintValidatorTest.php | 201 +++--- .../AvailableForTotalAmountManagerTest.php | 610 ++++++++++++++++++ .../AvailableForXArticlesManagerTest.php | 328 +++++----- .../Thelia/Tests/Condition/OperatorsTest.php | 114 ++++ .../Constraint/ConstraintFactoryTest.php | 228 ------- .../AvailableForTotalAmountManagerTest.php | 592 ----------------- .../Tests/Constraint/Rule/OperatorsTest.php | 481 -------------- .../Validator/CustomerParamTest.php | 168 ----- .../Constraint/Validator/DateParamTest.php | 158 ----- .../Constraint/Validator/IntegerParamTest.php | 159 ----- .../Validator/IntervalParamTest.php | 184 ------ .../Constraint/Validator/PriceParamTest.php | 237 ------- .../Validator/QuantityParamTest.php | 195 ------ .../Validator/RepeatedDateParamTest.php | 309 --------- .../Validator/RepeatedIntervalParamTest.php | 426 ------------ .../Thelia/Tests/Coupon/CouponFactoryTest.php | 2 +- .../Tests/Coupon/Type/RemoveXAmountTest.php | 2 +- .../Type/RemoveXPercentForCategoryYTest.php | 70 -- .../Tests/Coupon/Type/RemoveXPercentTest.php | 2 +- install/faker.php | 90 +-- install/import.php | 7 +- install/tax_faker.php | 14 +- .../coupon/{rules.html => conditions.html} | 0 41 files changed, 1387 insertions(+), 3637 deletions(-) rename core/lib/Thelia/Exception/{InvalidRuleException.php => InvalidConditionException.php} (88%) create mode 100644 core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php rename core/lib/Thelia/Tests/{Constraint => Condition}/ConstraintValidatorTest.php (53%) create mode 100644 core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php rename core/lib/Thelia/Tests/{Constraint/Rule => Condition/Implementation}/AvailableForXArticlesManagerTest.php (54%) create mode 100644 core/lib/Thelia/Tests/Condition/OperatorsTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php delete mode 100644 core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php delete mode 100644 core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php rename templates/admin/default/coupon/{rules.html => conditions.html} (100%) diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 335a36340..b3086c266 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -74,7 +74,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface } /** - * Occurring when a Coupon rule is about to be updated + * Occurring when a Coupon condition is about to be updated * * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule */ @@ -86,7 +86,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface } /** - * Occurring when a Coupon rule is about to be consumed + * Occurring when a Coupon condition is about to be consumed * * @param CouponConsumeEvent $event Event consuming Coupon */ @@ -138,13 +138,14 @@ class Coupon extends BaseAction implements EventSubscriberInterface { $coupon->setDispatcher($this->getDispatcher()); - // Set default rule if none found + // Set default condition if none found /** @var ConditionManagerInterface $noConditionRule */ $noConditionRule = $this->container->get('thelia.condition.match_for_everyone'); - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); $couponRuleCollection = new ConditionCollection(); $couponRuleCollection->add($noConditionRule); - $defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection( + $defaultSerializedRule = $conditionFactory->serializeConditionCollection( $couponRuleCollection ); @@ -179,11 +180,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface { $coupon->setDispatcher($this->getDispatcher()); - /** @var ConditionFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); $coupon->createOrUpdateConditions( - $constraintFactory->serializeConditionCollection($event->getConditions()), + $conditionFactory->serializeConditionCollection($event->getConditions()), $event->getLocale() ); diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index 642b474e0..ff024ecae 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -82,7 +82,7 @@ class ConditionFactory if ($conditions !== null) { /** @var $condition ConditionManagerInterface */ foreach ($conditions as $condition) { - // Remove all rule if the "no condition" condition is found + // Remove all condition if the "no condition" condition is found // if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') { // return base64_encode(json_encode(array($condition->getSerializableRule()))); // } @@ -153,7 +153,7 @@ class ConditionFactory * * @param string $conditionServiceId ConditionManager class name * - * @return array Ready to be drawn rule inputs + * @return array Ready to be drawn condition inputs */ public function getInputs($conditionServiceId) { diff --git a/core/lib/Thelia/Condition/ConditionManagerAbstract.php b/core/lib/Thelia/Condition/ConditionManagerAbstract.php index 16ef2c044..e5c8aed1a 100644 --- a/core/lib/Thelia/Condition/ConditionManagerAbstract.php +++ b/core/lib/Thelia/Condition/ConditionManagerAbstract.php @@ -84,7 +84,7 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->conditionValidator = $adapter->getConditionValidator(); + $this->conditionValidator = $adapter->getConditionEvaluator(); } // /** @@ -94,13 +94,13 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface // * validating $paramsToValidate against // * // * @return $this -// * @throws InvalidRuleException +// * @throws InvalidConditionException // */ // protected function setValidators(array $validators) // { // foreach ($validators as $validator) { // if (!$validator instanceof RuleValidator) { -// throw new InvalidRuleException(get_class()); +// throw new InvalidConditionException(get_class()); // } // if (!in_array($validator->getOperator(), $this->availableOperators)) { // throw new InvalidConditionOperatorException( diff --git a/core/lib/Thelia/Condition/ConditionManagerInterface.php b/core/lib/Thelia/Condition/ConditionManagerInterface.php index bf7f439b3..0e7fc99b1 100644 --- a/core/lib/Thelia/Condition/ConditionManagerInterface.php +++ b/core/lib/Thelia/Condition/ConditionManagerInterface.php @@ -121,15 +121,15 @@ interface ConditionManagerInterface */ public function getValidators(); - /** - * Populate a Condition from a form admin - * - * @param array $operators Condition Operator set by the Admin - * @param array $values Condition Values set by the Admin - * - * @return bool - */ - public function populateFromForm(array$operators, array $values); +// /** +// * Populate a Condition from a form admin +// * +// * @param array $operators Condition Operator set by the Admin +// * @param array $values Condition Values set by the Admin +// * +// * @return bool +// */ +// public function populateFromForm(array$operators, array $values); /** diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php index e56d58d6b..bc158c878 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php @@ -159,17 +159,17 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract return false; } - $constraint1 = $this->conditionValidator->variableOpComparison( + $condition1 = $this->conditionValidator->variableOpComparison( $this->adapter->getCartTotalPrice(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); - $constraint2 = $this->conditionValidator->variableOpComparison( + $condition2 = $this->conditionValidator->variableOpComparison( $this->adapter->getCheckoutCurrency(), $this->operators[self::INPUT2], $this->values[self::INPUT2] ); - if ($constraint1 && $constraint2) { + if ($condition1 && $condition2) { return true; } diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f1882920e..6bebe103e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -203,9 +203,9 @@ class CouponController extends BaseAdminController } else { // Display // Prepare the data that will hydrate the form - /** @var ConditionFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); - $conditions = $constraintFactory->unserializeConditionCollection( + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); @@ -318,26 +318,26 @@ class CouponController extends BaseAdminController return $this->pageNotFound(); } - $rules = new ConditionCollection(); + $conditions = new ConditionCollection(); /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->container->get('thelia.condition.factory'); $conditionsReceived = json_decode($this->getRequest()->get('rules')); foreach ($conditionsReceived as $conditionReceived) { - $rule = $conditionFactory->build( + $condition = $conditionFactory->build( $conditionReceived->serviceId, (array) $conditionReceived->operators, (array) $conditionReceived->values ); - $rules->add(clone $rule); + $conditions->add(clone $condition); } // $coupon->setSerializedRules( -// $constraintFactory->serializeCouponRuleCollection($rules) +// $conditionFactory->serializeCouponRuleCollection($rules) // ); $conditionEvent = new ConditionCreateOrUpdateEvent( - $rules + $conditions ); $conditionEvent->setCouponModel($coupon); @@ -350,19 +350,19 @@ class CouponController extends BaseAdminController $this->adminLogAppend( sprintf( - 'Coupon %s (ID %s) rules updated', + 'Coupon %s (ID %s) conditions updated', $conditionEvent->getCouponModel()->getTitle(), $conditionEvent->getCouponModel()->getServiceId() ) ); - $cleanedRules = $this->cleanConditionForTemplate($rules); + $cleanedConditions = $this->cleanConditionForTemplate($conditions); return $this->render( - 'coupon/rules', + 'coupon/conditions', array( 'couponId' => $couponId, - 'rules' => $cleanedRules, + 'rules' => $cleanedConditions, 'urlEdit' => $couponId, 'urlDelete' => $couponId ) @@ -469,7 +469,7 @@ class CouponController extends BaseAdminController $message = false; try { - // Check the form against constraints violations + // Check the form against conditions violations $form = $this->validateForm($creationForm, 'POST'); // Get the form field values @@ -525,7 +525,7 @@ class CouponController extends BaseAdminController } /** - * Get all available rules + * Get all available conditions * * @return array */ @@ -560,18 +560,18 @@ class CouponController extends BaseAdminController $cleanedCoupons = array(); /** @var CouponInterface $availableCoupon */ foreach ($availableCoupons as $availableCoupon) { - $rule = array(); - $rule['serviceId'] = $availableCoupon->getServiceId(); - $rule['name'] = $availableCoupon->getName(); - $rule['toolTip'] = $availableCoupon->getToolTip(); - $cleanedCoupons[] = $rule; + $condition = array(); + $condition['serviceId'] = $availableCoupon->getServiceId(); + $condition['name'] = $availableCoupon->getName(); + $condition['toolTip'] = $availableCoupon->getToolTip(); + $cleanedCoupons[] = $condition; } return $cleanedCoupons; } /** - * Clean rule for template + * Clean condition for template * * @param ConditionCollection $conditions Condition collection * diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 16c20c4e8..ea8473192 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -25,8 +25,8 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Util\PropelModelPager; -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\ConditionManagerInterface; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\LoopResult; @@ -68,7 +68,7 @@ class Coupon extends BaseI18nLoop /** * Execute Loop * - * @param PropelModelPager $pagination + * @param PropelModelPager $pagination Pagination manager * * @return \Thelia\Core\Template\Element\LoopResult */ @@ -94,8 +94,8 @@ class Coupon extends BaseI18nLoop $coupons = $this->search($search, $pagination); $loopResult = new LoopResult(); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); /** @var Request $request */ $request = $this->container->get('request'); @@ -105,7 +105,7 @@ class Coupon extends BaseI18nLoop /** @var MCoupon $coupon */ foreach ($coupons as $coupon) { $loopResultRow = new LoopResultRow(); - $rules = $constraintFactory->unserializeCouponRuleCollection( + $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); @@ -130,10 +130,10 @@ class Coupon extends BaseI18nLoop $datediff = $coupon->getExpirationDate()->getTimestamp() - $now; $daysLeftBeforeExpiration = floor($datediff/(60*60*24)); - $cleanedRules = array(); - /** @var CouponRuleInterface $rule */ - foreach ($rules->getRules() as $rule) { - $cleanedRules[] = $rule->getToolTip(); + $cleanedConditions = array(); + /** @var ConditionManagerInterface $condition */ + foreach ($conditions->getConditions() as $condition) { + $cleanedConditions[] = $condition->getToolTip(); } $loopResultRow->set("ID", $coupon->getId()) ->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED')) @@ -149,7 +149,7 @@ class Coupon extends BaseI18nLoop ->set("IS_AVAILABLE_ON_SPECIAL_OFFERS", $coupon->getIsAvailableOnSpecialOffers()) ->set("IS_ENABLED", $coupon->getIsEnabled()) ->set("AMOUNT", $coupon->getAmount()) - ->set("APPLICATION_CONDITIONS", $cleanedRules) + ->set("APPLICATION_CONDITIONS", $cleanedConditions) ->set("TOOLTIP", $couponManager->getToolTip()) ->set("DAY_LEFT_BEFORE_EXPIRATION", $daysLeftBeforeExpiration) ->set("SERVICE_ID", $couponManager->getServiceId()); diff --git a/core/lib/Thelia/Coupon/AdapterInterface.php b/core/lib/Thelia/Coupon/AdapterInterface.php index 4ca2b67aa..37979b44f 100644 --- a/core/lib/Thelia/Coupon/AdapterInterface.php +++ b/core/lib/Thelia/Coupon/AdapterInterface.php @@ -165,11 +165,11 @@ interface AdapterInterface public function getRequest(); /** - * Return Condition Validator + * Return Condition Evaluator * * @return ConditionEvaluator */ - public function getConditionValidator(); + public function getConditionEvaluator(); /** * Return all available currencies diff --git a/core/lib/Thelia/Coupon/BaseAdapter.php b/core/lib/Thelia/Coupon/BaseAdapter.php index 6963ef0d6..883758ce1 100644 --- a/core/lib/Thelia/Coupon/BaseAdapter.php +++ b/core/lib/Thelia/Coupon/BaseAdapter.php @@ -27,16 +27,13 @@ use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; -use Thelia\Constraint\ConditionValidator; use Thelia\Core\HttpFoundation\Request; -use Thelia\Core\Security\SecurityContext; use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; use Thelia\Cart\CartTrait; use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; -use Thelia\Model\LangQuery; /** * Created by JetBrains PhpStorm. @@ -266,7 +263,7 @@ class BaseAdapter implements AdapterInterface * * @return ConditionValidator */ - public function getConditionValidator() + public function getConditionEvaluator() { return $this->container->get('thelia.condition.validator'); } diff --git a/core/lib/Thelia/Coupon/CouponFactory.php b/core/lib/Thelia/Coupon/CouponFactory.php index 64c0058b4..e5752a762 100644 --- a/core/lib/Thelia/Coupon/CouponFactory.php +++ b/core/lib/Thelia/Coupon/CouponFactory.php @@ -25,13 +25,11 @@ namespace Thelia\Coupon; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Exception\NotFoundResourceException; -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Condition\ConditionFactory; use Thelia\Coupon\Type\CouponInterface; use Thelia\Exception\CouponExpiredException; -use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidConditionException; use Thelia\Model\Coupon; -use Symfony\Component\Serializer\Encoder\JsonEncoder; /** * Created by JetBrains PhpStorm. @@ -57,7 +55,7 @@ class CouponFactory * * @param ContainerInterface $container Service container */ - function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container) { $this->container = $container; $this->adapter = $container->get('thelia.adapter'); @@ -69,6 +67,7 @@ class CouponFactory * @param string $couponCode Coupon code ex: XMAS * * @throws \Thelia\Exception\CouponExpiredException + * @throws \Thelia\Exception\InvalidConditionException * @throws \Symfony\Component\Translation\Exception\NotFoundResourceException * @return CouponInterface ready to be processed */ @@ -87,9 +86,9 @@ class CouponFactory } /** @var CouponInterface $couponInterface */ - $couponInterface = $this->buildCouponInterfacFromModel($couponModel); - if ($couponInterface->getRules()->isEmpty()) { - throw new InvalidRuleException( + $couponInterface = $this->buildCouponInterfaceFromModel($couponModel); + if ($couponInterface->getConditions()->isEmpty()) { + throw new InvalidConditionException( get_class($couponInterface) ); } @@ -104,7 +103,7 @@ class CouponFactory * * @return CouponInterface ready to use CouponInterface object instance */ - protected function buildCouponInterfacFromModel(Coupon $model) + protected function buildCouponInterfaceFromModel(Coupon $model) { $isCumulative = ($model->getIsCumulative() == 1 ? true : false); $isRemovingPostage = ($model->getIsRemovingPostage() == 1 ? true : false); @@ -130,13 +129,13 @@ class CouponFactory $model->getExpirationDate() ); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); - $rules = $constraintFactory->unserializeCouponRuleCollection( + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditions = $conditionFactory->unserializeConditionCollection( $model->getSerializedRules() ); - $couponManager->setRules($rules); + $couponManager->setConditions($conditions); return $couponManager; } diff --git a/core/lib/Thelia/Coupon/RuleOrganizer.php b/core/lib/Thelia/Coupon/RuleOrganizer.php index 4c95fb7c4..ee840bfbc 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizer.php +++ b/core/lib/Thelia/Coupon/RuleOrganizer.php @@ -30,7 +30,7 @@ namespace Thelia\Coupon; * * Manage how Coupons could interact with a Checkout * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ @@ -39,11 +39,11 @@ class RuleOrganizer implements RuleOrganizerInterface /** * Organize ConditionManagerInterface * - * @param array $rules Array of ConditionManagerInterface + * @param array $conditions Array of ConditionManagerInterface * * @return array Array of ConditionManagerInterface sorted */ - public function organize(array $rules) + public function organize(array $conditions) { // TODO: Implement organize() method. } diff --git a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php index 37a3334f3..93dd12ee9 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php +++ b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php @@ -28,9 +28,9 @@ namespace Thelia\Coupon; * Date: 8/19/13 * Time: 3:24 PM * - * Manage how Coupons could interact with a Checkout + * Manage how Condition could interact with a Checkout * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ @@ -39,9 +39,9 @@ interface RuleOrganizerInterface /** * Organize ConditionManagerInterface * - * @param array $rules Array of ConditionManagerInterface + * @param array $conditions Array of ConditionManagerInterface * * @return array Array of ConditionManagerInterface sorted */ - public function organize(array $rules); + public function organize(array $conditions); } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index ef5e17a27..f3aa392bc 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -24,13 +24,12 @@ namespace Thelia\Coupon\Type; use Symfony\Component\Intl\Exception\NotImplementedException; -use Thelia\Constraint\ConstraintManager; -use Thelia\Constraint\ConditionValidator; +use Thelia\Condition\ConditionEvaluator; use Thelia\Core\Translation\Translator; use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\RuleOrganizerInterface; -use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidConditionException; /** * Created by JetBrains PhpStorm. @@ -55,11 +54,10 @@ abstract class CouponAbstract implements CouponInterface protected $organizer = null; /** @var ConditionCollection Array of ConditionManagerInterface */ - protected $rules = null; - - /** @var ConditionValidator Constraint validator */ - protected $constraintValidator = null; + protected $conditions = null; + /** @var ConditionEvaluator Condition validator */ + protected $conditionEvaluator = null; /** @var string Service Id */ @@ -108,17 +106,17 @@ abstract class CouponAbstract implements CouponInterface * * @param AdapterInterface $adapter Service adapter */ - function __construct(AdapterInterface $adapter) + public function __construct(AdapterInterface $adapter) { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->constraintValidator = $adapter->getConditionValidator(); + $this->conditionEvaluator = $adapter->getConditionEvaluator(); } /** - * Set Rule Organizer + * Set Condition Organizer * - * @param RuleOrganizerInterface $organizer Manage Rule groups (&& and ||) + * @param RuleOrganizerInterface $organizer Manage Condition groups (&& and ||) * * @return $this */ @@ -207,23 +205,23 @@ abstract class CouponAbstract implements CouponInterface * * @return ConditionCollection */ - public function getRules() + public function getConditions() { - return clone $this->rules; + return clone $this->conditions; } /** - * Replace the existing Rules by those given in parameter - * If one Rule is badly implemented, no Rule will be added + * Replace the existing Conditions by those given in parameter + * If one Condition is badly implemented, no Condition will be added * - * @param ConditionCollection $rules ConditionManagerInterface to add + * @param ConditionCollection $conditions ConditionManagerInterface to add * * @return $this - * @throws \Thelia\Exception\InvalidRuleException + * @throws \Thelia\Exception\InvalidConditionException */ - public function setRules(ConditionCollection $rules) + public function setConditions(ConditionCollection $conditions) { - $this->rules = $rules; + $this->conditions = $conditions; return $this; } @@ -249,7 +247,6 @@ abstract class CouponAbstract implements CouponInterface return $this->isAvailableOnSpecialOffers; } - /** * Check if Coupon has been disabled by admin * @@ -300,14 +297,14 @@ abstract class CouponAbstract implements CouponInterface /** - * Check if the current Coupon is matching its conditions (Rules) + * Check if the current state of the application is matching this Coupon conditions * Thelia variables are given by the AdapterInterface * * @return bool */ public function isMatching() { - return $this->constraintValidator->isMatching($this->rules); + return $this->conditionEvaluator->isMatching($this->conditions); } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index d8ef41f43..192a608e8 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -142,7 +142,7 @@ interface CouponInterface * * @return ConditionCollection A set of ConditionManagerInterface */ - public function getRules(); + public function getConditions(); /** * Replace the existing Rules by those given in parameter @@ -151,9 +151,9 @@ interface CouponInterface * @param ConditionCollection $rules ConditionManagerInterface to add * * @return $this - * @throws \Thelia\Exception\InvalidRuleException + * @throws \Thelia\Exception\InvalidConditionException */ - public function setRules(ConditionCollection $rules); + public function setConditions(ConditionCollection $rules); /** * Return Coupon expiration date diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php b/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php index eb5dc4548..1f9e12420 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon\Type; -use Thelia\Constraint\ConstraintManager; use Thelia\Coupon\Type\CouponAbstract; /** diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php index be6b65aea..d5c45b4d3 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon\Type; -use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\Type\CouponAbstract; use Thelia\Exception\MissingAdapterException; diff --git a/core/lib/Thelia/Exception/InvalidRuleException.php b/core/lib/Thelia/Exception/InvalidConditionException.php similarity index 88% rename from core/lib/Thelia/Exception/InvalidRuleException.php rename to core/lib/Thelia/Exception/InvalidConditionException.php index f2eb48a84..dbc3315c8 100644 --- a/core/lib/Thelia/Exception/InvalidRuleException.php +++ b/core/lib/Thelia/Exception/InvalidConditionException.php @@ -30,23 +30,23 @@ use Thelia\Log\Tlog; * Date: 8/19/13 * Time: 3:24 PM * - * Thrown when a Rule is badly implemented + * Thrown when a Condition is badly implemented * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ -class InvalidRuleException extends \RuntimeException +class InvalidConditionException extends \RuntimeException { /** - * InvalidConditionOperatorException thrown when a Rule is badly implemented + * InvalidConditionOperatorException thrown when a Condition is badly implemented * * @param string $className Class name */ public function __construct($className) { - $message = 'Invalid Rule given to ' . $className; + $message = 'Invalid Condition given to ' . $className; Tlog::getInstance()->addError($message); parent::__construct($message); diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php new file mode 100644 index 000000000..8efc4d38f --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php @@ -0,0 +1,227 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test ConditionFactory Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class ConditionFactoryTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + public function setUp() + { + } + + /** + * Check the Rules serialization module + */ + public function testBuild() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $conditionFactory = new ConditionFactory($this->getContainer()); + $ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values); + + $expected = $condition1; + $actual = $ruleManager1; + + $this->assertEquals($expected, $actual); + $this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId()); + $this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators()); + } + +// /** +// * Check the Rules serialization module +// */ +// public function testBuildFail() +// { +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 40.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition1->setValidatorsFromForm($operators, $values); +// +// $conditionFactory = new ConditionFactory($this->getContainer()); +// $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values); +// +// $expected = false; +// $actual = $conditionManager1; +// +// $this->assertEquals($expected, $actual); +// } +// +// /** +// * Check the Rules serialization module +// */ +// public function testRuleSerialisation() +// { +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 40.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition1->setValidatorsFromForm($operators, $values); +// +// $condition2 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 400.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition2->setValidatorsFromForm($operators, $values); +// +// $conditions = new ConditionCollection(); +// $conditions->add($condition1); +// $conditions->add($condition2); +// +// $conditionFactory = new ConditionFactory($this->getContainer()); +// +// $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); +// $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions); +// +// $expected = (string) $conditions; +// $actual = (string) $unserializedConditions; +// +// $this->assertEquals($expected, $actual); +// } +// +// /** +// * Get Mocked Container with 2 Rules +// * +// * @return ContainerBuilder +// */ +// public function getContainer() +// { +// $container = new ContainerBuilder(); +// +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $condition2 = new MatchForXArticlesManager($stubAdapter); +// +// $adapter = new BaseAdapter($container); +// +// $container->set('thelia.condition.match_for_total_amount', $condition1); +// $container->set('thelia.condition.match_for_x_articles', $condition2); +// $container->set('thelia.adapter', $adapter); +// +// return $container; +// } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } +} diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php b/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php similarity index 53% rename from core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php rename to core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php index e3e83eb2b..5d7ae29d7 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php +++ b/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php @@ -21,12 +21,12 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint; +namespace Thelia\Condition\Implementation; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\BaseAdapter; use Thelia\Coupon\ConditionCollection; @@ -41,7 +41,7 @@ use Thelia\Coupon\ConditionCollection; * @author Guillaume MOREL * */ -class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase +class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase { /** @@ -54,8 +54,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess1Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -66,23 +68,23 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; $actual =$isValid; @@ -91,8 +93,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail1Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -103,33 +107,35 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; $actual =$isValid; - $this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules'); + $this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions'); } public function testTestSuccess2Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -143,33 +149,33 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(5)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => '>' + MatchForXArticlesManager::INPUT1 => '>' ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; $actual =$isValid; @@ -178,8 +184,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail2Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -193,101 +201,101 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(5)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => '>' + MatchForXArticlesManager::INPUT1 => '>' ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; $actual =$isValid; - $this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules'); + $this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions'); } public function testVariableOpComparisonSuccess() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = true; - $actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::DIFFERENT, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR, 0); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::IN, array(1, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3)); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::OUT, array(0, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3)); $this->assertEquals($expected, $actual); } public function testVariableOpComparisonFail() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = false; - $actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::DIFFERENT, 2); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(0, Operators::SUPERIOR, 0); + $actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(3, Operators::INFERIOR, 2); + $actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4); + $actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(0, Operators::IN, array(1, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3)); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::OUT, array(0, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3)); $this->assertEquals($expected, $actual); } @@ -297,9 +305,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase */ public function testVariableOpComparisonException() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = true; - $actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1); + $actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1); $this->assertEquals($expected, $actual); } @@ -316,7 +324,8 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -324,13 +333,13 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getTranslator') ->will($this->returnValue($stubTranslator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $adapter = new BaseAdapter($container); - $container->set('thelia.condition.match_for_total_amount', $rule1); - $container->set('thelia.condition.match_for_x_articles', $rule2); + $container->set('thelia.condition.match_for_total_amount', $condition1); + $container->set('thelia.condition.match_for_x_articles', $condition2); $container->set('thelia.adapter', $adapter); return $container; diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php new file mode 100644 index 000000000..cc142ac38 --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php @@ -0,0 +1,610 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; +use Thelia\Exception\InvalidConditionValueException; +use Thelia\Model\Currency; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test MatchForTotalAmountManager Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase +{ + /** @var AdapterInterface $stubTheliaAdapter */ + protected $stubTheliaAdapter = null; + + /** + * Generate adapter stub + * + * @param int $cartTotalPrice Cart total price + * @param string $checkoutCurrency Checkout currency + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue($cartTotalPrice)); + + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue($checkoutCurrency)); + + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currency1 = new Currency(); + $currency1->setCode('EUR'); + $currency2 = new Currency(); + $currency2->setCode('USD'); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue(array($currency1, $currency2))); + + return $stubAdapter; + } + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionOperatorException + * + */ + public function testInValidBackOfficeInputOperator() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::IN, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => '400', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionOperatorException + * + */ + public function testInValidBackOfficeInputOperator2() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::INFERIOR + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => '400', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionValueException + * + */ + public function testInValidBackOfficeInputValue() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 'X', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionValueException + * + */ + public function testInValidBackOfficeInputValue2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400, + MatchForTotalAmountManager::INPUT2 => 'FLA'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionInferior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferiorEquals2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionInferiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test equals operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionEqual() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test equals operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionEqual() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperiorEquals2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionSuperiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionSuperior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check currency is checked + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionCurrency() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check currency is checked + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionCurrency() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400.00, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'USD'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php similarity index 54% rename from core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php index 468a813c2..4243b1082 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php @@ -21,12 +21,12 @@ /* */ /**********************************************************************************/ -namespace Thelia\Coupon; +namespace Thelia\Condition\Implementation; -use Thelia\Constraint\ConditionValidator; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Constraint\Rule\SerializableRule; +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Condition\SerializableCondition; +use Thelia\Coupon\AdapterInterface; /** * Created by JetBrains PhpStorm. @@ -39,12 +39,9 @@ use Thelia\Constraint\Rule\SerializableRule; * @author Guillaume MOREL * */ -class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase +class MatchForXArticlesManagerTest extends \PHPUnit_Framework_TestCase { -// /** @var AdapterInterface $stubTheliaAdapter */ -// protected $stubTheliaAdapter = null; - /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -57,32 +54,34 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidConditionOperatorException */ public function testInValidBackOfficeInputOperator() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); + /** @var AdapterInterface $stubAdapter */ $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::IN + MatchForXArticlesManager::INPUT1 => Operators::IN ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -92,12 +91,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidConditionValueException */ public function testInValidBackOfficeInputValue() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -105,19 +105,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 'X' + MatchForXArticlesManager::INPUT1 => 'X' ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -127,12 +127,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -140,19 +141,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -162,12 +163,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -175,19 +177,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4, + MatchForXArticlesManager::INPUT1 => 4, ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -197,12 +199,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -210,19 +213,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5, + MatchForXArticlesManager::INPUT1 => 5, ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -232,12 +235,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -245,19 +249,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -267,12 +271,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -280,19 +285,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -302,12 +307,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test equals operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -315,19 +321,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::EQUAL + MatchForXArticlesManager::INPUT1 => Operators::EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -337,12 +343,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test equals operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -350,19 +357,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::EQUAL + MatchForXArticlesManager::INPUT1 => Operators::EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -372,12 +379,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -385,19 +393,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -407,12 +415,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -420,19 +429,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -442,12 +451,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -455,19 +465,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -477,12 +487,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -490,19 +501,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -512,12 +523,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -525,19 +537,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -546,7 +558,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase public function testGetSerializableRule() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -554,22 +567,22 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $serializableRule = $rule1->getSerializableRule(); + $serializableRule = $condition1->getSerializableCondition(); - $expected = new SerializableRule(); - $expected->ruleServiceId = $rule1->getServiceId(); + $expected = new SerializableCondition(); + $expected->conditionServiceId = $condition1->getServiceId(); $expected->operators = $operators; $expected->values = $values; @@ -581,7 +594,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase public function testGetAvailableOperators() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -589,20 +603,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); $expected = array( - AvailableForXArticlesManager::INPUT1 => array( + MatchForXArticlesManager::INPUT1 => array( Operators::INFERIOR, Operators::INFERIOR_OR_EQUAL, Operators::EQUAL, @@ -610,7 +624,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase Operators::SUPERIOR ) ); - $actual = $rule1->getAvailableOperators(); + $actual = $condition1->getAvailableOperators(); $this->assertEquals($expected, $actual); @@ -626,20 +640,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase // ->method('getNbArticlesInCart') // ->will($this->returnValue(4)); // -// $rule1 = new MatchForXArticlesManager($stubAdapter); +// $condition1 = new MatchForXArticlesManager($stubAdapter); // $operators = array( // MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR // ); // $values = array( // MatchForXArticlesManager::INPUT1 => 4 // ); -// $rule1->setValidatorsFromForm($operators, $values); +// $condition1->setValidatorsFromForm($operators, $values); // // $expected = array( // $operators, // $values // ); -// $actual = $rule1->getValidators(); +// $actual = $condition1->getValidators(); // // $this->assertEquals($expected, $actual); // diff --git a/core/lib/Thelia/Tests/Condition/OperatorsTest.php b/core/lib/Thelia/Tests/Condition/OperatorsTest.php new file mode 100644 index 000000000..667714189 --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/OperatorsTest.php @@ -0,0 +1,114 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition; + +use Thelia\Core\Translation\Translator; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test Operators Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class OperatorsTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + } + + public function testOperatorI18n() + { + /** @var Translator $stubTranslator */ + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnCallback((array($this, 'callbackI18n')))); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); + $expected = 'inferior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); + $expected = 'inferior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::EQUAL); + $expected = 'equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL); + $expected = 'superior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); + $expected = 'superior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); + $expected = 'different from'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::IN); + $expected = 'in'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::OUT); + $expected = 'not in'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, 'unexpected operator'); + $expected = 'unexpected operator'; + $this->assertEquals($expected, $actual); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + function callbackI18n() + { + $args = func_get_args(); + + return $args[0]; + } +} + + diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php deleted file mode 100644 index f7f2b131a..000000000 --- a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php +++ /dev/null @@ -1,228 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\BaseAdapter; -use Thelia\Coupon\ConditionCollection; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test ConstraintManager Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase -{ - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - public function setUp() - { - } - - /** - * Check the Rules serialization module - */ - public function testBuild() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - $ruleManager1 = $constraintFactory->build($rule1->getServiceId(), $operators, $values); - - $expected = $rule1; - $actual = $ruleManager1; - - $this->assertEquals($expected, $actual); - $this->assertEquals($rule1->getServiceId(), $ruleManager1->getServiceId()); - $this->assertEquals($rule1->getValidators(), $ruleManager1->getValidators()); - } - - /** - * Check the Rules serialization module - */ - public function testBuildFail() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - $ruleManager1 = $constraintFactory->build('unset.service', $operators, $values); - - $expected = false; - $actual = $ruleManager1; - - $this->assertEquals($expected, $actual); - } - - /** - * Check the Rules serialization module - */ - public function testRuleSerialisation() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - $rule2 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule2->setValidatorsFromForm($operators, $values); - - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $unserializedRules = $constraintFactory->unserializeCouponRuleCollection($serializedRules); - - $expected = (string) $rules; - $actual = (string) $unserializedRules; - - $this->assertEquals($expected, $actual); - } - - /** - * Get Mocked Container with 2 Rules - * - * @return ContainerBuilder - */ - public function getContainer() - { - $container = new ContainerBuilder(); - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $rule2 = new AvailableForXArticlesManager($stubAdapter); - - $adapter = new BaseAdapter($container); - - $container->set('thelia.condition.match_for_total_amount', $rule1); - $container->set('thelia.condition.match_for_x_articles', $rule2); - $container->set('thelia.adapter', $adapter); - - return $container; - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } -} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php deleted file mode 100644 index 53cf39a9b..000000000 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php +++ /dev/null @@ -1,592 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\ConditionValidator; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Exception\InvalidConditionValueException; -use Thelia\Model\Currency; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test MatchForTotalAmountManager Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase -{ - /** @var AdapterInterface $stubTheliaAdapter */ - protected $stubTheliaAdapter = null; - - /** - * Generate adapter stub - * - * @param int $cartTotalPrice Cart total price - * @param string $checkoutCurrency Checkout currency - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') - { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue($cartTotalPrice)); - - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue($checkoutCurrency)); - - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); - - $currency1 = new Currency(); - $currency1->setCode('EUR'); - $currency2 = new Currency(); - $currency2->setCode('USD'); - $stubAdapter->expects($this->any()) - ->method('getAvailableCurrencies') - ->will($this->returnValue(array($currency1, $currency2))); - - return $stubAdapter; - } - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionOperatorException - * - */ - public function testInValidBackOfficeInputOperator() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::IN, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => '400', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionOperatorException - * - */ - public function testInValidBackOfficeInputOperator2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::INFERIOR - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => '400', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionValueException - * - */ - public function testInValidBackOfficeInputValue() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 'X', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionValueException - * - */ - public function testInValidBackOfficeInputValue2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400, - AvailableForTotalAmountManager::INPUT2 => 'FLA'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferior() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleInferior() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferiorEquals() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferiorEquals2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleInferiorEquals() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test equals operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleEqual() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test equals operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleEqual() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperiorEquals() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperiorEquals2() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleSuperiorEquals() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperior() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleSuperior() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check currency is checked - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleCurrency() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check currency is checked - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleCurrency() - { - $stubAdapter = $this->generateAdapterStub(400.00, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'USD'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php deleted file mode 100644 index ef9340dac..000000000 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ /dev/null @@ -1,481 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\Rule\Operators; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test Operators Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class OperatorsTest extends \PHPUnit_Framework_TestCase -{ - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - -// public function testSomething() -// { -// // Stop here and mark this test as incomplete. -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } - - public function testOperatorI18n() - { - $stubTranslator = $this->getMockBuilder('\Symfony\Component\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubTranslator->expects($this->any()) - ->method('trans') - ->will($this->returnCallback((array($this, 'callbackI18n')))); - - $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); - $expected = 'inferior to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); - $expected = 'inferior or equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::EQUAL); - $expected = 'equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL); - $expected = 'superior or equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); - $expected = 'superior to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); - $expected = 'different from'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::IN); - $expected = 'in'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::OUT); - $expected = 'not in'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, 'unexpected operator'); - $expected = 'unexpected operator'; - $this->assertEquals($expected, $actual); - } - - -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorValidBefore() -// { -// $adapter = new BaseAdapter(); -// // Given -// $a = 11; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorInvalidEquals() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorInvalidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualValidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 10; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualInValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualInValidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualInValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 14; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualInvalidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorInvalidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorInvalidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorDifferentValid() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::DIFFERENT; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorDifferentInvalidEquals() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::DIFFERENT; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInValid() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = 'X'; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - function callbackI18n() { - $args = func_get_args(); - - return $args[0]; - } -} - - diff --git a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php deleted file mode 100644 index d78faacd0..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php +++ /dev/null @@ -1,168 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\CustomerParam; -use Thelia\Constraint\Validator\QuantityParam; -use Thelia\Model\Customer; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test CustomerParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class CustomerParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** @var AdapterInterface $stubTheliaAdapter */ -// protected $stubTheliaAdapter = null; -// -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// /** @var AdapterInterface $stubTheliaAdapter */ -// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); -// } -// -// /** -// * Generate valid BaseAdapter -// * -// * @param int $customerId Customer id -// * -// * @return AdapterInterface -// */ -// protected function generateValidCouponBaseAdapterMock($customerId = 4521) -// { -// $customer = new Customer(); -// $customer->setId($customerId); -// $customer->setFirstname('Firstname'); -// $customer->setLastname('Lastname'); -// $customer->setEmail('em@il.com'); -// -// /** @var AdapterInterface $stubTheliaAdapter */ -// $stubTheliaAdapter = $this->getMock( -// 'Thelia\Coupon\BaseAdapter', -// array('getCustomer'), -// array() -// ); -// $stubTheliaAdapter->expects($this->any()) -// ->method('getCustomer') -// ->will($this->returnValue($customer)); -// -// return $stubTheliaAdapter; -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testCanUseCoupon() -// { -// $customerId = 4521; -// $couponValidForCustomerId = 4521; -// -// $adapter = $this->generateValidCouponBaseAdapterMock($customerId); -// -// $customerParam = new CustomerParam($adapter, $couponValidForCustomerId); -// -// $expected = 0; -// $actual = $customerParam->compareTo($customerId); -// $this->assertEquals($expected, $actual); -// } -// -//// /** -//// * -//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -//// * -//// */ -//// public function testCanNotUseCouponTest() -//// { -//// -//// } -//// -//// /** -//// * -//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -//// * @expectedException InvalidArgumentException -//// * -//// */ -//// public function testCanNotUseCouponCustomerNotFoundTest() -//// { -//// -//// } -// -// -// -// -//// /** -//// * Test is the object is serializable -//// * If no data is lost during the process -//// */ -//// public function isSerializableTest() -//// { -//// $adapter = new BaseAdapter(); -//// $intValidator = 42; -//// $intToValidate = -1; -//// -//// $param = new QuantityParam($adapter, $intValidator); -//// -//// $serialized = base64_encode(serialize($param)); -//// /** @var QuantityParam $unserialized */ -//// $unserialized = base64_decode(serialize($serialized)); -//// -//// $this->assertEquals($param->getValue(), $unserialized->getValue()); -//// $this->assertEquals($param->getInteger(), $unserialized->getInteger()); -//// -//// $new = new QuantityParam($adapter, $unserialized->getInteger()); -//// $this->assertEquals($param->getInteger(), $new->getInteger()); -//// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php deleted file mode 100644 index 9fa382317..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php +++ /dev/null @@ -1,158 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\DateParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test DateParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class DateParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = 1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testEqualsDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testSuperiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-09"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = -1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $dateParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// -// $param = new DateParam($adapter, $dateValidator); -// -// $serialized = base64_encode(serialize($param)); -// /** @var DateParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getDateTime(), $unserialized->getDateTime()); -// -// $new = new DateParam($adapter, $unserialized->getDateTime()); -// $this->assertEquals($param->getDateTime(), $new->getDateTime()); -// } -// -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php deleted file mode 100644 index 3761a2a11..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php +++ /dev/null @@ -1,159 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\IntegerParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test IntegerParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntegerParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testInferiorInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 41; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testEqualsInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 42; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testSuperiorInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 43; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = -1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = '42'; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// -// $param = new IntegerParam($adapter, $intValidator); -// -// $serialized = base64_encode(serialize($param)); -// /** @var IntegerParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getInteger(), $unserialized->getInteger()); -// -// $new = new IntegerParam($adapter, $unserialized->getInteger()); -// $this->assertEquals($param->getInteger(), $new->getInteger()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php deleted file mode 100644 index ce59875cc..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php +++ /dev/null @@ -1,184 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\IntervalParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test IntervalParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntervalParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testEqualsDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-07-08"); -// -// echo '1 ' . date_format($dateValidatorStart, 'g:ia \o\n l jS F Y') . "\n"; -// echo '2 ' . date_format($dateToValidate, 'g:ia \o\n l jS F Y') . "\n"; -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testEqualsDate2() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testSuperiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-08-09"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = -1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = 1377012588; -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $dateParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// -// $param = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $serialized = base64_encode(serialize($param)); -// /** @var IntervalParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod()); -// -// $new = new IntervalParam($adapter, $unserialized->getStart(), $unserialized->getInterval()); -// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php deleted file mode 100644 index 892800f50..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php +++ /dev/null @@ -1,237 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\PriceParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test PriceParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class PriceParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testInferiorPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 1.00; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testInferiorPrice2() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.49; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testEqualsPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.50; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testSuperiorPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.51; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = -1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = '42.50'; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException2() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = -1; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException3() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 0; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException4() -// { -// $adapter = new BaseAdapter(); -// $priceValidator = 42.50; -// $priceToValidate = 1; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'GBP'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $priceValidator = 42.50; -// -// $param = new PriceParam($adapter, $priceValidator, 'GBP'); -// -// $serialized = base64_encode(serialize($param)); -// /** @var PriceParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getPrice(), $unserialized->getPrice()); -// $this->assertEquals($param->getCurrency(), $unserialized->getCurrency()); -// -// $new = new PriceParam($adapter, $unserialized->getPrice(), $unserialized->getCurrency()); -// $this->assertEquals($param->getPrice(), $new->getPrice()); -// $this->assertEquals($param->getCurrency(), $new->getCurrency()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php deleted file mode 100644 index 4c2155ee8..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php +++ /dev/null @@ -1,195 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\QuantityParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test QuantityParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class QuantityParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testInferiorQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 0; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testInferiorQuantity2() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 41; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testEqualsQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 42; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testSuperiorQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 43; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = -1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = '42'; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException2() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = -1; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = -1; -// -// $param = new QuantityParam($adapter, $intValidator); -// -// $serialized = base64_encode(serialize($param)); -// /** @var QuantityParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getInteger(), $unserialized->getInteger()); -// -// $new = new QuantityParam($adapter, $unserialized->getInteger()); -// $this->assertEquals($param->getInteger(), $new->getInteger()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php deleted file mode 100644 index 8e2d344b8..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php +++ /dev/null @@ -1,309 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\RepeatedDateParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RepeatedDateParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 1); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-09-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 10); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-05-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 10); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-11-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-03-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-12-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testSuperiorDateRepeatEveryFourMonthTwoTimes() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-03-09"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $repeatedDateParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// -// $param = new RepeatedDateParam($adapter); -// $param->setFrom($startDateValidator); -// $param->repeatEveryMonth(4, 2); -// -// $serialized = base64_encode(serialize($param)); -// /** @var RepeatedDateParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod()); -// -// $new = new RepeatedDateParam($adapter); -// $new->setFrom($unserialized->getFrom()); -// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition()); -// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php deleted file mode 100644 index bf138da93..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php +++ /dev/null @@ -1,426 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\Validator\RepeatedIntervalParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RepeatedIntervalParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-07-19"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-08-01"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-08-07"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testSuperiorDateRepeatEveryMonthFourTime() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-10-19"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 0); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException \InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $RepeatedIntervalParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// $duration = 10; -// -// $param = new RepeatedIntervalParam($adapter); -// $param->setFrom($startDateValidator); -// $param->setDurationInDays($duration); -// $param->repeatEveryMonth(1, 4); -// -// $serialized = base64_encode(serialize($param)); -// /** @var RepeatedIntervalParam $unserialized */ -// $unserialized = base64_decode(serialize($serialized)); -// -// $this->assertEquals($param->getValue(), $unserialized->getValue()); -// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod()); -// -// $new = new RepeatedIntervalParam($adapter); -// $new->setFrom($unserialized->getFrom()); -// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition()); -// $new->setDurationInDays($unserialized->getDurationInDays()); -// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index 3d609c497..6341a199e 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -161,7 +161,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // * Test if an expired Coupon is build or not (equal) // * // * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // */ // public function testBuildCouponFromCodeWithoutRule() // { diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index f3a4ff620..de739bf90 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -197,7 +197,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // * Test Coupon rule setter // * // * @covers Thelia\Coupon\type\RemoveXAmountManager::setRules -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // * // */ // public function testSetRulesInvalid() diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php deleted file mode 100644 index ac13d4ea0..000000000 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php +++ /dev/null @@ -1,70 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RemoveXPercentForCategoryY Class - * - * @package Coupon - * @author Guillaume MOREL - * - */ -class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// public function incompleteTest() -// { -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index 4d60604f5..b1b012fb3 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -169,7 +169,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // * Test Coupon rule setter // * // * @covers Thelia\Coupon\type\RemoveXPercentManager::setRules -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // * // */ // public function testSetRulesInvalid() diff --git a/install/faker.php b/install/faker.php index 7e2b6e84d..68673394b 100755 --- a/install/faker.php +++ b/install/faker.php @@ -1,9 +1,11 @@ 20, 'Description' /** * Generate Coupon fixtures */ -function generateCouponFixtures($thelia) +function generateCouponFixtures(\Thelia\Core\Thelia $thelia) { + /** @var $container ContainerInterface Service Container */ $container = $thelia->getContainer(); + /** @var AdapterInterface $adapter */ $adapter = $container->get('thelia.adapter'); // Coupons @@ -663,36 +667,36 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months"))); - $rule1 = new AvailableForTotalAmountManager($adapter); + $condition1 = new MatchForTotalAmountManager($adapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForTotalAmountManager($adapter); + $condition2 = new MatchForTotalAmountManager($adapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon1->setSerializedRules($serializedRules); + $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); + $coupon1->setSerializedRules($serializedConditions); $coupon1->setMaxUsage(40); $coupon1->setIsCumulative(1); $coupon1->setIsRemovingPostage(0); @@ -721,22 +725,22 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months"))); - $rule1 = new AvailableForXArticlesManager($adapter); + $condition1 = new MatchForXArticlesManager($adapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR, + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR, ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4, + MatchForXArticlesManager::INPUT1 => 4, ); - $rule1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $condition1->setValidatorsFromForm($operators, $values); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon2->setSerializedRules($serializedRules); + $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); + $coupon2->setSerializedRules($serializedConditions); $coupon2->setMaxUsage(-1); $coupon2->setIsCumulative(0); $coupon2->setIsRemovingPostage(1); @@ -765,18 +769,18 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); - $rule1 = new MatchForEveryoneManager($adapter); + $condition1 = new MatchForEveryoneManager($adapter); $operators = array(); $values = array(); - $rule1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $condition1->setValidatorsFromForm($operators, $values); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + /** @var ConditionFactory $constraintCondition */ + $constraintCondition = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon3->setSerializedRules($serializedRules); + $serializedConditions = $constraintCondition->serializeConditionCollection($conditions); + $coupon3->setSerializedRules($serializedConditions); $coupon3->setMaxUsage(-1); $coupon3->setIsCumulative(1); $coupon3->setIsRemovingPostage(0); diff --git a/install/import.php b/install/import.php index 47313df6e..d0910eede 100644 --- a/install/import.php +++ b/install/import.php @@ -21,11 +21,8 @@ /* */ /*************************************************************************************/ -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\ConditionCollection; +use Thelia\Condition\Implementation\MatchForTotalAmountManager; +use Thelia\Condition\Implementation\MatchForXArticlesManager; require __DIR__ . '/../core/bootstrap.php'; diff --git a/install/tax_faker.php b/install/tax_faker.php index f967ca7a4..85e274c98 100755 --- a/install/tax_faker.php +++ b/install/tax_faker.php @@ -1,16 +1,6 @@ Date: Wed, 25 Sep 2013 16:47:01 +0200 Subject: [PATCH 18/27] WIP : Refactor contraint/rule becomes conditions (more generic) --- core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php index 8efc4d38f..412f81b3a 100644 --- a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php @@ -55,6 +55,12 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase */ public function testBuild() { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + + + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') ->disableOriginalConstructor() ->getMock(); From 0da90c4a993a26af71b816e02f1b5ddc24a678c9 Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 17:22:36 +0200 Subject: [PATCH 19/27] WIP : Condition : Fix unit text --- .../Tests/Condition/ConstraintFactoryTest.php | 302 ++++++++++-------- 1 file changed, 169 insertions(+), 133 deletions(-) diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php index 412f81b3a..6bc279479 100644 --- a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php @@ -24,9 +24,12 @@ namespace Thelia\Condition\Implementation; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Thelia\Condition\ConditionEvaluator; use Thelia\Condition\ConditionFactory; use Thelia\Condition\Operators; use Thelia\Coupon\AdapterInterface; +use Thelia\Coupon\ConditionCollection; +use Thelia\Model\CurrencyQuery; /** * Created by JetBrains PhpStorm. @@ -55,12 +58,6 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase */ public function testBuild() { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') - ->disableOriginalConstructor() - ->getMock(); - - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') ->disableOriginalConstructor() ->getMock(); @@ -73,6 +70,31 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getTranslator') ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter))); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( @@ -85,7 +107,7 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase ); $condition1->setValidatorsFromForm($operators, $values); - $conditionFactory = new ConditionFactory($this->getContainer()); + $conditionFactory = new ConditionFactory($stubContainer); $ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values); $expected = $condition1; @@ -96,132 +118,146 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators()); } -// /** -// * Check the Rules serialization module -// */ -// public function testBuildFail() -// { -// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') -// ->disableOriginalConstructor() -// ->getMock(); -// -// /** @var AdapterInterface $stubAdapter */ -// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $stubAdapter->expects($this->any()) -// ->method('getTranslator') -// ->will($this->returnValue($stubTranslator)); -// -// $condition1 = new MatchForTotalAmountManager($stubAdapter); -// $operators = array( -// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, -// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL -// ); -// $values = array( -// MatchForTotalAmountManager::INPUT1 => 40.00, -// MatchForTotalAmountManager::INPUT2 => 'EUR' -// ); -// $condition1->setValidatorsFromForm($operators, $values); -// -// $conditionFactory = new ConditionFactory($this->getContainer()); -// $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values); -// -// $expected = false; -// $actual = $conditionManager1; -// -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Check the Rules serialization module -// */ -// public function testRuleSerialisation() -// { -// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') -// ->disableOriginalConstructor() -// ->getMock(); -// -// /** @var AdapterInterface $stubAdapter */ -// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $stubAdapter->expects($this->any()) -// ->method('getTranslator') -// ->will($this->returnValue($stubTranslator)); -// -// $condition1 = new MatchForTotalAmountManager($stubAdapter); -// $operators = array( -// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, -// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL -// ); -// $values = array( -// MatchForTotalAmountManager::INPUT1 => 40.00, -// MatchForTotalAmountManager::INPUT2 => 'EUR' -// ); -// $condition1->setValidatorsFromForm($operators, $values); -// -// $condition2 = new MatchForTotalAmountManager($stubAdapter); -// $operators = array( -// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, -// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL -// ); -// $values = array( -// MatchForTotalAmountManager::INPUT1 => 400.00, -// MatchForTotalAmountManager::INPUT2 => 'EUR' -// ); -// $condition2->setValidatorsFromForm($operators, $values); -// -// $conditions = new ConditionCollection(); -// $conditions->add($condition1); -// $conditions->add($condition2); -// -// $conditionFactory = new ConditionFactory($this->getContainer()); -// -// $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); -// $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions); -// -// $expected = (string) $conditions; -// $actual = (string) $unserializedConditions; -// -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Get Mocked Container with 2 Rules -// * -// * @return ContainerBuilder -// */ -// public function getContainer() -// { -// $container = new ContainerBuilder(); -// -// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') -// ->disableOriginalConstructor() -// ->getMock(); -// -// /** @var AdapterInterface $stubAdapter */ -// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $stubAdapter->expects($this->any()) -// ->method('getTranslator') -// ->will($this->returnValue($stubTranslator)); -// -// $condition1 = new MatchForTotalAmountManager($stubAdapter); -// $condition2 = new MatchForXArticlesManager($stubAdapter); -// -// $adapter = new BaseAdapter($container); -// -// $container->set('thelia.condition.match_for_total_amount', $condition1); -// $container->set('thelia.condition.match_for_x_articles', $condition2); -// $container->set('thelia.adapter', $adapter); -// -// return $container; -// } + /** + * Check the Rules serialization module + */ + public function testBuildFail() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter))); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValueMap(array('unset.service', false))); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $conditionFactory = new ConditionFactory($stubContainer); + $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values); + + $expected = false; + $actual = $conditionManager1; + + $this->assertEquals($expected, $actual); + } + + /** + * Check the Rules serialization module + */ + public function testRuleSerialisation() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter))); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $condition2 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition2->setValidatorsFromForm($operators, $values); + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); + + $conditionFactory = new ConditionFactory($stubContainer); + + $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); + $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions); + + $expected = (string) $conditions; + $actual = (string) $unserializedConditions; + + $this->assertEquals($expected, $actual); + } /** * Tears down the fixture, for example, closes a network connection. From 965a50586439be98f964ddc73c51ef416d7ab686 Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 17:47:42 +0200 Subject: [PATCH 20/27] WIP : Condition : Fix unit text --- ...orTest.php => ConstraintEvaluatorTest.php} | 220 +++++++++++++----- 1 file changed, 163 insertions(+), 57 deletions(-) rename core/lib/Thelia/Tests/Condition/{ConstraintValidatorTest.php => ConstraintEvaluatorTest.php} (68%) diff --git a/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php b/core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php similarity index 68% rename from core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php rename to core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php index 5d7ae29d7..7df8d6dfb 100644 --- a/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php +++ b/core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php @@ -27,8 +27,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Thelia\Condition\ConditionEvaluator; use Thelia\Condition\Operators; use Thelia\Coupon\AdapterInterface; -use Thelia\Coupon\BaseAdapter; use Thelia\Coupon\ConditionCollection; +use Thelia\Model\CurrencyQuery; /** * Created by JetBrains PhpStorm. @@ -54,7 +54,9 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess1Rules() { - $conditionEvaluator = new ConditionEvaluator(); + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); /** @var AdapterInterface $stubAdapter */ $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') @@ -62,14 +64,46 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(401)); + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + + $stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager') + ->disableOriginalConstructor() + ->getMock(); + $stubMatchForTotalAmountManager->expects($this->any()) + ->method('isMatching') + ->will($this->returnValue(true)); + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($stubMatchForTotalAmountManager)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConditionEvaluator') - ->will($this->returnValue($conditionEvaluator)); + ->method('getCartTotalPrice') + ->will($this->returnValue(401.00)); $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( @@ -84,6 +118,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $conditions = new ConditionCollection(); $conditions->add($condition1); + $conditionEvaluator = new ConditionEvaluator(); $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; @@ -93,7 +128,9 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase public function testTestFail1Rules() { - $conditionEvaluator = new ConditionEvaluator(); + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); /** @var AdapterInterface $stubAdapter */ $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') @@ -101,14 +138,46 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + + $stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager') + ->disableOriginalConstructor() + ->getMock(); + $stubMatchForTotalAmountManager->expects($this->any()) + ->method('isMatching') + ->will($this->returnValue(true)); + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($stubMatchForTotalAmountManager)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConditionEvaluator') - ->will($this->returnValue($conditionEvaluator)); + ->method('getCartTotalPrice') + ->will($this->returnValue(400.00)); $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( @@ -123,6 +192,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $conditions = new ConditionCollection(); $conditions->add($condition1); + $conditionEvaluator = new ConditionEvaluator(); $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; @@ -132,7 +202,9 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess2Rules() { - $conditionEvaluator = new ConditionEvaluator(); + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); /** @var AdapterInterface $stubAdapter */ $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') @@ -140,17 +212,49 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(401)); + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + + $stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager') + ->disableOriginalConstructor() + ->getMock(); + $stubMatchForTotalAmountManager->expects($this->any()) + ->method('isMatching') + ->will($this->returnValue(true)); + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($stubMatchForTotalAmountManager)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(401.00)); $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(5)); - $stubAdapter->expects($this->any()) - ->method('getConditionEvaluator') - ->will($this->returnValue($conditionEvaluator)); $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( @@ -175,6 +279,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $conditions->add($condition1); $conditions->add($condition2); + $conditionEvaluator = new ConditionEvaluator(); $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; @@ -184,7 +289,9 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase public function testTestFail2Rules() { - $conditionEvaluator = new ConditionEvaluator(); + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); /** @var AdapterInterface $stubAdapter */ $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') @@ -192,17 +299,49 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue(400)); + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + + $stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager') + ->disableOriginalConstructor() + ->getMock(); + $stubMatchForTotalAmountManager->expects($this->any()) + ->method('isMatching') + ->will($this->returnValue(true)); + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($stubMatchForTotalAmountManager)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue(400.00)); $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(5)); - $stubAdapter->expects($this->any()) - ->method('getConditionEvaluator') - ->will($this->returnValue($conditionEvaluator)); $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( @@ -227,6 +366,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $conditions->add($condition1); $conditions->add($condition2); + $conditionEvaluator = new ConditionEvaluator(); $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; @@ -311,40 +451,6 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } - /** - * Get Mocked Container with 2 Rules - * - * @return ContainerBuilder - */ - public function getContainer() - { - $container = new ContainerBuilder(); - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - /** @var AdapterInterface $stubAdapter */ - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $condition1 = new MatchForTotalAmountManager($stubAdapter); - $condition2 = new MatchForXArticlesManager($stubAdapter); - - $adapter = new BaseAdapter($container); - - $container->set('thelia.condition.match_for_total_amount', $condition1); - $container->set('thelia.condition.match_for_x_articles', $condition2); - $container->set('thelia.adapter', $adapter); - - return $container; - } - /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. From 4d3335f5899fa5df4a28bb24e3a3170c9357897a Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 25 Sep 2013 18:15:48 +0200 Subject: [PATCH 21/27] WIP : Condition : Fix unit text --- .../Condition/SerializableCondition.php | 58 ++++---- ...torTest.php => ConditionEvaluatorTest.php} | 0 ...ctoryTest.php => ConditionFactoryTest.php} | 134 ++++++++++++++++++ .../MatchForEveryoneManagerTest.php | 129 +++++++++++++++++ ...php => MatchForTotalAmountManagerTest.php} | 0 ...t.php => MatchForXArticlesManagerTest.php} | 0 6 files changed, 292 insertions(+), 29 deletions(-) rename core/lib/Thelia/Tests/Condition/{ConstraintEvaluatorTest.php => ConditionEvaluatorTest.php} (100%) rename core/lib/Thelia/Tests/Condition/{ConstraintFactoryTest.php => ConditionFactoryTest.php} (69%) create mode 100644 core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php rename core/lib/Thelia/Tests/Condition/Implementation/{AvailableForTotalAmountManagerTest.php => MatchForTotalAmountManagerTest.php} (100%) rename core/lib/Thelia/Tests/Condition/Implementation/{AvailableForXArticlesManagerTest.php => MatchForXArticlesManagerTest.php} (100%) diff --git a/core/lib/Thelia/Condition/SerializableCondition.php b/core/lib/Thelia/Condition/SerializableCondition.php index 9dbec171c..426052506 100644 --- a/core/lib/Thelia/Condition/SerializableCondition.php +++ b/core/lib/Thelia/Condition/SerializableCondition.php @@ -45,33 +45,33 @@ class SerializableCondition /** @var array Values set by Admin for this Condition */ public $values = array(); - /** - * Get Operators set by Admin for this Condition - * - * @return array - */ - public function getOperators() - { - return $this->operators; - } - - /** - * Get Condition Service id - * - * @return string - */ - public function getConditionServiceId() - { - return $this->conditionServiceId; - } - - /** - * Get Values set by Admin for this Condition - * - * @return array - */ - public function getValues() - { - return $this->values; - } +// /** +// * Get Operators set by Admin for this Condition +// * +// * @return array +// */ +// public function getOperators() +// { +// return $this->operators; +// } +// +// /** +// * Get Condition Service id +// * +// * @return string +// */ +// public function getConditionServiceId() +// { +// return $this->conditionServiceId; +// } +// +// /** +// * Get Values set by Admin for this Condition +// * +// * @return array +// */ +// public function getValues() +// { +// return $this->values; +// } } diff --git a/core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php b/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php rename to core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php similarity index 69% rename from core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php rename to core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php index 6bc279479..97686e871 100644 --- a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php @@ -259,6 +259,140 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * Check the getInputs method + */ + public function testGetInputs() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($condition1)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + + $conditionFactory = new ConditionFactory($stubContainer); + + $expected = $condition1->getValidators(); + $actual = $conditionFactory->getInputs('thelia.condition.match_for_x_articles'); + + $this->assertEquals($expected, $actual); + + } + + /** + * Check the getInputs method + */ + public function testGetInputsFalse() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($condition1)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(false)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + + $conditionFactory = new ConditionFactory($stubContainer); + + $expected = false; + $actual = $conditionFactory->getInputs('thelia.condition.unknown'); + + $this->assertEquals($expected, $actual); + + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php new file mode 100644 index 000000000..85e357eca --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php @@ -0,0 +1,129 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; +use Thelia\Exception\InvalidConditionValueException; +use Thelia\Model\Currency; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test MatchForEveryoneManager Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase +{ + /** @var AdapterInterface $stubTheliaAdapter */ + protected $stubTheliaAdapter = null; + + /** + * Generate adapter stub + * + * @param int $cartTotalPrice Cart total price + * @param string $checkoutCurrency Checkout currency + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue($cartTotalPrice)); + + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue($checkoutCurrency)); + + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currency1 = new Currency(); + $currency1->setCode('EUR'); + $currency2 = new Currency(); + $currency2->setCode('USD'); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue(array($currency1, $currency2))); + + return $stubAdapter; + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForEveryoneManager::setValidators + * + */ + public function testValidBackOfficeInputOperator() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForEveryoneManager($stubAdapter); + $operators = array(); + $values = array(); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + + /** + * Check if condition is always matching + * + * @covers Thelia\Condition\Implementation\MatchForEveryoneManager::isMatching + * + */ + public function testIsMatching() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForEveryoneManager($stubAdapter); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual = $isValid; + $this->assertEquals($expected, $actual); + } + +} diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php From 9ceddf4870593d9e8735aae959a4d9e753abda94 Mon Sep 17 00:00:00 2001 From: gmorel Date: Thu, 26 Sep 2013 14:12:53 +0200 Subject: [PATCH 22/27] WIP : Condition : refactor name --- templates/admin/default/coupon/form.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 2eb6487ac..fc62834a4 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -167,13 +167,13 @@
    {if $noRules} - {include file='includes/notifications.html' message={intl l='Please save your Coupon in oder to affect it some application fields'}} + {include file='includes/notifications.html' message={intl l='Please save your Coupon in oder to affect it some conditions'}} {else}
    @@ -182,7 +182,7 @@ - {include file='coupon/rules.html' rules=$rules} + {include file='coupon/conditions.html' conditions=$rules}
    - {intl l='Rules'} + {intl l='Conditions'}
    @@ -191,7 +191,7 @@
    - {intl l='Save this rule'} + {intl l='Save this condition'}
    From c521fb2696469d2d9db85629566a0ef269189822 Mon Sep 17 00:00:00 2001 From: gmorel Date: Thu, 26 Sep 2013 14:12:59 +0200 Subject: [PATCH 23/27] WIP : Condition : refactor name --- templates/admin/default/coupon/conditions.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/admin/default/coupon/conditions.html b/templates/admin/default/coupon/conditions.html index c5a09aa97..bd368eadf 100644 --- a/templates/admin/default/coupon/conditions.html +++ b/templates/admin/default/coupon/conditions.html @@ -1,16 +1,16 @@ -{foreach from=$rules item=rule key=i name=rulesForeach} +{foreach from=$conditions item=condition key=i name=conditionsForeach} - {if !$smarty.foreach.rulesForeach.first} + {if !$smarty.foreach.conditionsForeach.first} {intl l='And'} {/if} - {$rule nofilter} + {$condition nofilter} {intl l='Edit'} - {if $rules|count != 1} + {if $conditions|count != 1} {intl l='Delete'} From 73fde64f5b128c4e643abe330826f251d0520b01 Mon Sep 17 00:00:00 2001 From: gmorel Date: Thu, 26 Sep 2013 17:47:41 +0200 Subject: [PATCH 24/27] WIP : coupon refactor + fix --- core/lib/Thelia/Config/Resources/config.xml | 6 +- .../Thelia/Config/Resources/routing/admin.xml | 10 +- .../Controller/Admin/CouponController.php | 57 +- .../Thelia/Model/Base/AttributeTemplate.php | 76 +- .../Model/Base/AttributeTemplateQuery.php | 47 +- core/lib/Thelia/Model/Base/Coupon.php | 544 ++-- core/lib/Thelia/Model/Base/CouponQuery.php | 328 +-- core/lib/Thelia/Model/Base/CouponVersion.php | 532 ++-- .../Thelia/Model/Base/CouponVersionQuery.php | 328 +-- core/lib/Thelia/Model/Base/FeatureProduct.php | 48 +- .../Thelia/Model/Base/FeatureProductQuery.php | 28 +- .../lib/Thelia/Model/Base/FeatureTemplate.php | 76 +- .../Model/Base/FeatureTemplateQuery.php | 47 +- .../Base/OrderProductAttributeCombination.php | 48 +- .../OrderProductAttributeCombinationQuery.php | 28 +- .../lib/Thelia/Model/Base/OrderProductTax.php | 76 +- .../Model/Base/OrderProductTaxQuery.php | 47 +- .../Thelia/Model/Base/ProductSaleElements.php | 96 +- .../Model/Base/ProductSaleElementsQuery.php | 33 +- .../Model/Map/AttributeTemplateTableMap.php | 36 +- core/lib/Thelia/Model/Map/CouponTableMap.php | 66 +- .../Model/Map/CouponVersionTableMap.php | 66 +- .../Model/Map/FeatureProductTableMap.php | 30 +- core/lib/Thelia/Model/Map/FeatureTableMap.php | 2 +- .../Model/Map/FeatureTemplateTableMap.php | 36 +- ...derProductAttributeCombinationTableMap.php | 30 +- .../Model/Map/OrderProductTaxTableMap.php | 36 +- .../Model/Map/ProductSaleElementsTableMap.php | 40 +- install/faker.php | 30 +- local/config/schema.xml | 2510 +++++++++-------- templates/admin/default/assets/js/coupon.js | 119 +- templates/admin/default/coupon-create.html | 2 +- templates/admin/default/coupon-read.html | 6 +- templates/admin/default/coupon-update.html | 86 +- .../default/coupon/condition-input-ajax.html | 22 +- .../admin/default/coupon/conditions.html | 4 +- templates/admin/default/coupon/form.html | 33 +- .../casperjs/exe/31_coupons_rule.js | 164 +- 38 files changed, 3091 insertions(+), 2682 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 1060adf04..e26526a06 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -281,15 +281,15 @@ - + - + - + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 7f2065929..1d6101f95 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -264,12 +264,12 @@ Thelia\Controller\Admin\CouponController::readAction \d+ - - Thelia\Controller\Admin\CouponController::getRuleInputAction - .* + + Thelia\Controller\Admin\CouponController::getConditionInputAction + .* - - Thelia\Controller\Admin\CouponController::updateRulesAction + + Thelia\Controller\Admin\CouponController::updateConditionsAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 6bebe103e..93d08b7b9 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -208,7 +208,10 @@ class CouponController extends BaseAdminController $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); - +var_dump($coupon->getIsEnabled());; +var_dump($coupon->getIsAvailableOnSpecialOffers());; +var_dump($coupon->getIsCumulative());; +var_dump($coupon->getIsRemovingPostage());; $data = array( 'code' => $coupon->getCode(), 'title' => $coupon->getTitle(), @@ -222,15 +225,15 @@ class CouponController extends BaseAdminController 'isCumulative' => ($coupon->getIsCumulative() == 1), 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), 'maxUsage' => $coupon->getMaxUsage(), - 'rules' => $conditions, + 'conditions' => $conditions, 'locale' => $coupon->getLocale(), ); - $args['rulesObject'] = array(); + $args['conditionsObject'] = array(); /** @var ConditionManagerInterface $condition */ foreach ($conditions->getConditions() as $condition) { - $args['rulesObject'][] = array( + $args['conditionsObject'][] = array( 'serviceId' => $condition->getServiceId(), 'name' => $condition->getName(), 'tooltip' => $condition->getToolTip(), @@ -238,7 +241,7 @@ class CouponController extends BaseAdminController ); } - $args['rules'] = $this->cleanConditionForTemplate($conditions); + $args['conditions'] = $this->cleanConditionForTemplate($conditions); // Setup the object form $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data); @@ -249,14 +252,14 @@ class CouponController extends BaseAdminController $args['couponCode'] = $coupon->getCode(); $args['availableCoupons'] = $this->getAvailableCoupons(); $args['availableConditions'] = $this->getAvailableConditions(); - $args['urlAjaxGetRuleInput'] = $this->getRoute( - 'admin.coupon.rule.input', - array('ruleId' => 'ruleId'), + $args['urlAjaxGetConditionInput'] = $this->getRoute( + 'admin.coupon.condition.input', + array('conditionId' => 'conditionId'), Router::ABSOLUTE_URL ); - $args['urlAjaxUpdateRules'] = $this->getRoute( - 'admin.coupon.rule.update', + $args['urlAjaxUpdateConditions'] = $this->getRoute( + 'admin.coupon.condition.update', array('couponId' => $couponId), Router::ABSOLUTE_URL ); @@ -269,11 +272,11 @@ class CouponController extends BaseAdminController /** * Manage Coupons read display * - * @param string $ruleId Rule service id + * @param string $conditionId Condition service id * * @return \Symfony\Component\HttpFoundation\Response */ - public function getRuleInputAction($ruleId) + public function getConditionInputAction($conditionId) { $this->checkAuth('ADMIN', 'admin.coupon.read'); @@ -281,7 +284,7 @@ class CouponController extends BaseAdminController /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->container->get('thelia.condition.factory'); - $inputs = $conditionFactory->getInputs($ruleId); + $inputs = $conditionFactory->getInputs($conditionId); if ($inputs === null) { return $this->pageNotFound(); @@ -290,7 +293,7 @@ class CouponController extends BaseAdminController return $this->render( 'coupon/condition-input-ajax', array( - 'ruleId' => $ruleId, + 'conditionId' => $conditionId, 'inputs' => $inputs ) ); @@ -304,7 +307,7 @@ class CouponController extends BaseAdminController * * @return \Symfony\Component\HttpFoundation\Response */ - public function updateRulesAction($couponId) + public function updateConditionsAction($couponId) { $this->checkAuth('ADMIN', 'admin.coupon.read'); @@ -322,7 +325,7 @@ class CouponController extends BaseAdminController /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->container->get('thelia.condition.factory'); - $conditionsReceived = json_decode($this->getRequest()->get('rules')); + $conditionsReceived = json_decode($this->getRequest()->get('conditions')); foreach ($conditionsReceived as $conditionReceived) { $condition = $conditionFactory->build( $conditionReceived->serviceId, @@ -332,8 +335,8 @@ class CouponController extends BaseAdminController $conditions->add(clone $condition); } -// $coupon->setSerializedRules( -// $conditionFactory->serializeCouponRuleCollection($rules) +// $coupon->setSerializedConditions( +// $conditionFactory->serializeCouponConditionCollection($conditions) // ); $conditionEvent = new ConditionCreateOrUpdateEvent( @@ -362,7 +365,7 @@ class CouponController extends BaseAdminController 'coupon/conditions', array( 'couponId' => $couponId, - 'rules' => $cleanedConditions, + 'conditions' => $cleanedConditions, 'urlEdit' => $couponId, 'urlDelete' => $couponId ) @@ -412,7 +415,7 @@ class CouponController extends BaseAdminController $couponBeingCreated->setAmount($data['amount']); $couponBeingCreated->setIsEnabled($data['isEnabled']); $couponBeingCreated->setExpirationDate($data['expirationDate']); - $couponBeingCreated->setSerializedRules( + $couponBeingCreated->setSerializedConditions( new ConditionCollection( array() ) @@ -589,22 +592,22 @@ class CouponController extends BaseAdminController } // /** -// * Validation Rule creation +// * Validation Condition creation // * -// * @param string $type Rule class type -// * @param string $operator Rule operator (<, >, =, etc) -// * @param array $values Rules values +// * @param string $type Condition class type +// * @param string $operator Condition operator (<, >, =, etc) +// * @param array $values Condition values // * // * @return bool // */ -// protected function validateRulesCreation($type, $operator, $values) +// protected function validateConditionsCreation($type, $operator, $values) // { // /** @var AdapterInterface $adapter */ // $adapter = $this->container->get('thelia.adapter'); // $validator = new PriceParam() // try { -// $rule = new AvailableForTotalAmount($adapter, $validators); -// $rule = new $type($adapter, $validators); +// $condition = new AvailableForTotalAmount($adapter, $validators); +// $condition = new $type($adapter, $validators); // } catch (\Exception $e) { // return false; // } diff --git a/core/lib/Thelia/Model/Base/AttributeTemplate.php b/core/lib/Thelia/Model/Base/AttributeTemplate.php index cedc85431..85d432a62 100644 --- a/core/lib/Thelia/Model/Base/AttributeTemplate.php +++ b/core/lib/Thelia/Model/Base/AttributeTemplate.php @@ -76,6 +76,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface */ protected $template_id; + /** + * The value for the position field. + * @var int + */ + protected $position; + /** * The value for the created_at field. * @var string @@ -393,6 +399,17 @@ abstract class AttributeTemplate implements ActiveRecordInterface return $this->template_id; } + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -504,6 +521,27 @@ abstract class AttributeTemplate implements ActiveRecordInterface return $this; } // setTemplateId() + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\AttributeTemplate The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[] = AttributeTemplateTableMap::POSITION; + } + + + return $this; + } // setPosition() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -592,13 +630,16 @@ abstract class AttributeTemplate implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AttributeTemplateTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; $this->template_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeTemplateTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeTemplateTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeTemplateTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AttributeTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -611,7 +652,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 5; // 5 = AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 6; // 6 = AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\AttributeTemplate object", 0, $e); @@ -867,6 +908,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface if ($this->isColumnModified(AttributeTemplateTableMap::TEMPLATE_ID)) { $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; } + if ($this->isColumnModified(AttributeTemplateTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = 'POSITION'; + } if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -893,6 +937,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface case 'TEMPLATE_ID': $stmt->bindValue($identifier, $this->template_id, PDO::PARAM_INT); break; + case 'POSITION': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -971,9 +1018,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface return $this->getTemplateId(); break; case 3: - return $this->getCreatedAt(); + return $this->getPosition(); break; case 4: + return $this->getCreatedAt(); + break; + case 5: return $this->getUpdatedAt(); break; default: @@ -1008,8 +1058,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getAttributeId(), $keys[2] => $this->getTemplateId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), + $keys[3] => $this->getPosition(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1068,9 +1119,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface $this->setTemplateId($value); break; case 3: - $this->setCreatedAt($value); + $this->setPosition($value); break; case 4: + $this->setCreatedAt($value); + break; + case 5: $this->setUpdatedAt($value); break; } // switch() @@ -1100,8 +1154,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setAttributeId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setTemplateId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + if (array_key_exists($keys[3], $arr)) $this->setPosition($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); } /** @@ -1116,6 +1171,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface if ($this->isColumnModified(AttributeTemplateTableMap::ID)) $criteria->add(AttributeTemplateTableMap::ID, $this->id); if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_ID)) $criteria->add(AttributeTemplateTableMap::ATTRIBUTE_ID, $this->attribute_id); if ($this->isColumnModified(AttributeTemplateTableMap::TEMPLATE_ID)) $criteria->add(AttributeTemplateTableMap::TEMPLATE_ID, $this->template_id); + if ($this->isColumnModified(AttributeTemplateTableMap::POSITION)) $criteria->add(AttributeTemplateTableMap::POSITION, $this->position); if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) $criteria->add(AttributeTemplateTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) $criteria->add(AttributeTemplateTableMap::UPDATED_AT, $this->updated_at); @@ -1183,6 +1239,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface { $copyObj->setAttributeId($this->getAttributeId()); $copyObj->setTemplateId($this->getTemplateId()); + $copyObj->setPosition($this->getPosition()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { @@ -1323,6 +1380,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface $this->id = null; $this->attribute_id = null; $this->template_id = null; + $this->position = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php b/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php index bd895360b..e1a8d0320 100644 --- a/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php +++ b/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php @@ -24,12 +24,14 @@ use Thelia\Model\Map\AttributeTemplateTableMap; * @method ChildAttributeTemplateQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildAttributeTemplateQuery orderByAttributeId($order = Criteria::ASC) Order by the attribute_id column * @method ChildAttributeTemplateQuery orderByTemplateId($order = Criteria::ASC) Order by the template_id column + * @method ChildAttributeTemplateQuery orderByPosition($order = Criteria::ASC) Order by the position column * @method ChildAttributeTemplateQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAttributeTemplateQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildAttributeTemplateQuery groupById() Group by the id column * @method ChildAttributeTemplateQuery groupByAttributeId() Group by the attribute_id column * @method ChildAttributeTemplateQuery groupByTemplateId() Group by the template_id column + * @method ChildAttributeTemplateQuery groupByPosition() Group by the position column * @method ChildAttributeTemplateQuery groupByCreatedAt() Group by the created_at column * @method ChildAttributeTemplateQuery groupByUpdatedAt() Group by the updated_at column * @@ -51,12 +53,14 @@ use Thelia\Model\Map\AttributeTemplateTableMap; * @method ChildAttributeTemplate findOneById(int $id) Return the first ChildAttributeTemplate filtered by the id column * @method ChildAttributeTemplate findOneByAttributeId(int $attribute_id) Return the first ChildAttributeTemplate filtered by the attribute_id column * @method ChildAttributeTemplate findOneByTemplateId(int $template_id) Return the first ChildAttributeTemplate filtered by the template_id column + * @method ChildAttributeTemplate findOneByPosition(int $position) Return the first ChildAttributeTemplate filtered by the position column * @method ChildAttributeTemplate findOneByCreatedAt(string $created_at) Return the first ChildAttributeTemplate filtered by the created_at column * @method ChildAttributeTemplate findOneByUpdatedAt(string $updated_at) Return the first ChildAttributeTemplate filtered by the updated_at column * * @method array findById(int $id) Return ChildAttributeTemplate objects filtered by the id column * @method array findByAttributeId(int $attribute_id) Return ChildAttributeTemplate objects filtered by the attribute_id column * @method array findByTemplateId(int $template_id) Return ChildAttributeTemplate objects filtered by the template_id column + * @method array findByPosition(int $position) Return ChildAttributeTemplate objects filtered by the position column * @method array findByCreatedAt(string $created_at) Return ChildAttributeTemplate objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAttributeTemplate objects filtered by the updated_at column * @@ -147,7 +151,7 @@ abstract class AttributeTemplateQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, ATTRIBUTE_ID, TEMPLATE_ID, CREATED_AT, UPDATED_AT FROM attribute_template WHERE ID = :p0'; + $sql = 'SELECT ID, ATTRIBUTE_ID, TEMPLATE_ID, POSITION, CREATED_AT, UPDATED_AT FROM attribute_template WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -363,6 +367,47 @@ abstract class AttributeTemplateQuery extends ModelCriteria return $this->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $templateId, $comparison); } + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(AttributeTemplateTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::POSITION, $position, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/Coupon.php b/core/lib/Thelia/Model/Base/Coupon.php index 4c5dcd917..81bc23d07 100644 --- a/core/lib/Thelia/Model/Base/Coupon.php +++ b/core/lib/Thelia/Model/Base/Coupon.php @@ -84,15 +84,9 @@ abstract class Coupon implements ActiveRecordInterface */ protected $amount; - /** - * The value for the is_used field. - * @var int - */ - protected $is_used; - /** * The value for the is_enabled field. - * @var int + * @var boolean */ protected $is_enabled; @@ -102,36 +96,42 @@ abstract class Coupon implements ActiveRecordInterface */ protected $expiration_date; - /** - * The value for the serialized_rules field. - * @var string - */ - protected $serialized_rules; - - /** - * The value for the is_cumulative field. - * @var int - */ - protected $is_cumulative; - - /** - * The value for the is_removing_postage field. - * @var int - */ - protected $is_removing_postage; - /** * The value for the max_usage field. * @var int */ protected $max_usage; + /** + * The value for the is_cumulative field. + * @var boolean + */ + protected $is_cumulative; + + /** + * The value for the is_removing_postage field. + * @var boolean + */ + protected $is_removing_postage; + /** * The value for the is_available_on_special_offers field. * @var boolean */ protected $is_available_on_special_offers; + /** + * The value for the is_used field. + * @var boolean + */ + protected $is_used; + + /** + * The value for the serialized_conditions field. + * @var string + */ + protected $serialized_conditions; + /** * The value for the created_at field. * @var string @@ -516,21 +516,10 @@ abstract class Coupon implements ActiveRecordInterface return $this->amount; } - /** - * Get the [is_used] column value. - * - * @return int - */ - public function getIsUsed() - { - - return $this->is_used; - } - /** * Get the [is_enabled] column value. * - * @return int + * @return boolean */ public function getIsEnabled() { @@ -558,39 +547,6 @@ abstract class Coupon implements ActiveRecordInterface } } - /** - * Get the [serialized_rules] column value. - * - * @return string - */ - public function getSerializedRules() - { - - return $this->serialized_rules; - } - - /** - * Get the [is_cumulative] column value. - * - * @return int - */ - public function getIsCumulative() - { - - return $this->is_cumulative; - } - - /** - * Get the [is_removing_postage] column value. - * - * @return int - */ - public function getIsRemovingPostage() - { - - return $this->is_removing_postage; - } - /** * Get the [max_usage] column value. * @@ -602,6 +558,28 @@ abstract class Coupon implements ActiveRecordInterface return $this->max_usage; } + /** + * Get the [is_cumulative] column value. + * + * @return boolean + */ + public function getIsCumulative() + { + + return $this->is_cumulative; + } + + /** + * Get the [is_removing_postage] column value. + * + * @return boolean + */ + public function getIsRemovingPostage() + { + + return $this->is_removing_postage; + } + /** * Get the [is_available_on_special_offers] column value. * @@ -613,6 +591,28 @@ abstract class Coupon implements ActiveRecordInterface return $this->is_available_on_special_offers; } + /** + * Get the [is_used] column value. + * + * @return boolean + */ + public function getIsUsed() + { + + return $this->is_used; + } + + /** + * Get the [serialized_conditions] column value. + * + * @return string + */ + public function getSerializedConditions() + { + + return $this->serialized_conditions; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -749,36 +749,23 @@ abstract class Coupon implements ActiveRecordInterface } // setAmount() /** - * Set the value of [is_used] column. + * Sets the value of the [is_enabled] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). * - * @param int $v new value - * @return \Thelia\Model\Coupon The current object (for fluent API support) - */ - public function setIsUsed($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_used !== $v) { - $this->is_used = $v; - $this->modifiedColumns[] = CouponTableMap::IS_USED; - } - - - return $this; - } // setIsUsed() - - /** - * Set the value of [is_enabled] column. - * - * @param int $v new value + * @param boolean|integer|string $v The new value * @return \Thelia\Model\Coupon The current object (for fluent API support) */ public function setIsEnabled($v) { if ($v !== null) { - $v = (int) $v; + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } } if ($this->is_enabled !== $v) { @@ -811,69 +798,6 @@ abstract class Coupon implements ActiveRecordInterface return $this; } // setExpirationDate() - /** - * Set the value of [serialized_rules] column. - * - * @param string $v new value - * @return \Thelia\Model\Coupon The current object (for fluent API support) - */ - public function setSerializedRules($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->serialized_rules !== $v) { - $this->serialized_rules = $v; - $this->modifiedColumns[] = CouponTableMap::SERIALIZED_RULES; - } - - - return $this; - } // setSerializedRules() - - /** - * Set the value of [is_cumulative] column. - * - * @param int $v new value - * @return \Thelia\Model\Coupon The current object (for fluent API support) - */ - public function setIsCumulative($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_cumulative !== $v) { - $this->is_cumulative = $v; - $this->modifiedColumns[] = CouponTableMap::IS_CUMULATIVE; - } - - - return $this; - } // setIsCumulative() - - /** - * Set the value of [is_removing_postage] column. - * - * @param int $v new value - * @return \Thelia\Model\Coupon The current object (for fluent API support) - */ - public function setIsRemovingPostage($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_removing_postage !== $v) { - $this->is_removing_postage = $v; - $this->modifiedColumns[] = CouponTableMap::IS_REMOVING_POSTAGE; - } - - - return $this; - } // setIsRemovingPostage() - /** * Set the value of [max_usage] column. * @@ -895,6 +819,64 @@ abstract class Coupon implements ActiveRecordInterface return $this; } // setMaxUsage() + /** + * Sets the value of the [is_cumulative] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function setIsCumulative($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_cumulative !== $v) { + $this->is_cumulative = $v; + $this->modifiedColumns[] = CouponTableMap::IS_CUMULATIVE; + } + + + return $this; + } // setIsCumulative() + + /** + * Sets the value of the [is_removing_postage] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function setIsRemovingPostage($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_removing_postage !== $v) { + $this->is_removing_postage = $v; + $this->modifiedColumns[] = CouponTableMap::IS_REMOVING_POSTAGE; + } + + + return $this; + } // setIsRemovingPostage() + /** * Sets the value of the [is_available_on_special_offers] column. * Non-boolean arguments are converted using the following rules: @@ -924,6 +906,56 @@ abstract class Coupon implements ActiveRecordInterface return $this; } // setIsAvailableOnSpecialOffers() + /** + * Sets the value of the [is_used] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function setIsUsed($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_used !== $v) { + $this->is_used = $v; + $this->modifiedColumns[] = CouponTableMap::IS_USED; + } + + + return $this; + } // setIsUsed() + + /** + * Set the value of [serialized_conditions] column. + * + * @param string $v new value + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function setSerializedConditions($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->serialized_conditions !== $v) { + $this->serialized_conditions = $v; + $this->modifiedColumns[] = CouponTableMap::SERIALIZED_CONDITIONS; + } + + + return $this; + } // setSerializedConditions() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -1040,33 +1072,33 @@ abstract class Coupon implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; $this->amount = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponTableMap::translateFieldName('IsUsed', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_used = (null !== $col) ? (int) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_enabled = (null !== $col) ? (boolean) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CouponTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_enabled = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CouponTableMap::translateFieldName('ExpirationDate', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CouponTableMap::translateFieldName('ExpirationDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->expiration_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CouponTableMap::translateFieldName('SerializedRules', TableMap::TYPE_PHPNAME, $indexType)]; - $this->serialized_rules = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CouponTableMap::translateFieldName('IsCumulative', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_cumulative = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CouponTableMap::translateFieldName('IsRemovingPostage', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_removing_postage = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CouponTableMap::translateFieldName('MaxUsage', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CouponTableMap::translateFieldName('MaxUsage', TableMap::TYPE_PHPNAME, $indexType)]; $this->max_usage = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponTableMap::translateFieldName('IsAvailableOnSpecialOffers', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CouponTableMap::translateFieldName('IsCumulative', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_cumulative = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CouponTableMap::translateFieldName('IsRemovingPostage', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_removing_postage = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CouponTableMap::translateFieldName('IsAvailableOnSpecialOffers', TableMap::TYPE_PHPNAME, $indexType)]; $this->is_available_on_special_offers = (null !== $col) ? (boolean) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CouponTableMap::translateFieldName('IsUsed', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_used = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponTableMap::translateFieldName('SerializedConditions', TableMap::TYPE_PHPNAME, $indexType)]; + $this->serialized_conditions = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; @@ -1368,17 +1400,14 @@ abstract class Coupon implements ActiveRecordInterface if ($this->isColumnModified(CouponTableMap::AMOUNT)) { $modifiedColumns[':p' . $index++] = 'AMOUNT'; } - if ($this->isColumnModified(CouponTableMap::IS_USED)) { - $modifiedColumns[':p' . $index++] = 'IS_USED'; - } if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) { $modifiedColumns[':p' . $index++] = 'IS_ENABLED'; } if ($this->isColumnModified(CouponTableMap::EXPIRATION_DATE)) { $modifiedColumns[':p' . $index++] = 'EXPIRATION_DATE'; } - if ($this->isColumnModified(CouponTableMap::SERIALIZED_RULES)) { - $modifiedColumns[':p' . $index++] = 'SERIALIZED_RULES'; + if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) { + $modifiedColumns[':p' . $index++] = 'MAX_USAGE'; } if ($this->isColumnModified(CouponTableMap::IS_CUMULATIVE)) { $modifiedColumns[':p' . $index++] = 'IS_CUMULATIVE'; @@ -1386,12 +1415,15 @@ abstract class Coupon implements ActiveRecordInterface if ($this->isColumnModified(CouponTableMap::IS_REMOVING_POSTAGE)) { $modifiedColumns[':p' . $index++] = 'IS_REMOVING_POSTAGE'; } - if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) { - $modifiedColumns[':p' . $index++] = 'MAX_USAGE'; - } if ($this->isColumnModified(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) { $modifiedColumns[':p' . $index++] = 'IS_AVAILABLE_ON_SPECIAL_OFFERS'; } + if ($this->isColumnModified(CouponTableMap::IS_USED)) { + $modifiedColumns[':p' . $index++] = 'IS_USED'; + } + if ($this->isColumnModified(CouponTableMap::SERIALIZED_CONDITIONS)) { + $modifiedColumns[':p' . $index++] = 'SERIALIZED_CONDITIONS'; + } if ($this->isColumnModified(CouponTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1424,30 +1456,30 @@ abstract class Coupon implements ActiveRecordInterface case 'AMOUNT': $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); break; - case 'IS_USED': - $stmt->bindValue($identifier, $this->is_used, PDO::PARAM_INT); - break; case 'IS_ENABLED': - $stmt->bindValue($identifier, $this->is_enabled, PDO::PARAM_INT); + $stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT); break; case 'EXPIRATION_DATE': $stmt->bindValue($identifier, $this->expiration_date ? $this->expiration_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; - case 'SERIALIZED_RULES': - $stmt->bindValue($identifier, $this->serialized_rules, PDO::PARAM_STR); - break; - case 'IS_CUMULATIVE': - $stmt->bindValue($identifier, $this->is_cumulative, PDO::PARAM_INT); - break; - case 'IS_REMOVING_POSTAGE': - $stmt->bindValue($identifier, $this->is_removing_postage, PDO::PARAM_INT); - break; case 'MAX_USAGE': $stmt->bindValue($identifier, $this->max_usage, PDO::PARAM_INT); break; + case 'IS_CUMULATIVE': + $stmt->bindValue($identifier, (int) $this->is_cumulative, PDO::PARAM_INT); + break; + case 'IS_REMOVING_POSTAGE': + $stmt->bindValue($identifier, (int) $this->is_removing_postage, PDO::PARAM_INT); + break; case 'IS_AVAILABLE_ON_SPECIAL_OFFERS': $stmt->bindValue($identifier, (int) $this->is_available_on_special_offers, PDO::PARAM_INT); break; + case 'IS_USED': + $stmt->bindValue($identifier, (int) $this->is_used, PDO::PARAM_INT); + break; + case 'SERIALIZED_CONDITIONS': + $stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1532,29 +1564,29 @@ abstract class Coupon implements ActiveRecordInterface return $this->getAmount(); break; case 4: - return $this->getIsUsed(); - break; - case 5: return $this->getIsEnabled(); break; - case 6: + case 5: return $this->getExpirationDate(); break; - case 7: - return $this->getSerializedRules(); - break; - case 8: - return $this->getIsCumulative(); - break; - case 9: - return $this->getIsRemovingPostage(); - break; - case 10: + case 6: return $this->getMaxUsage(); break; - case 11: + case 7: + return $this->getIsCumulative(); + break; + case 8: + return $this->getIsRemovingPostage(); + break; + case 9: return $this->getIsAvailableOnSpecialOffers(); break; + case 10: + return $this->getIsUsed(); + break; + case 11: + return $this->getSerializedConditions(); + break; case 12: return $this->getCreatedAt(); break; @@ -1597,14 +1629,14 @@ abstract class Coupon implements ActiveRecordInterface $keys[1] => $this->getCode(), $keys[2] => $this->getType(), $keys[3] => $this->getAmount(), - $keys[4] => $this->getIsUsed(), - $keys[5] => $this->getIsEnabled(), - $keys[6] => $this->getExpirationDate(), - $keys[7] => $this->getSerializedRules(), - $keys[8] => $this->getIsCumulative(), - $keys[9] => $this->getIsRemovingPostage(), - $keys[10] => $this->getMaxUsage(), - $keys[11] => $this->getIsAvailableOnSpecialOffers(), + $keys[4] => $this->getIsEnabled(), + $keys[5] => $this->getExpirationDate(), + $keys[6] => $this->getMaxUsage(), + $keys[7] => $this->getIsCumulative(), + $keys[8] => $this->getIsRemovingPostage(), + $keys[9] => $this->getIsAvailableOnSpecialOffers(), + $keys[10] => $this->getIsUsed(), + $keys[11] => $this->getSerializedConditions(), $keys[12] => $this->getCreatedAt(), $keys[13] => $this->getUpdatedAt(), $keys[14] => $this->getVersion(), @@ -1669,29 +1701,29 @@ abstract class Coupon implements ActiveRecordInterface $this->setAmount($value); break; case 4: - $this->setIsUsed($value); - break; - case 5: $this->setIsEnabled($value); break; - case 6: + case 5: $this->setExpirationDate($value); break; - case 7: - $this->setSerializedRules($value); - break; - case 8: - $this->setIsCumulative($value); - break; - case 9: - $this->setIsRemovingPostage($value); - break; - case 10: + case 6: $this->setMaxUsage($value); break; - case 11: + case 7: + $this->setIsCumulative($value); + break; + case 8: + $this->setIsRemovingPostage($value); + break; + case 9: $this->setIsAvailableOnSpecialOffers($value); break; + case 10: + $this->setIsUsed($value); + break; + case 11: + $this->setSerializedConditions($value); + break; case 12: $this->setCreatedAt($value); break; @@ -1729,14 +1761,14 @@ abstract class Coupon implements ActiveRecordInterface if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setIsUsed($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setIsEnabled($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setExpirationDate($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setSerializedRules($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setIsCumulative($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setIsRemovingPostage($arr[$keys[9]]); - if (array_key_exists($keys[10], $arr)) $this->setMaxUsage($arr[$keys[10]]); - if (array_key_exists($keys[11], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[11]]); + if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setIsCumulative($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setIsRemovingPostage($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setIsUsed($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setSerializedConditions($arr[$keys[11]]); if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]); if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]); if (array_key_exists($keys[14], $arr)) $this->setVersion($arr[$keys[14]]); @@ -1755,14 +1787,14 @@ abstract class Coupon implements ActiveRecordInterface if ($this->isColumnModified(CouponTableMap::CODE)) $criteria->add(CouponTableMap::CODE, $this->code); if ($this->isColumnModified(CouponTableMap::TYPE)) $criteria->add(CouponTableMap::TYPE, $this->type); if ($this->isColumnModified(CouponTableMap::AMOUNT)) $criteria->add(CouponTableMap::AMOUNT, $this->amount); - if ($this->isColumnModified(CouponTableMap::IS_USED)) $criteria->add(CouponTableMap::IS_USED, $this->is_used); if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) $criteria->add(CouponTableMap::IS_ENABLED, $this->is_enabled); if ($this->isColumnModified(CouponTableMap::EXPIRATION_DATE)) $criteria->add(CouponTableMap::EXPIRATION_DATE, $this->expiration_date); - if ($this->isColumnModified(CouponTableMap::SERIALIZED_RULES)) $criteria->add(CouponTableMap::SERIALIZED_RULES, $this->serialized_rules); + if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) $criteria->add(CouponTableMap::MAX_USAGE, $this->max_usage); if ($this->isColumnModified(CouponTableMap::IS_CUMULATIVE)) $criteria->add(CouponTableMap::IS_CUMULATIVE, $this->is_cumulative); if ($this->isColumnModified(CouponTableMap::IS_REMOVING_POSTAGE)) $criteria->add(CouponTableMap::IS_REMOVING_POSTAGE, $this->is_removing_postage); - if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) $criteria->add(CouponTableMap::MAX_USAGE, $this->max_usage); if ($this->isColumnModified(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) $criteria->add(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $this->is_available_on_special_offers); + if ($this->isColumnModified(CouponTableMap::IS_USED)) $criteria->add(CouponTableMap::IS_USED, $this->is_used); + if ($this->isColumnModified(CouponTableMap::SERIALIZED_CONDITIONS)) $criteria->add(CouponTableMap::SERIALIZED_CONDITIONS, $this->serialized_conditions); if ($this->isColumnModified(CouponTableMap::CREATED_AT)) $criteria->add(CouponTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(CouponTableMap::UPDATED_AT)) $criteria->add(CouponTableMap::UPDATED_AT, $this->updated_at); if ($this->isColumnModified(CouponTableMap::VERSION)) $criteria->add(CouponTableMap::VERSION, $this->version); @@ -1832,14 +1864,14 @@ abstract class Coupon implements ActiveRecordInterface $copyObj->setCode($this->getCode()); $copyObj->setType($this->getType()); $copyObj->setAmount($this->getAmount()); - $copyObj->setIsUsed($this->getIsUsed()); $copyObj->setIsEnabled($this->getIsEnabled()); $copyObj->setExpirationDate($this->getExpirationDate()); - $copyObj->setSerializedRules($this->getSerializedRules()); + $copyObj->setMaxUsage($this->getMaxUsage()); $copyObj->setIsCumulative($this->getIsCumulative()); $copyObj->setIsRemovingPostage($this->getIsRemovingPostage()); - $copyObj->setMaxUsage($this->getMaxUsage()); $copyObj->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers()); + $copyObj->setIsUsed($this->getIsUsed()); + $copyObj->setSerializedConditions($this->getSerializedConditions()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); $copyObj->setVersion($this->getVersion()); @@ -2365,14 +2397,14 @@ abstract class Coupon implements ActiveRecordInterface $this->code = null; $this->type = null; $this->amount = null; - $this->is_used = null; $this->is_enabled = null; $this->expiration_date = null; - $this->serialized_rules = null; + $this->max_usage = null; $this->is_cumulative = null; $this->is_removing_postage = null; - $this->max_usage = null; $this->is_available_on_special_offers = null; + $this->is_used = null; + $this->serialized_conditions = null; $this->created_at = null; $this->updated_at = null; $this->version = null; @@ -2669,14 +2701,14 @@ abstract class Coupon implements ActiveRecordInterface $version->setCode($this->getCode()); $version->setType($this->getType()); $version->setAmount($this->getAmount()); - $version->setIsUsed($this->getIsUsed()); $version->setIsEnabled($this->getIsEnabled()); $version->setExpirationDate($this->getExpirationDate()); - $version->setSerializedRules($this->getSerializedRules()); + $version->setMaxUsage($this->getMaxUsage()); $version->setIsCumulative($this->getIsCumulative()); $version->setIsRemovingPostage($this->getIsRemovingPostage()); - $version->setMaxUsage($this->getMaxUsage()); $version->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers()); + $version->setIsUsed($this->getIsUsed()); + $version->setSerializedConditions($this->getSerializedConditions()); $version->setCreatedAt($this->getCreatedAt()); $version->setUpdatedAt($this->getUpdatedAt()); $version->setVersion($this->getVersion()); @@ -2721,14 +2753,14 @@ abstract class Coupon implements ActiveRecordInterface $this->setCode($version->getCode()); $this->setType($version->getType()); $this->setAmount($version->getAmount()); - $this->setIsUsed($version->getIsUsed()); $this->setIsEnabled($version->getIsEnabled()); $this->setExpirationDate($version->getExpirationDate()); - $this->setSerializedRules($version->getSerializedRules()); + $this->setMaxUsage($version->getMaxUsage()); $this->setIsCumulative($version->getIsCumulative()); $this->setIsRemovingPostage($version->getIsRemovingPostage()); - $this->setMaxUsage($version->getMaxUsage()); $this->setIsAvailableOnSpecialOffers($version->getIsAvailableOnSpecialOffers()); + $this->setIsUsed($version->getIsUsed()); + $this->setSerializedConditions($version->getSerializedConditions()); $this->setCreatedAt($version->getCreatedAt()); $this->setUpdatedAt($version->getUpdatedAt()); $this->setVersion($version->getVersion()); diff --git a/core/lib/Thelia/Model/Base/CouponQuery.php b/core/lib/Thelia/Model/Base/CouponQuery.php index e92380879..d480f06c4 100644 --- a/core/lib/Thelia/Model/Base/CouponQuery.php +++ b/core/lib/Thelia/Model/Base/CouponQuery.php @@ -26,14 +26,14 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCouponQuery orderByCode($order = Criteria::ASC) Order by the code column * @method ChildCouponQuery orderByType($order = Criteria::ASC) Order by the type column * @method ChildCouponQuery orderByAmount($order = Criteria::ASC) Order by the amount column - * @method ChildCouponQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column * @method ChildCouponQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column * @method ChildCouponQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column - * @method ChildCouponQuery orderBySerializedRules($order = Criteria::ASC) Order by the serialized_rules column + * @method ChildCouponQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column * @method ChildCouponQuery orderByIsCumulative($order = Criteria::ASC) Order by the is_cumulative column * @method ChildCouponQuery orderByIsRemovingPostage($order = Criteria::ASC) Order by the is_removing_postage column - * @method ChildCouponQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column * @method ChildCouponQuery orderByIsAvailableOnSpecialOffers($order = Criteria::ASC) Order by the is_available_on_special_offers column + * @method ChildCouponQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column + * @method ChildCouponQuery orderBySerializedConditions($order = Criteria::ASC) Order by the serialized_conditions column * @method ChildCouponQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildCouponQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @method ChildCouponQuery orderByVersion($order = Criteria::ASC) Order by the version column @@ -42,14 +42,14 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCouponQuery groupByCode() Group by the code column * @method ChildCouponQuery groupByType() Group by the type column * @method ChildCouponQuery groupByAmount() Group by the amount column - * @method ChildCouponQuery groupByIsUsed() Group by the is_used column * @method ChildCouponQuery groupByIsEnabled() Group by the is_enabled column * @method ChildCouponQuery groupByExpirationDate() Group by the expiration_date column - * @method ChildCouponQuery groupBySerializedRules() Group by the serialized_rules column + * @method ChildCouponQuery groupByMaxUsage() Group by the max_usage column * @method ChildCouponQuery groupByIsCumulative() Group by the is_cumulative column * @method ChildCouponQuery groupByIsRemovingPostage() Group by the is_removing_postage column - * @method ChildCouponQuery groupByMaxUsage() Group by the max_usage column * @method ChildCouponQuery groupByIsAvailableOnSpecialOffers() Group by the is_available_on_special_offers column + * @method ChildCouponQuery groupByIsUsed() Group by the is_used column + * @method ChildCouponQuery groupBySerializedConditions() Group by the serialized_conditions column * @method ChildCouponQuery groupByCreatedAt() Group by the created_at column * @method ChildCouponQuery groupByUpdatedAt() Group by the updated_at column * @method ChildCouponQuery groupByVersion() Group by the version column @@ -73,14 +73,14 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCoupon findOneByCode(string $code) Return the first ChildCoupon filtered by the code column * @method ChildCoupon findOneByType(string $type) Return the first ChildCoupon filtered by the type column * @method ChildCoupon findOneByAmount(double $amount) Return the first ChildCoupon filtered by the amount column - * @method ChildCoupon findOneByIsUsed(int $is_used) Return the first ChildCoupon filtered by the is_used column - * @method ChildCoupon findOneByIsEnabled(int $is_enabled) Return the first ChildCoupon filtered by the is_enabled column + * @method ChildCoupon findOneByIsEnabled(boolean $is_enabled) Return the first ChildCoupon filtered by the is_enabled column * @method ChildCoupon findOneByExpirationDate(string $expiration_date) Return the first ChildCoupon filtered by the expiration_date column - * @method ChildCoupon findOneBySerializedRules(string $serialized_rules) Return the first ChildCoupon filtered by the serialized_rules column - * @method ChildCoupon findOneByIsCumulative(int $is_cumulative) Return the first ChildCoupon filtered by the is_cumulative column - * @method ChildCoupon findOneByIsRemovingPostage(int $is_removing_postage) Return the first ChildCoupon filtered by the is_removing_postage column * @method ChildCoupon findOneByMaxUsage(int $max_usage) Return the first ChildCoupon filtered by the max_usage column + * @method ChildCoupon findOneByIsCumulative(boolean $is_cumulative) Return the first ChildCoupon filtered by the is_cumulative column + * @method ChildCoupon findOneByIsRemovingPostage(boolean $is_removing_postage) Return the first ChildCoupon filtered by the is_removing_postage column * @method ChildCoupon findOneByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return the first ChildCoupon filtered by the is_available_on_special_offers column + * @method ChildCoupon findOneByIsUsed(boolean $is_used) Return the first ChildCoupon filtered by the is_used column + * @method ChildCoupon findOneBySerializedConditions(string $serialized_conditions) Return the first ChildCoupon filtered by the serialized_conditions column * @method ChildCoupon findOneByCreatedAt(string $created_at) Return the first ChildCoupon filtered by the created_at column * @method ChildCoupon findOneByUpdatedAt(string $updated_at) Return the first ChildCoupon filtered by the updated_at column * @method ChildCoupon findOneByVersion(int $version) Return the first ChildCoupon filtered by the version column @@ -89,14 +89,14 @@ use Thelia\Model\Map\CouponTableMap; * @method array findByCode(string $code) Return ChildCoupon objects filtered by the code column * @method array findByType(string $type) Return ChildCoupon objects filtered by the type column * @method array findByAmount(double $amount) Return ChildCoupon objects filtered by the amount column - * @method array findByIsUsed(int $is_used) Return ChildCoupon objects filtered by the is_used column - * @method array findByIsEnabled(int $is_enabled) Return ChildCoupon objects filtered by the is_enabled column + * @method array findByIsEnabled(boolean $is_enabled) Return ChildCoupon objects filtered by the is_enabled column * @method array findByExpirationDate(string $expiration_date) Return ChildCoupon objects filtered by the expiration_date column - * @method array findBySerializedRules(string $serialized_rules) Return ChildCoupon objects filtered by the serialized_rules column - * @method array findByIsCumulative(int $is_cumulative) Return ChildCoupon objects filtered by the is_cumulative column - * @method array findByIsRemovingPostage(int $is_removing_postage) Return ChildCoupon objects filtered by the is_removing_postage column * @method array findByMaxUsage(int $max_usage) Return ChildCoupon objects filtered by the max_usage column + * @method array findByIsCumulative(boolean $is_cumulative) Return ChildCoupon objects filtered by the is_cumulative column + * @method array findByIsRemovingPostage(boolean $is_removing_postage) Return ChildCoupon objects filtered by the is_removing_postage column * @method array findByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return ChildCoupon objects filtered by the is_available_on_special_offers column + * @method array findByIsUsed(boolean $is_used) Return ChildCoupon objects filtered by the is_used column + * @method array findBySerializedConditions(string $serialized_conditions) Return ChildCoupon objects filtered by the serialized_conditions column * @method array findByCreatedAt(string $created_at) Return ChildCoupon objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildCoupon objects filtered by the updated_at column * @method array findByVersion(int $version) Return ChildCoupon objects filtered by the version column @@ -195,7 +195,7 @@ abstract class CouponQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_USED, IS_ENABLED, EXPIRATION_DATE, SERIALIZED_RULES, IS_CUMULATIVE, IS_REMOVING_POSTAGE, MAX_USAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0'; + $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -424,83 +424,28 @@ abstract class CouponQuery extends ModelCriteria return $this->addUsingAlias(CouponTableMap::AMOUNT, $amount, $comparison); } - /** - * Filter the query on the is_used column - * - * Example usage: - * - * $query->filterByIsUsed(1234); // WHERE is_used = 1234 - * $query->filterByIsUsed(array(12, 34)); // WHERE is_used IN (12, 34) - * $query->filterByIsUsed(array('min' => 12)); // WHERE is_used > 12 - * - * - * @param mixed $isUsed The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponQuery The current query, for fluid interface - */ - public function filterByIsUsed($isUsed = null, $comparison = null) - { - if (is_array($isUsed)) { - $useMinMax = false; - if (isset($isUsed['min'])) { - $this->addUsingAlias(CouponTableMap::IS_USED, $isUsed['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isUsed['max'])) { - $this->addUsingAlias(CouponTableMap::IS_USED, $isUsed['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponTableMap::IS_USED, $isUsed, $comparison); - } - /** * Filter the query on the is_enabled column * * Example usage: * - * $query->filterByIsEnabled(1234); // WHERE is_enabled = 1234 - * $query->filterByIsEnabled(array(12, 34)); // WHERE is_enabled IN (12, 34) - * $query->filterByIsEnabled(array('min' => 12)); // WHERE is_enabled > 12 + * $query->filterByIsEnabled(true); // WHERE is_enabled = true + * $query->filterByIsEnabled('yes'); // WHERE is_enabled = true * * - * @param mixed $isEnabled The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param boolean|string $isEnabled The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCouponQuery The current query, for fluid interface */ public function filterByIsEnabled($isEnabled = null, $comparison = null) { - if (is_array($isEnabled)) { - $useMinMax = false; - if (isset($isEnabled['min'])) { - $this->addUsingAlias(CouponTableMap::IS_ENABLED, $isEnabled['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isEnabled['max'])) { - $this->addUsingAlias(CouponTableMap::IS_ENABLED, $isEnabled['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } + if (is_string($isEnabled)) { + $is_enabled = in_array(strtolower($isEnabled), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; } return $this->addUsingAlias(CouponTableMap::IS_ENABLED, $isEnabled, $comparison); @@ -549,117 +494,6 @@ abstract class CouponQuery extends ModelCriteria return $this->addUsingAlias(CouponTableMap::EXPIRATION_DATE, $expirationDate, $comparison); } - /** - * Filter the query on the serialized_rules column - * - * Example usage: - * - * $query->filterBySerializedRules('fooValue'); // WHERE serialized_rules = 'fooValue' - * $query->filterBySerializedRules('%fooValue%'); // WHERE serialized_rules LIKE '%fooValue%' - * - * - * @param string $serializedRules The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponQuery The current query, for fluid interface - */ - public function filterBySerializedRules($serializedRules = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($serializedRules)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $serializedRules)) { - $serializedRules = str_replace('*', '%', $serializedRules); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CouponTableMap::SERIALIZED_RULES, $serializedRules, $comparison); - } - - /** - * Filter the query on the is_cumulative column - * - * Example usage: - * - * $query->filterByIsCumulative(1234); // WHERE is_cumulative = 1234 - * $query->filterByIsCumulative(array(12, 34)); // WHERE is_cumulative IN (12, 34) - * $query->filterByIsCumulative(array('min' => 12)); // WHERE is_cumulative > 12 - * - * - * @param mixed $isCumulative The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponQuery The current query, for fluid interface - */ - public function filterByIsCumulative($isCumulative = null, $comparison = null) - { - if (is_array($isCumulative)) { - $useMinMax = false; - if (isset($isCumulative['min'])) { - $this->addUsingAlias(CouponTableMap::IS_CUMULATIVE, $isCumulative['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isCumulative['max'])) { - $this->addUsingAlias(CouponTableMap::IS_CUMULATIVE, $isCumulative['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponTableMap::IS_CUMULATIVE, $isCumulative, $comparison); - } - - /** - * Filter the query on the is_removing_postage column - * - * Example usage: - * - * $query->filterByIsRemovingPostage(1234); // WHERE is_removing_postage = 1234 - * $query->filterByIsRemovingPostage(array(12, 34)); // WHERE is_removing_postage IN (12, 34) - * $query->filterByIsRemovingPostage(array('min' => 12)); // WHERE is_removing_postage > 12 - * - * - * @param mixed $isRemovingPostage The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponQuery The current query, for fluid interface - */ - public function filterByIsRemovingPostage($isRemovingPostage = null, $comparison = null) - { - if (is_array($isRemovingPostage)) { - $useMinMax = false; - if (isset($isRemovingPostage['min'])) { - $this->addUsingAlias(CouponTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isRemovingPostage['max'])) { - $this->addUsingAlias(CouponTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage, $comparison); - } - /** * Filter the query on the max_usage column * @@ -701,6 +535,60 @@ abstract class CouponQuery extends ModelCriteria return $this->addUsingAlias(CouponTableMap::MAX_USAGE, $maxUsage, $comparison); } + /** + * Filter the query on the is_cumulative column + * + * Example usage: + * + * $query->filterByIsCumulative(true); // WHERE is_cumulative = true + * $query->filterByIsCumulative('yes'); // WHERE is_cumulative = true + * + * + * @param boolean|string $isCumulative The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByIsCumulative($isCumulative = null, $comparison = null) + { + if (is_string($isCumulative)) { + $is_cumulative = in_array(strtolower($isCumulative), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponTableMap::IS_CUMULATIVE, $isCumulative, $comparison); + } + + /** + * Filter the query on the is_removing_postage column + * + * Example usage: + * + * $query->filterByIsRemovingPostage(true); // WHERE is_removing_postage = true + * $query->filterByIsRemovingPostage('yes'); // WHERE is_removing_postage = true + * + * + * @param boolean|string $isRemovingPostage The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByIsRemovingPostage($isRemovingPostage = null, $comparison = null) + { + if (is_string($isRemovingPostage)) { + $is_removing_postage = in_array(strtolower($isRemovingPostage), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage, $comparison); + } + /** * Filter the query on the is_available_on_special_offers column * @@ -728,6 +616,62 @@ abstract class CouponQuery extends ModelCriteria return $this->addUsingAlias(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $isAvailableOnSpecialOffers, $comparison); } + /** + * Filter the query on the is_used column + * + * Example usage: + * + * $query->filterByIsUsed(true); // WHERE is_used = true + * $query->filterByIsUsed('yes'); // WHERE is_used = true + * + * + * @param boolean|string $isUsed The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByIsUsed($isUsed = null, $comparison = null) + { + if (is_string($isUsed)) { + $is_used = in_array(strtolower($isUsed), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponTableMap::IS_USED, $isUsed, $comparison); + } + + /** + * Filter the query on the serialized_conditions column + * + * Example usage: + * + * $query->filterBySerializedConditions('fooValue'); // WHERE serialized_conditions = 'fooValue' + * $query->filterBySerializedConditions('%fooValue%'); // WHERE serialized_conditions LIKE '%fooValue%' + * + * + * @param string $serializedConditions The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterBySerializedConditions($serializedConditions = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($serializedConditions)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $serializedConditions)) { + $serializedConditions = str_replace('*', '%', $serializedConditions); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(CouponTableMap::SERIALIZED_CONDITIONS, $serializedConditions, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/CouponVersion.php b/core/lib/Thelia/Model/Base/CouponVersion.php index efa4898f4..83e5bf6dc 100644 --- a/core/lib/Thelia/Model/Base/CouponVersion.php +++ b/core/lib/Thelia/Model/Base/CouponVersion.php @@ -79,15 +79,9 @@ abstract class CouponVersion implements ActiveRecordInterface */ protected $amount; - /** - * The value for the is_used field. - * @var int - */ - protected $is_used; - /** * The value for the is_enabled field. - * @var int + * @var boolean */ protected $is_enabled; @@ -97,36 +91,42 @@ abstract class CouponVersion implements ActiveRecordInterface */ protected $expiration_date; - /** - * The value for the serialized_rules field. - * @var string - */ - protected $serialized_rules; - - /** - * The value for the is_cumulative field. - * @var int - */ - protected $is_cumulative; - - /** - * The value for the is_removing_postage field. - * @var int - */ - protected $is_removing_postage; - /** * The value for the max_usage field. * @var int */ protected $max_usage; + /** + * The value for the is_cumulative field. + * @var boolean + */ + protected $is_cumulative; + + /** + * The value for the is_removing_postage field. + * @var boolean + */ + protected $is_removing_postage; + /** * The value for the is_available_on_special_offers field. * @var boolean */ protected $is_available_on_special_offers; + /** + * The value for the is_used field. + * @var boolean + */ + protected $is_used; + + /** + * The value for the serialized_conditions field. + * @var string + */ + protected $serialized_conditions; + /** * The value for the created_at field. * @var string @@ -470,21 +470,10 @@ abstract class CouponVersion implements ActiveRecordInterface return $this->amount; } - /** - * Get the [is_used] column value. - * - * @return int - */ - public function getIsUsed() - { - - return $this->is_used; - } - /** * Get the [is_enabled] column value. * - * @return int + * @return boolean */ public function getIsEnabled() { @@ -512,39 +501,6 @@ abstract class CouponVersion implements ActiveRecordInterface } } - /** - * Get the [serialized_rules] column value. - * - * @return string - */ - public function getSerializedRules() - { - - return $this->serialized_rules; - } - - /** - * Get the [is_cumulative] column value. - * - * @return int - */ - public function getIsCumulative() - { - - return $this->is_cumulative; - } - - /** - * Get the [is_removing_postage] column value. - * - * @return int - */ - public function getIsRemovingPostage() - { - - return $this->is_removing_postage; - } - /** * Get the [max_usage] column value. * @@ -556,6 +512,28 @@ abstract class CouponVersion implements ActiveRecordInterface return $this->max_usage; } + /** + * Get the [is_cumulative] column value. + * + * @return boolean + */ + public function getIsCumulative() + { + + return $this->is_cumulative; + } + + /** + * Get the [is_removing_postage] column value. + * + * @return boolean + */ + public function getIsRemovingPostage() + { + + return $this->is_removing_postage; + } + /** * Get the [is_available_on_special_offers] column value. * @@ -567,6 +545,28 @@ abstract class CouponVersion implements ActiveRecordInterface return $this->is_available_on_special_offers; } + /** + * Get the [is_used] column value. + * + * @return boolean + */ + public function getIsUsed() + { + + return $this->is_used; + } + + /** + * Get the [serialized_conditions] column value. + * + * @return string + */ + public function getSerializedConditions() + { + + return $this->serialized_conditions; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -707,36 +707,23 @@ abstract class CouponVersion implements ActiveRecordInterface } // setAmount() /** - * Set the value of [is_used] column. + * Sets the value of the [is_enabled] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). * - * @param int $v new value - * @return \Thelia\Model\CouponVersion The current object (for fluent API support) - */ - public function setIsUsed($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_used !== $v) { - $this->is_used = $v; - $this->modifiedColumns[] = CouponVersionTableMap::IS_USED; - } - - - return $this; - } // setIsUsed() - - /** - * Set the value of [is_enabled] column. - * - * @param int $v new value + * @param boolean|integer|string $v The new value * @return \Thelia\Model\CouponVersion The current object (for fluent API support) */ public function setIsEnabled($v) { if ($v !== null) { - $v = (int) $v; + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } } if ($this->is_enabled !== $v) { @@ -769,69 +756,6 @@ abstract class CouponVersion implements ActiveRecordInterface return $this; } // setExpirationDate() - /** - * Set the value of [serialized_rules] column. - * - * @param string $v new value - * @return \Thelia\Model\CouponVersion The current object (for fluent API support) - */ - public function setSerializedRules($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->serialized_rules !== $v) { - $this->serialized_rules = $v; - $this->modifiedColumns[] = CouponVersionTableMap::SERIALIZED_RULES; - } - - - return $this; - } // setSerializedRules() - - /** - * Set the value of [is_cumulative] column. - * - * @param int $v new value - * @return \Thelia\Model\CouponVersion The current object (for fluent API support) - */ - public function setIsCumulative($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_cumulative !== $v) { - $this->is_cumulative = $v; - $this->modifiedColumns[] = CouponVersionTableMap::IS_CUMULATIVE; - } - - - return $this; - } // setIsCumulative() - - /** - * Set the value of [is_removing_postage] column. - * - * @param int $v new value - * @return \Thelia\Model\CouponVersion The current object (for fluent API support) - */ - public function setIsRemovingPostage($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->is_removing_postage !== $v) { - $this->is_removing_postage = $v; - $this->modifiedColumns[] = CouponVersionTableMap::IS_REMOVING_POSTAGE; - } - - - return $this; - } // setIsRemovingPostage() - /** * Set the value of [max_usage] column. * @@ -853,6 +777,64 @@ abstract class CouponVersion implements ActiveRecordInterface return $this; } // setMaxUsage() + /** + * Sets the value of the [is_cumulative] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\CouponVersion The current object (for fluent API support) + */ + public function setIsCumulative($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_cumulative !== $v) { + $this->is_cumulative = $v; + $this->modifiedColumns[] = CouponVersionTableMap::IS_CUMULATIVE; + } + + + return $this; + } // setIsCumulative() + + /** + * Sets the value of the [is_removing_postage] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\CouponVersion The current object (for fluent API support) + */ + public function setIsRemovingPostage($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_removing_postage !== $v) { + $this->is_removing_postage = $v; + $this->modifiedColumns[] = CouponVersionTableMap::IS_REMOVING_POSTAGE; + } + + + return $this; + } // setIsRemovingPostage() + /** * Sets the value of the [is_available_on_special_offers] column. * Non-boolean arguments are converted using the following rules: @@ -882,6 +864,56 @@ abstract class CouponVersion implements ActiveRecordInterface return $this; } // setIsAvailableOnSpecialOffers() + /** + * Sets the value of the [is_used] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\CouponVersion The current object (for fluent API support) + */ + public function setIsUsed($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_used !== $v) { + $this->is_used = $v; + $this->modifiedColumns[] = CouponVersionTableMap::IS_USED; + } + + + return $this; + } // setIsUsed() + + /** + * Set the value of [serialized_conditions] column. + * + * @param string $v new value + * @return \Thelia\Model\CouponVersion The current object (for fluent API support) + */ + public function setSerializedConditions($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->serialized_conditions !== $v) { + $this->serialized_conditions = $v; + $this->modifiedColumns[] = CouponVersionTableMap::SERIALIZED_CONDITIONS; + } + + + return $this; + } // setSerializedConditions() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -998,33 +1030,33 @@ abstract class CouponVersion implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponVersionTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; $this->amount = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponVersionTableMap::translateFieldName('IsUsed', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_used = (null !== $col) ? (int) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponVersionTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_enabled = (null !== $col) ? (boolean) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CouponVersionTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_enabled = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CouponVersionTableMap::translateFieldName('ExpirationDate', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CouponVersionTableMap::translateFieldName('ExpirationDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->expiration_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CouponVersionTableMap::translateFieldName('SerializedRules', TableMap::TYPE_PHPNAME, $indexType)]; - $this->serialized_rules = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CouponVersionTableMap::translateFieldName('IsCumulative', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_cumulative = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CouponVersionTableMap::translateFieldName('IsRemovingPostage', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_removing_postage = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CouponVersionTableMap::translateFieldName('MaxUsage', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CouponVersionTableMap::translateFieldName('MaxUsage', TableMap::TYPE_PHPNAME, $indexType)]; $this->max_usage = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponVersionTableMap::translateFieldName('IsAvailableOnSpecialOffers', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CouponVersionTableMap::translateFieldName('IsCumulative', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_cumulative = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CouponVersionTableMap::translateFieldName('IsRemovingPostage', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_removing_postage = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CouponVersionTableMap::translateFieldName('IsAvailableOnSpecialOffers', TableMap::TYPE_PHPNAME, $indexType)]; $this->is_available_on_special_offers = (null !== $col) ? (boolean) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CouponVersionTableMap::translateFieldName('IsUsed', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_used = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CouponVersionTableMap::translateFieldName('SerializedConditions', TableMap::TYPE_PHPNAME, $indexType)]; + $this->serialized_conditions = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CouponVersionTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; @@ -1280,17 +1312,14 @@ abstract class CouponVersion implements ActiveRecordInterface if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) { $modifiedColumns[':p' . $index++] = 'AMOUNT'; } - if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) { - $modifiedColumns[':p' . $index++] = 'IS_USED'; - } if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) { $modifiedColumns[':p' . $index++] = 'IS_ENABLED'; } if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) { $modifiedColumns[':p' . $index++] = 'EXPIRATION_DATE'; } - if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_RULES)) { - $modifiedColumns[':p' . $index++] = 'SERIALIZED_RULES'; + if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) { + $modifiedColumns[':p' . $index++] = 'MAX_USAGE'; } if ($this->isColumnModified(CouponVersionTableMap::IS_CUMULATIVE)) { $modifiedColumns[':p' . $index++] = 'IS_CUMULATIVE'; @@ -1298,12 +1327,15 @@ abstract class CouponVersion implements ActiveRecordInterface if ($this->isColumnModified(CouponVersionTableMap::IS_REMOVING_POSTAGE)) { $modifiedColumns[':p' . $index++] = 'IS_REMOVING_POSTAGE'; } - if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) { - $modifiedColumns[':p' . $index++] = 'MAX_USAGE'; - } if ($this->isColumnModified(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) { $modifiedColumns[':p' . $index++] = 'IS_AVAILABLE_ON_SPECIAL_OFFERS'; } + if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) { + $modifiedColumns[':p' . $index++] = 'IS_USED'; + } + if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) { + $modifiedColumns[':p' . $index++] = 'SERIALIZED_CONDITIONS'; + } if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1336,30 +1368,30 @@ abstract class CouponVersion implements ActiveRecordInterface case 'AMOUNT': $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); break; - case 'IS_USED': - $stmt->bindValue($identifier, $this->is_used, PDO::PARAM_INT); - break; case 'IS_ENABLED': - $stmt->bindValue($identifier, $this->is_enabled, PDO::PARAM_INT); + $stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT); break; case 'EXPIRATION_DATE': $stmt->bindValue($identifier, $this->expiration_date ? $this->expiration_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; - case 'SERIALIZED_RULES': - $stmt->bindValue($identifier, $this->serialized_rules, PDO::PARAM_STR); - break; - case 'IS_CUMULATIVE': - $stmt->bindValue($identifier, $this->is_cumulative, PDO::PARAM_INT); - break; - case 'IS_REMOVING_POSTAGE': - $stmt->bindValue($identifier, $this->is_removing_postage, PDO::PARAM_INT); - break; case 'MAX_USAGE': $stmt->bindValue($identifier, $this->max_usage, PDO::PARAM_INT); break; + case 'IS_CUMULATIVE': + $stmt->bindValue($identifier, (int) $this->is_cumulative, PDO::PARAM_INT); + break; + case 'IS_REMOVING_POSTAGE': + $stmt->bindValue($identifier, (int) $this->is_removing_postage, PDO::PARAM_INT); + break; case 'IS_AVAILABLE_ON_SPECIAL_OFFERS': $stmt->bindValue($identifier, (int) $this->is_available_on_special_offers, PDO::PARAM_INT); break; + case 'IS_USED': + $stmt->bindValue($identifier, (int) $this->is_used, PDO::PARAM_INT); + break; + case 'SERIALIZED_CONDITIONS': + $stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1437,29 +1469,29 @@ abstract class CouponVersion implements ActiveRecordInterface return $this->getAmount(); break; case 4: - return $this->getIsUsed(); - break; - case 5: return $this->getIsEnabled(); break; - case 6: + case 5: return $this->getExpirationDate(); break; - case 7: - return $this->getSerializedRules(); - break; - case 8: - return $this->getIsCumulative(); - break; - case 9: - return $this->getIsRemovingPostage(); - break; - case 10: + case 6: return $this->getMaxUsage(); break; - case 11: + case 7: + return $this->getIsCumulative(); + break; + case 8: + return $this->getIsRemovingPostage(); + break; + case 9: return $this->getIsAvailableOnSpecialOffers(); break; + case 10: + return $this->getIsUsed(); + break; + case 11: + return $this->getSerializedConditions(); + break; case 12: return $this->getCreatedAt(); break; @@ -1502,14 +1534,14 @@ abstract class CouponVersion implements ActiveRecordInterface $keys[1] => $this->getCode(), $keys[2] => $this->getType(), $keys[3] => $this->getAmount(), - $keys[4] => $this->getIsUsed(), - $keys[5] => $this->getIsEnabled(), - $keys[6] => $this->getExpirationDate(), - $keys[7] => $this->getSerializedRules(), - $keys[8] => $this->getIsCumulative(), - $keys[9] => $this->getIsRemovingPostage(), - $keys[10] => $this->getMaxUsage(), - $keys[11] => $this->getIsAvailableOnSpecialOffers(), + $keys[4] => $this->getIsEnabled(), + $keys[5] => $this->getExpirationDate(), + $keys[6] => $this->getMaxUsage(), + $keys[7] => $this->getIsCumulative(), + $keys[8] => $this->getIsRemovingPostage(), + $keys[9] => $this->getIsAvailableOnSpecialOffers(), + $keys[10] => $this->getIsUsed(), + $keys[11] => $this->getSerializedConditions(), $keys[12] => $this->getCreatedAt(), $keys[13] => $this->getUpdatedAt(), $keys[14] => $this->getVersion(), @@ -1571,29 +1603,29 @@ abstract class CouponVersion implements ActiveRecordInterface $this->setAmount($value); break; case 4: - $this->setIsUsed($value); - break; - case 5: $this->setIsEnabled($value); break; - case 6: + case 5: $this->setExpirationDate($value); break; - case 7: - $this->setSerializedRules($value); - break; - case 8: - $this->setIsCumulative($value); - break; - case 9: - $this->setIsRemovingPostage($value); - break; - case 10: + case 6: $this->setMaxUsage($value); break; - case 11: + case 7: + $this->setIsCumulative($value); + break; + case 8: + $this->setIsRemovingPostage($value); + break; + case 9: $this->setIsAvailableOnSpecialOffers($value); break; + case 10: + $this->setIsUsed($value); + break; + case 11: + $this->setSerializedConditions($value); + break; case 12: $this->setCreatedAt($value); break; @@ -1631,14 +1663,14 @@ abstract class CouponVersion implements ActiveRecordInterface if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setIsUsed($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setIsEnabled($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setExpirationDate($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setSerializedRules($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setIsCumulative($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setIsRemovingPostage($arr[$keys[9]]); - if (array_key_exists($keys[10], $arr)) $this->setMaxUsage($arr[$keys[10]]); - if (array_key_exists($keys[11], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[11]]); + if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setIsCumulative($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setIsRemovingPostage($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setIsAvailableOnSpecialOffers($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setIsUsed($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setSerializedConditions($arr[$keys[11]]); if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]); if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]); if (array_key_exists($keys[14], $arr)) $this->setVersion($arr[$keys[14]]); @@ -1657,14 +1689,14 @@ abstract class CouponVersion implements ActiveRecordInterface if ($this->isColumnModified(CouponVersionTableMap::CODE)) $criteria->add(CouponVersionTableMap::CODE, $this->code); if ($this->isColumnModified(CouponVersionTableMap::TYPE)) $criteria->add(CouponVersionTableMap::TYPE, $this->type); if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) $criteria->add(CouponVersionTableMap::AMOUNT, $this->amount); - if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) $criteria->add(CouponVersionTableMap::IS_USED, $this->is_used); if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) $criteria->add(CouponVersionTableMap::IS_ENABLED, $this->is_enabled); if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) $criteria->add(CouponVersionTableMap::EXPIRATION_DATE, $this->expiration_date); - if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_RULES)) $criteria->add(CouponVersionTableMap::SERIALIZED_RULES, $this->serialized_rules); + if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) $criteria->add(CouponVersionTableMap::MAX_USAGE, $this->max_usage); if ($this->isColumnModified(CouponVersionTableMap::IS_CUMULATIVE)) $criteria->add(CouponVersionTableMap::IS_CUMULATIVE, $this->is_cumulative); if ($this->isColumnModified(CouponVersionTableMap::IS_REMOVING_POSTAGE)) $criteria->add(CouponVersionTableMap::IS_REMOVING_POSTAGE, $this->is_removing_postage); - if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) $criteria->add(CouponVersionTableMap::MAX_USAGE, $this->max_usage); if ($this->isColumnModified(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) $criteria->add(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $this->is_available_on_special_offers); + if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) $criteria->add(CouponVersionTableMap::IS_USED, $this->is_used); + if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) $criteria->add(CouponVersionTableMap::SERIALIZED_CONDITIONS, $this->serialized_conditions); if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) $criteria->add(CouponVersionTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(CouponVersionTableMap::UPDATED_AT)) $criteria->add(CouponVersionTableMap::UPDATED_AT, $this->updated_at); if ($this->isColumnModified(CouponVersionTableMap::VERSION)) $criteria->add(CouponVersionTableMap::VERSION, $this->version); @@ -1742,14 +1774,14 @@ abstract class CouponVersion implements ActiveRecordInterface $copyObj->setCode($this->getCode()); $copyObj->setType($this->getType()); $copyObj->setAmount($this->getAmount()); - $copyObj->setIsUsed($this->getIsUsed()); $copyObj->setIsEnabled($this->getIsEnabled()); $copyObj->setExpirationDate($this->getExpirationDate()); - $copyObj->setSerializedRules($this->getSerializedRules()); + $copyObj->setMaxUsage($this->getMaxUsage()); $copyObj->setIsCumulative($this->getIsCumulative()); $copyObj->setIsRemovingPostage($this->getIsRemovingPostage()); - $copyObj->setMaxUsage($this->getMaxUsage()); $copyObj->setIsAvailableOnSpecialOffers($this->getIsAvailableOnSpecialOffers()); + $copyObj->setIsUsed($this->getIsUsed()); + $copyObj->setSerializedConditions($this->getSerializedConditions()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); $copyObj->setVersion($this->getVersion()); @@ -1840,14 +1872,14 @@ abstract class CouponVersion implements ActiveRecordInterface $this->code = null; $this->type = null; $this->amount = null; - $this->is_used = null; $this->is_enabled = null; $this->expiration_date = null; - $this->serialized_rules = null; + $this->max_usage = null; $this->is_cumulative = null; $this->is_removing_postage = null; - $this->max_usage = null; $this->is_available_on_special_offers = null; + $this->is_used = null; + $this->serialized_conditions = null; $this->created_at = null; $this->updated_at = null; $this->version = null; diff --git a/core/lib/Thelia/Model/Base/CouponVersionQuery.php b/core/lib/Thelia/Model/Base/CouponVersionQuery.php index ed7e587e7..eebd85dd9 100644 --- a/core/lib/Thelia/Model/Base/CouponVersionQuery.php +++ b/core/lib/Thelia/Model/Base/CouponVersionQuery.php @@ -25,14 +25,14 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersionQuery orderByCode($order = Criteria::ASC) Order by the code column * @method ChildCouponVersionQuery orderByType($order = Criteria::ASC) Order by the type column * @method ChildCouponVersionQuery orderByAmount($order = Criteria::ASC) Order by the amount column - * @method ChildCouponVersionQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column * @method ChildCouponVersionQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column * @method ChildCouponVersionQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column - * @method ChildCouponVersionQuery orderBySerializedRules($order = Criteria::ASC) Order by the serialized_rules column + * @method ChildCouponVersionQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column * @method ChildCouponVersionQuery orderByIsCumulative($order = Criteria::ASC) Order by the is_cumulative column * @method ChildCouponVersionQuery orderByIsRemovingPostage($order = Criteria::ASC) Order by the is_removing_postage column - * @method ChildCouponVersionQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column * @method ChildCouponVersionQuery orderByIsAvailableOnSpecialOffers($order = Criteria::ASC) Order by the is_available_on_special_offers column + * @method ChildCouponVersionQuery orderByIsUsed($order = Criteria::ASC) Order by the is_used column + * @method ChildCouponVersionQuery orderBySerializedConditions($order = Criteria::ASC) Order by the serialized_conditions column * @method ChildCouponVersionQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildCouponVersionQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @method ChildCouponVersionQuery orderByVersion($order = Criteria::ASC) Order by the version column @@ -41,14 +41,14 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersionQuery groupByCode() Group by the code column * @method ChildCouponVersionQuery groupByType() Group by the type column * @method ChildCouponVersionQuery groupByAmount() Group by the amount column - * @method ChildCouponVersionQuery groupByIsUsed() Group by the is_used column * @method ChildCouponVersionQuery groupByIsEnabled() Group by the is_enabled column * @method ChildCouponVersionQuery groupByExpirationDate() Group by the expiration_date column - * @method ChildCouponVersionQuery groupBySerializedRules() Group by the serialized_rules column + * @method ChildCouponVersionQuery groupByMaxUsage() Group by the max_usage column * @method ChildCouponVersionQuery groupByIsCumulative() Group by the is_cumulative column * @method ChildCouponVersionQuery groupByIsRemovingPostage() Group by the is_removing_postage column - * @method ChildCouponVersionQuery groupByMaxUsage() Group by the max_usage column * @method ChildCouponVersionQuery groupByIsAvailableOnSpecialOffers() Group by the is_available_on_special_offers column + * @method ChildCouponVersionQuery groupByIsUsed() Group by the is_used column + * @method ChildCouponVersionQuery groupBySerializedConditions() Group by the serialized_conditions column * @method ChildCouponVersionQuery groupByCreatedAt() Group by the created_at column * @method ChildCouponVersionQuery groupByUpdatedAt() Group by the updated_at column * @method ChildCouponVersionQuery groupByVersion() Group by the version column @@ -68,14 +68,14 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersion findOneByCode(string $code) Return the first ChildCouponVersion filtered by the code column * @method ChildCouponVersion findOneByType(string $type) Return the first ChildCouponVersion filtered by the type column * @method ChildCouponVersion findOneByAmount(double $amount) Return the first ChildCouponVersion filtered by the amount column - * @method ChildCouponVersion findOneByIsUsed(int $is_used) Return the first ChildCouponVersion filtered by the is_used column - * @method ChildCouponVersion findOneByIsEnabled(int $is_enabled) Return the first ChildCouponVersion filtered by the is_enabled column + * @method ChildCouponVersion findOneByIsEnabled(boolean $is_enabled) Return the first ChildCouponVersion filtered by the is_enabled column * @method ChildCouponVersion findOneByExpirationDate(string $expiration_date) Return the first ChildCouponVersion filtered by the expiration_date column - * @method ChildCouponVersion findOneBySerializedRules(string $serialized_rules) Return the first ChildCouponVersion filtered by the serialized_rules column - * @method ChildCouponVersion findOneByIsCumulative(int $is_cumulative) Return the first ChildCouponVersion filtered by the is_cumulative column - * @method ChildCouponVersion findOneByIsRemovingPostage(int $is_removing_postage) Return the first ChildCouponVersion filtered by the is_removing_postage column * @method ChildCouponVersion findOneByMaxUsage(int $max_usage) Return the first ChildCouponVersion filtered by the max_usage column + * @method ChildCouponVersion findOneByIsCumulative(boolean $is_cumulative) Return the first ChildCouponVersion filtered by the is_cumulative column + * @method ChildCouponVersion findOneByIsRemovingPostage(boolean $is_removing_postage) Return the first ChildCouponVersion filtered by the is_removing_postage column * @method ChildCouponVersion findOneByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return the first ChildCouponVersion filtered by the is_available_on_special_offers column + * @method ChildCouponVersion findOneByIsUsed(boolean $is_used) Return the first ChildCouponVersion filtered by the is_used column + * @method ChildCouponVersion findOneBySerializedConditions(string $serialized_conditions) Return the first ChildCouponVersion filtered by the serialized_conditions column * @method ChildCouponVersion findOneByCreatedAt(string $created_at) Return the first ChildCouponVersion filtered by the created_at column * @method ChildCouponVersion findOneByUpdatedAt(string $updated_at) Return the first ChildCouponVersion filtered by the updated_at column * @method ChildCouponVersion findOneByVersion(int $version) Return the first ChildCouponVersion filtered by the version column @@ -84,14 +84,14 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method array findByCode(string $code) Return ChildCouponVersion objects filtered by the code column * @method array findByType(string $type) Return ChildCouponVersion objects filtered by the type column * @method array findByAmount(double $amount) Return ChildCouponVersion objects filtered by the amount column - * @method array findByIsUsed(int $is_used) Return ChildCouponVersion objects filtered by the is_used column - * @method array findByIsEnabled(int $is_enabled) Return ChildCouponVersion objects filtered by the is_enabled column + * @method array findByIsEnabled(boolean $is_enabled) Return ChildCouponVersion objects filtered by the is_enabled column * @method array findByExpirationDate(string $expiration_date) Return ChildCouponVersion objects filtered by the expiration_date column - * @method array findBySerializedRules(string $serialized_rules) Return ChildCouponVersion objects filtered by the serialized_rules column - * @method array findByIsCumulative(int $is_cumulative) Return ChildCouponVersion objects filtered by the is_cumulative column - * @method array findByIsRemovingPostage(int $is_removing_postage) Return ChildCouponVersion objects filtered by the is_removing_postage column * @method array findByMaxUsage(int $max_usage) Return ChildCouponVersion objects filtered by the max_usage column + * @method array findByIsCumulative(boolean $is_cumulative) Return ChildCouponVersion objects filtered by the is_cumulative column + * @method array findByIsRemovingPostage(boolean $is_removing_postage) Return ChildCouponVersion objects filtered by the is_removing_postage column * @method array findByIsAvailableOnSpecialOffers(boolean $is_available_on_special_offers) Return ChildCouponVersion objects filtered by the is_available_on_special_offers column + * @method array findByIsUsed(boolean $is_used) Return ChildCouponVersion objects filtered by the is_used column + * @method array findBySerializedConditions(string $serialized_conditions) Return ChildCouponVersion objects filtered by the serialized_conditions column * @method array findByCreatedAt(string $created_at) Return ChildCouponVersion objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildCouponVersion objects filtered by the updated_at column * @method array findByVersion(int $version) Return ChildCouponVersion objects filtered by the version column @@ -183,7 +183,7 @@ abstract class CouponVersionQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_USED, IS_ENABLED, EXPIRATION_DATE, SERIALIZED_RULES, IS_CUMULATIVE, IS_REMOVING_POSTAGE, MAX_USAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1'; + $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -426,83 +426,28 @@ abstract class CouponVersionQuery extends ModelCriteria return $this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount, $comparison); } - /** - * Filter the query on the is_used column - * - * Example usage: - * - * $query->filterByIsUsed(1234); // WHERE is_used = 1234 - * $query->filterByIsUsed(array(12, 34)); // WHERE is_used IN (12, 34) - * $query->filterByIsUsed(array('min' => 12)); // WHERE is_used > 12 - * - * - * @param mixed $isUsed The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponVersionQuery The current query, for fluid interface - */ - public function filterByIsUsed($isUsed = null, $comparison = null) - { - if (is_array($isUsed)) { - $useMinMax = false; - if (isset($isUsed['min'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_USED, $isUsed['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isUsed['max'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_USED, $isUsed['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponVersionTableMap::IS_USED, $isUsed, $comparison); - } - /** * Filter the query on the is_enabled column * * Example usage: * - * $query->filterByIsEnabled(1234); // WHERE is_enabled = 1234 - * $query->filterByIsEnabled(array(12, 34)); // WHERE is_enabled IN (12, 34) - * $query->filterByIsEnabled(array('min' => 12)); // WHERE is_enabled > 12 + * $query->filterByIsEnabled(true); // WHERE is_enabled = true + * $query->filterByIsEnabled('yes'); // WHERE is_enabled = true * * - * @param mixed $isEnabled The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param boolean|string $isEnabled The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCouponVersionQuery The current query, for fluid interface */ public function filterByIsEnabled($isEnabled = null, $comparison = null) { - if (is_array($isEnabled)) { - $useMinMax = false; - if (isset($isEnabled['min'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_ENABLED, $isEnabled['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isEnabled['max'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_ENABLED, $isEnabled['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } + if (is_string($isEnabled)) { + $is_enabled = in_array(strtolower($isEnabled), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; } return $this->addUsingAlias(CouponVersionTableMap::IS_ENABLED, $isEnabled, $comparison); @@ -551,117 +496,6 @@ abstract class CouponVersionQuery extends ModelCriteria return $this->addUsingAlias(CouponVersionTableMap::EXPIRATION_DATE, $expirationDate, $comparison); } - /** - * Filter the query on the serialized_rules column - * - * Example usage: - * - * $query->filterBySerializedRules('fooValue'); // WHERE serialized_rules = 'fooValue' - * $query->filterBySerializedRules('%fooValue%'); // WHERE serialized_rules LIKE '%fooValue%' - * - * - * @param string $serializedRules The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponVersionQuery The current query, for fluid interface - */ - public function filterBySerializedRules($serializedRules = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($serializedRules)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $serializedRules)) { - $serializedRules = str_replace('*', '%', $serializedRules); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CouponVersionTableMap::SERIALIZED_RULES, $serializedRules, $comparison); - } - - /** - * Filter the query on the is_cumulative column - * - * Example usage: - * - * $query->filterByIsCumulative(1234); // WHERE is_cumulative = 1234 - * $query->filterByIsCumulative(array(12, 34)); // WHERE is_cumulative IN (12, 34) - * $query->filterByIsCumulative(array('min' => 12)); // WHERE is_cumulative > 12 - * - * - * @param mixed $isCumulative The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponVersionQuery The current query, for fluid interface - */ - public function filterByIsCumulative($isCumulative = null, $comparison = null) - { - if (is_array($isCumulative)) { - $useMinMax = false; - if (isset($isCumulative['min'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_CUMULATIVE, $isCumulative['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isCumulative['max'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_CUMULATIVE, $isCumulative['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponVersionTableMap::IS_CUMULATIVE, $isCumulative, $comparison); - } - - /** - * Filter the query on the is_removing_postage column - * - * Example usage: - * - * $query->filterByIsRemovingPostage(1234); // WHERE is_removing_postage = 1234 - * $query->filterByIsRemovingPostage(array(12, 34)); // WHERE is_removing_postage IN (12, 34) - * $query->filterByIsRemovingPostage(array('min' => 12)); // WHERE is_removing_postage > 12 - * - * - * @param mixed $isRemovingPostage The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCouponVersionQuery The current query, for fluid interface - */ - public function filterByIsRemovingPostage($isRemovingPostage = null, $comparison = null) - { - if (is_array($isRemovingPostage)) { - $useMinMax = false; - if (isset($isRemovingPostage['min'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($isRemovingPostage['max'])) { - $this->addUsingAlias(CouponVersionTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CouponVersionTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage, $comparison); - } - /** * Filter the query on the max_usage column * @@ -703,6 +537,60 @@ abstract class CouponVersionQuery extends ModelCriteria return $this->addUsingAlias(CouponVersionTableMap::MAX_USAGE, $maxUsage, $comparison); } + /** + * Filter the query on the is_cumulative column + * + * Example usage: + * + * $query->filterByIsCumulative(true); // WHERE is_cumulative = true + * $query->filterByIsCumulative('yes'); // WHERE is_cumulative = true + * + * + * @param boolean|string $isCumulative The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponVersionQuery The current query, for fluid interface + */ + public function filterByIsCumulative($isCumulative = null, $comparison = null) + { + if (is_string($isCumulative)) { + $is_cumulative = in_array(strtolower($isCumulative), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponVersionTableMap::IS_CUMULATIVE, $isCumulative, $comparison); + } + + /** + * Filter the query on the is_removing_postage column + * + * Example usage: + * + * $query->filterByIsRemovingPostage(true); // WHERE is_removing_postage = true + * $query->filterByIsRemovingPostage('yes'); // WHERE is_removing_postage = true + * + * + * @param boolean|string $isRemovingPostage The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponVersionQuery The current query, for fluid interface + */ + public function filterByIsRemovingPostage($isRemovingPostage = null, $comparison = null) + { + if (is_string($isRemovingPostage)) { + $is_removing_postage = in_array(strtolower($isRemovingPostage), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponVersionTableMap::IS_REMOVING_POSTAGE, $isRemovingPostage, $comparison); + } + /** * Filter the query on the is_available_on_special_offers column * @@ -730,6 +618,62 @@ abstract class CouponVersionQuery extends ModelCriteria return $this->addUsingAlias(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, $isAvailableOnSpecialOffers, $comparison); } + /** + * Filter the query on the is_used column + * + * Example usage: + * + * $query->filterByIsUsed(true); // WHERE is_used = true + * $query->filterByIsUsed('yes'); // WHERE is_used = true + * + * + * @param boolean|string $isUsed The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponVersionQuery The current query, for fluid interface + */ + public function filterByIsUsed($isUsed = null, $comparison = null) + { + if (is_string($isUsed)) { + $is_used = in_array(strtolower($isUsed), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(CouponVersionTableMap::IS_USED, $isUsed, $comparison); + } + + /** + * Filter the query on the serialized_conditions column + * + * Example usage: + * + * $query->filterBySerializedConditions('fooValue'); // WHERE serialized_conditions = 'fooValue' + * $query->filterBySerializedConditions('%fooValue%'); // WHERE serialized_conditions LIKE '%fooValue%' + * + * + * @param string $serializedConditions The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponVersionQuery The current query, for fluid interface + */ + public function filterBySerializedConditions($serializedConditions = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($serializedConditions)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $serializedConditions)) { + $serializedConditions = str_replace('*', '%', $serializedConditions); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(CouponVersionTableMap::SERIALIZED_CONDITIONS, $serializedConditions, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/FeatureProduct.php b/core/lib/Thelia/Model/Base/FeatureProduct.php index 4af200d51..039967cee 100644 --- a/core/lib/Thelia/Model/Base/FeatureProduct.php +++ b/core/lib/Thelia/Model/Base/FeatureProduct.php @@ -85,10 +85,10 @@ abstract class FeatureProduct implements ActiveRecordInterface protected $feature_av_id; /** - * The value for the by_default field. + * The value for the free_text_value field. * @var string */ - protected $by_default; + protected $free_text_value; /** * The value for the position field. @@ -430,14 +430,14 @@ abstract class FeatureProduct implements ActiveRecordInterface } /** - * Get the [by_default] column value. + * Get the [free_text_value] column value. * * @return string */ - public function getByDefault() + public function getFreeTextValue() { - return $this->by_default; + return $this->free_text_value; } /** @@ -588,25 +588,25 @@ abstract class FeatureProduct implements ActiveRecordInterface } // setFeatureAvId() /** - * Set the value of [by_default] column. + * Set the value of [free_text_value] column. * * @param string $v new value * @return \Thelia\Model\FeatureProduct The current object (for fluent API support) */ - public function setByDefault($v) + public function setFreeTextValue($v) { if ($v !== null) { $v = (string) $v; } - if ($this->by_default !== $v) { - $this->by_default = $v; - $this->modifiedColumns[] = FeatureProductTableMap::BY_DEFAULT; + if ($this->free_text_value !== $v) { + $this->free_text_value = $v; + $this->modifiedColumns[] = FeatureProductTableMap::FREE_TEXT_VALUE; } return $this; - } // setByDefault() + } // setFreeTextValue() /** * Set the value of [position] column. @@ -720,8 +720,8 @@ abstract class FeatureProduct implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FeatureProductTableMap::translateFieldName('FeatureAvId', TableMap::TYPE_PHPNAME, $indexType)]; $this->feature_av_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FeatureProductTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)]; - $this->by_default = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FeatureProductTableMap::translateFieldName('FreeTextValue', TableMap::TYPE_PHPNAME, $indexType)]; + $this->free_text_value = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : FeatureProductTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; @@ -1015,8 +1015,8 @@ abstract class FeatureProduct implements ActiveRecordInterface if ($this->isColumnModified(FeatureProductTableMap::FEATURE_AV_ID)) { $modifiedColumns[':p' . $index++] = 'FEATURE_AV_ID'; } - if ($this->isColumnModified(FeatureProductTableMap::BY_DEFAULT)) { - $modifiedColumns[':p' . $index++] = 'BY_DEFAULT'; + if ($this->isColumnModified(FeatureProductTableMap::FREE_TEXT_VALUE)) { + $modifiedColumns[':p' . $index++] = 'FREE_TEXT_VALUE'; } if ($this->isColumnModified(FeatureProductTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = 'POSITION'; @@ -1050,8 +1050,8 @@ abstract class FeatureProduct implements ActiveRecordInterface case 'FEATURE_AV_ID': $stmt->bindValue($identifier, $this->feature_av_id, PDO::PARAM_INT); break; - case 'BY_DEFAULT': - $stmt->bindValue($identifier, $this->by_default, PDO::PARAM_STR); + case 'FREE_TEXT_VALUE': + $stmt->bindValue($identifier, $this->free_text_value, PDO::PARAM_STR); break; case 'POSITION': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); @@ -1137,7 +1137,7 @@ abstract class FeatureProduct implements ActiveRecordInterface return $this->getFeatureAvId(); break; case 4: - return $this->getByDefault(); + return $this->getFreeTextValue(); break; case 5: return $this->getPosition(); @@ -1181,7 +1181,7 @@ abstract class FeatureProduct implements ActiveRecordInterface $keys[1] => $this->getProductId(), $keys[2] => $this->getFeatureId(), $keys[3] => $this->getFeatureAvId(), - $keys[4] => $this->getByDefault(), + $keys[4] => $this->getFreeTextValue(), $keys[5] => $this->getPosition(), $keys[6] => $this->getCreatedAt(), $keys[7] => $this->getUpdatedAt(), @@ -1249,7 +1249,7 @@ abstract class FeatureProduct implements ActiveRecordInterface $this->setFeatureAvId($value); break; case 4: - $this->setByDefault($value); + $this->setFreeTextValue($value); break; case 5: $this->setPosition($value); @@ -1288,7 +1288,7 @@ abstract class FeatureProduct implements ActiveRecordInterface if (array_key_exists($keys[1], $arr)) $this->setProductId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setFeatureId($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setFeatureAvId($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setByDefault($arr[$keys[4]]); + if (array_key_exists($keys[4], $arr)) $this->setFreeTextValue($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setPosition($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); @@ -1307,7 +1307,7 @@ abstract class FeatureProduct implements ActiveRecordInterface if ($this->isColumnModified(FeatureProductTableMap::PRODUCT_ID)) $criteria->add(FeatureProductTableMap::PRODUCT_ID, $this->product_id); if ($this->isColumnModified(FeatureProductTableMap::FEATURE_ID)) $criteria->add(FeatureProductTableMap::FEATURE_ID, $this->feature_id); if ($this->isColumnModified(FeatureProductTableMap::FEATURE_AV_ID)) $criteria->add(FeatureProductTableMap::FEATURE_AV_ID, $this->feature_av_id); - if ($this->isColumnModified(FeatureProductTableMap::BY_DEFAULT)) $criteria->add(FeatureProductTableMap::BY_DEFAULT, $this->by_default); + if ($this->isColumnModified(FeatureProductTableMap::FREE_TEXT_VALUE)) $criteria->add(FeatureProductTableMap::FREE_TEXT_VALUE, $this->free_text_value); if ($this->isColumnModified(FeatureProductTableMap::POSITION)) $criteria->add(FeatureProductTableMap::POSITION, $this->position); if ($this->isColumnModified(FeatureProductTableMap::CREATED_AT)) $criteria->add(FeatureProductTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(FeatureProductTableMap::UPDATED_AT)) $criteria->add(FeatureProductTableMap::UPDATED_AT, $this->updated_at); @@ -1377,7 +1377,7 @@ abstract class FeatureProduct implements ActiveRecordInterface $copyObj->setProductId($this->getProductId()); $copyObj->setFeatureId($this->getFeatureId()); $copyObj->setFeatureAvId($this->getFeatureAvId()); - $copyObj->setByDefault($this->getByDefault()); + $copyObj->setFreeTextValue($this->getFreeTextValue()); $copyObj->setPosition($this->getPosition()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1571,7 +1571,7 @@ abstract class FeatureProduct implements ActiveRecordInterface $this->product_id = null; $this->feature_id = null; $this->feature_av_id = null; - $this->by_default = null; + $this->free_text_value = null; $this->position = null; $this->created_at = null; $this->updated_at = null; diff --git a/core/lib/Thelia/Model/Base/FeatureProductQuery.php b/core/lib/Thelia/Model/Base/FeatureProductQuery.php index c6a8f2a73..eb2ee7ec1 100644 --- a/core/lib/Thelia/Model/Base/FeatureProductQuery.php +++ b/core/lib/Thelia/Model/Base/FeatureProductQuery.php @@ -25,7 +25,7 @@ use Thelia\Model\Map\FeatureProductTableMap; * @method ChildFeatureProductQuery orderByProductId($order = Criteria::ASC) Order by the product_id column * @method ChildFeatureProductQuery orderByFeatureId($order = Criteria::ASC) Order by the feature_id column * @method ChildFeatureProductQuery orderByFeatureAvId($order = Criteria::ASC) Order by the feature_av_id column - * @method ChildFeatureProductQuery orderByByDefault($order = Criteria::ASC) Order by the by_default column + * @method ChildFeatureProductQuery orderByFreeTextValue($order = Criteria::ASC) Order by the free_text_value column * @method ChildFeatureProductQuery orderByPosition($order = Criteria::ASC) Order by the position column * @method ChildFeatureProductQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildFeatureProductQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column @@ -34,7 +34,7 @@ use Thelia\Model\Map\FeatureProductTableMap; * @method ChildFeatureProductQuery groupByProductId() Group by the product_id column * @method ChildFeatureProductQuery groupByFeatureId() Group by the feature_id column * @method ChildFeatureProductQuery groupByFeatureAvId() Group by the feature_av_id column - * @method ChildFeatureProductQuery groupByByDefault() Group by the by_default column + * @method ChildFeatureProductQuery groupByFreeTextValue() Group by the free_text_value column * @method ChildFeatureProductQuery groupByPosition() Group by the position column * @method ChildFeatureProductQuery groupByCreatedAt() Group by the created_at column * @method ChildFeatureProductQuery groupByUpdatedAt() Group by the updated_at column @@ -62,7 +62,7 @@ use Thelia\Model\Map\FeatureProductTableMap; * @method ChildFeatureProduct findOneByProductId(int $product_id) Return the first ChildFeatureProduct filtered by the product_id column * @method ChildFeatureProduct findOneByFeatureId(int $feature_id) Return the first ChildFeatureProduct filtered by the feature_id column * @method ChildFeatureProduct findOneByFeatureAvId(int $feature_av_id) Return the first ChildFeatureProduct filtered by the feature_av_id column - * @method ChildFeatureProduct findOneByByDefault(string $by_default) Return the first ChildFeatureProduct filtered by the by_default column + * @method ChildFeatureProduct findOneByFreeTextValue(string $free_text_value) Return the first ChildFeatureProduct filtered by the free_text_value column * @method ChildFeatureProduct findOneByPosition(int $position) Return the first ChildFeatureProduct filtered by the position column * @method ChildFeatureProduct findOneByCreatedAt(string $created_at) Return the first ChildFeatureProduct filtered by the created_at column * @method ChildFeatureProduct findOneByUpdatedAt(string $updated_at) Return the first ChildFeatureProduct filtered by the updated_at column @@ -71,7 +71,7 @@ use Thelia\Model\Map\FeatureProductTableMap; * @method array findByProductId(int $product_id) Return ChildFeatureProduct objects filtered by the product_id column * @method array findByFeatureId(int $feature_id) Return ChildFeatureProduct objects filtered by the feature_id column * @method array findByFeatureAvId(int $feature_av_id) Return ChildFeatureProduct objects filtered by the feature_av_id column - * @method array findByByDefault(string $by_default) Return ChildFeatureProduct objects filtered by the by_default column + * @method array findByFreeTextValue(string $free_text_value) Return ChildFeatureProduct objects filtered by the free_text_value column * @method array findByPosition(int $position) Return ChildFeatureProduct objects filtered by the position column * @method array findByCreatedAt(string $created_at) Return ChildFeatureProduct objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildFeatureProduct objects filtered by the updated_at column @@ -163,7 +163,7 @@ abstract class FeatureProductQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, PRODUCT_ID, FEATURE_ID, FEATURE_AV_ID, BY_DEFAULT, POSITION, CREATED_AT, UPDATED_AT FROM feature_product WHERE ID = :p0'; + $sql = 'SELECT ID, PRODUCT_ID, FEATURE_ID, FEATURE_AV_ID, FREE_TEXT_VALUE, POSITION, CREATED_AT, UPDATED_AT FROM feature_product WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -423,32 +423,32 @@ abstract class FeatureProductQuery extends ModelCriteria } /** - * Filter the query on the by_default column + * Filter the query on the free_text_value column * * Example usage: * - * $query->filterByByDefault('fooValue'); // WHERE by_default = 'fooValue' - * $query->filterByByDefault('%fooValue%'); // WHERE by_default LIKE '%fooValue%' + * $query->filterByFreeTextValue('fooValue'); // WHERE free_text_value = 'fooValue' + * $query->filterByFreeTextValue('%fooValue%'); // WHERE free_text_value LIKE '%fooValue%' * * - * @param string $byDefault The value to use as filter. + * @param string $freeTextValue The value to use as filter. * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildFeatureProductQuery The current query, for fluid interface */ - public function filterByByDefault($byDefault = null, $comparison = null) + public function filterByFreeTextValue($freeTextValue = null, $comparison = null) { if (null === $comparison) { - if (is_array($byDefault)) { + if (is_array($freeTextValue)) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $byDefault)) { - $byDefault = str_replace('*', '%', $byDefault); + } elseif (preg_match('/[\%\*]/', $freeTextValue)) { + $freeTextValue = str_replace('*', '%', $freeTextValue); $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(FeatureProductTableMap::BY_DEFAULT, $byDefault, $comparison); + return $this->addUsingAlias(FeatureProductTableMap::FREE_TEXT_VALUE, $freeTextValue, $comparison); } /** diff --git a/core/lib/Thelia/Model/Base/FeatureTemplate.php b/core/lib/Thelia/Model/Base/FeatureTemplate.php index bbccd9251..b8ba55629 100644 --- a/core/lib/Thelia/Model/Base/FeatureTemplate.php +++ b/core/lib/Thelia/Model/Base/FeatureTemplate.php @@ -76,6 +76,12 @@ abstract class FeatureTemplate implements ActiveRecordInterface */ protected $template_id; + /** + * The value for the position field. + * @var int + */ + protected $position; + /** * The value for the created_at field. * @var string @@ -393,6 +399,17 @@ abstract class FeatureTemplate implements ActiveRecordInterface return $this->template_id; } + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -504,6 +521,27 @@ abstract class FeatureTemplate implements ActiveRecordInterface return $this; } // setTemplateId() + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\FeatureTemplate The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[] = FeatureTemplateTableMap::POSITION; + } + + + return $this; + } // setPosition() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -592,13 +630,16 @@ abstract class FeatureTemplate implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : FeatureTemplateTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; $this->template_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FeatureTemplateTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FeatureTemplateTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FeatureTemplateTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FeatureTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : FeatureTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -611,7 +652,7 @@ abstract class FeatureTemplate implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 5; // 5 = FeatureTemplateTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 6; // 6 = FeatureTemplateTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\FeatureTemplate object", 0, $e); @@ -867,6 +908,9 @@ abstract class FeatureTemplate implements ActiveRecordInterface if ($this->isColumnModified(FeatureTemplateTableMap::TEMPLATE_ID)) { $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; } + if ($this->isColumnModified(FeatureTemplateTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = 'POSITION'; + } if ($this->isColumnModified(FeatureTemplateTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -893,6 +937,9 @@ abstract class FeatureTemplate implements ActiveRecordInterface case 'TEMPLATE_ID': $stmt->bindValue($identifier, $this->template_id, PDO::PARAM_INT); break; + case 'POSITION': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -971,9 +1018,12 @@ abstract class FeatureTemplate implements ActiveRecordInterface return $this->getTemplateId(); break; case 3: - return $this->getCreatedAt(); + return $this->getPosition(); break; case 4: + return $this->getCreatedAt(); + break; + case 5: return $this->getUpdatedAt(); break; default: @@ -1008,8 +1058,9 @@ abstract class FeatureTemplate implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getFeatureId(), $keys[2] => $this->getTemplateId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), + $keys[3] => $this->getPosition(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1068,9 +1119,12 @@ abstract class FeatureTemplate implements ActiveRecordInterface $this->setTemplateId($value); break; case 3: - $this->setCreatedAt($value); + $this->setPosition($value); break; case 4: + $this->setCreatedAt($value); + break; + case 5: $this->setUpdatedAt($value); break; } // switch() @@ -1100,8 +1154,9 @@ abstract class FeatureTemplate implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setFeatureId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setTemplateId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + if (array_key_exists($keys[3], $arr)) $this->setPosition($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); } /** @@ -1116,6 +1171,7 @@ abstract class FeatureTemplate implements ActiveRecordInterface if ($this->isColumnModified(FeatureTemplateTableMap::ID)) $criteria->add(FeatureTemplateTableMap::ID, $this->id); if ($this->isColumnModified(FeatureTemplateTableMap::FEATURE_ID)) $criteria->add(FeatureTemplateTableMap::FEATURE_ID, $this->feature_id); if ($this->isColumnModified(FeatureTemplateTableMap::TEMPLATE_ID)) $criteria->add(FeatureTemplateTableMap::TEMPLATE_ID, $this->template_id); + if ($this->isColumnModified(FeatureTemplateTableMap::POSITION)) $criteria->add(FeatureTemplateTableMap::POSITION, $this->position); if ($this->isColumnModified(FeatureTemplateTableMap::CREATED_AT)) $criteria->add(FeatureTemplateTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(FeatureTemplateTableMap::UPDATED_AT)) $criteria->add(FeatureTemplateTableMap::UPDATED_AT, $this->updated_at); @@ -1183,6 +1239,7 @@ abstract class FeatureTemplate implements ActiveRecordInterface { $copyObj->setFeatureId($this->getFeatureId()); $copyObj->setTemplateId($this->getTemplateId()); + $copyObj->setPosition($this->getPosition()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { @@ -1323,6 +1380,7 @@ abstract class FeatureTemplate implements ActiveRecordInterface $this->id = null; $this->feature_id = null; $this->template_id = null; + $this->position = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php b/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php index c99c1305f..cccad15ae 100644 --- a/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php +++ b/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php @@ -24,12 +24,14 @@ use Thelia\Model\Map\FeatureTemplateTableMap; * @method ChildFeatureTemplateQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildFeatureTemplateQuery orderByFeatureId($order = Criteria::ASC) Order by the feature_id column * @method ChildFeatureTemplateQuery orderByTemplateId($order = Criteria::ASC) Order by the template_id column + * @method ChildFeatureTemplateQuery orderByPosition($order = Criteria::ASC) Order by the position column * @method ChildFeatureTemplateQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildFeatureTemplateQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildFeatureTemplateQuery groupById() Group by the id column * @method ChildFeatureTemplateQuery groupByFeatureId() Group by the feature_id column * @method ChildFeatureTemplateQuery groupByTemplateId() Group by the template_id column + * @method ChildFeatureTemplateQuery groupByPosition() Group by the position column * @method ChildFeatureTemplateQuery groupByCreatedAt() Group by the created_at column * @method ChildFeatureTemplateQuery groupByUpdatedAt() Group by the updated_at column * @@ -51,12 +53,14 @@ use Thelia\Model\Map\FeatureTemplateTableMap; * @method ChildFeatureTemplate findOneById(int $id) Return the first ChildFeatureTemplate filtered by the id column * @method ChildFeatureTemplate findOneByFeatureId(int $feature_id) Return the first ChildFeatureTemplate filtered by the feature_id column * @method ChildFeatureTemplate findOneByTemplateId(int $template_id) Return the first ChildFeatureTemplate filtered by the template_id column + * @method ChildFeatureTemplate findOneByPosition(int $position) Return the first ChildFeatureTemplate filtered by the position column * @method ChildFeatureTemplate findOneByCreatedAt(string $created_at) Return the first ChildFeatureTemplate filtered by the created_at column * @method ChildFeatureTemplate findOneByUpdatedAt(string $updated_at) Return the first ChildFeatureTemplate filtered by the updated_at column * * @method array findById(int $id) Return ChildFeatureTemplate objects filtered by the id column * @method array findByFeatureId(int $feature_id) Return ChildFeatureTemplate objects filtered by the feature_id column * @method array findByTemplateId(int $template_id) Return ChildFeatureTemplate objects filtered by the template_id column + * @method array findByPosition(int $position) Return ChildFeatureTemplate objects filtered by the position column * @method array findByCreatedAt(string $created_at) Return ChildFeatureTemplate objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildFeatureTemplate objects filtered by the updated_at column * @@ -147,7 +151,7 @@ abstract class FeatureTemplateQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, FEATURE_ID, TEMPLATE_ID, CREATED_AT, UPDATED_AT FROM feature_template WHERE ID = :p0'; + $sql = 'SELECT ID, FEATURE_ID, TEMPLATE_ID, POSITION, CREATED_AT, UPDATED_AT FROM feature_template WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -363,6 +367,47 @@ abstract class FeatureTemplateQuery extends ModelCriteria return $this->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $templateId, $comparison); } + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(FeatureTemplateTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::POSITION, $position, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/OrderProductAttributeCombination.php b/core/lib/Thelia/Model/Base/OrderProductAttributeCombination.php index e02bc9cc5..971f127b6 100644 --- a/core/lib/Thelia/Model/Base/OrderProductAttributeCombination.php +++ b/core/lib/Thelia/Model/Base/OrderProductAttributeCombination.php @@ -87,10 +87,10 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface protected $attribute_description; /** - * The value for the attribute_postscriptumn field. + * The value for the attribute_postscriptum field. * @var string */ - protected $attribute_postscriptumn; + protected $attribute_postscriptum; /** * The value for the attribute_av_title field. @@ -451,14 +451,14 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface } /** - * Get the [attribute_postscriptumn] column value. + * Get the [attribute_postscriptum] column value. * * @return string */ - public function getAttributePostscriptumn() + public function getAttributePostscriptum() { - return $this->attribute_postscriptumn; + return $this->attribute_postscriptum; } /** @@ -655,25 +655,25 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface } // setAttributeDescription() /** - * Set the value of [attribute_postscriptumn] column. + * Set the value of [attribute_postscriptum] column. * * @param string $v new value * @return \Thelia\Model\OrderProductAttributeCombination The current object (for fluent API support) */ - public function setAttributePostscriptumn($v) + public function setAttributePostscriptum($v) { if ($v !== null) { $v = (string) $v; } - if ($this->attribute_postscriptumn !== $v) { - $this->attribute_postscriptumn = $v; - $this->modifiedColumns[] = OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN; + if ($this->attribute_postscriptum !== $v) { + $this->attribute_postscriptum = $v; + $this->modifiedColumns[] = OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM; } return $this; - } // setAttributePostscriptumn() + } // setAttributePostscriptum() /** * Set the value of [attribute_av_title] column. @@ -853,8 +853,8 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : OrderProductAttributeCombinationTableMap::translateFieldName('AttributeDescription', TableMap::TYPE_PHPNAME, $indexType)]; $this->attribute_description = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : OrderProductAttributeCombinationTableMap::translateFieldName('AttributePostscriptumn', TableMap::TYPE_PHPNAME, $indexType)]; - $this->attribute_postscriptumn = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : OrderProductAttributeCombinationTableMap::translateFieldName('AttributePostscriptum', TableMap::TYPE_PHPNAME, $indexType)]; + $this->attribute_postscriptum = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : OrderProductAttributeCombinationTableMap::translateFieldName('AttributeAvTitle', TableMap::TYPE_PHPNAME, $indexType)]; $this->attribute_av_title = (null !== $col) ? (string) $col : null; @@ -1138,8 +1138,8 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION)) { $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_DESCRIPTION'; } - if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN)) { - $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_POSTSCRIPTUMN'; + if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM)) { + $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_POSTSCRIPTUM'; } if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE)) { $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_AV_TITLE'; @@ -1185,8 +1185,8 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface case 'ATTRIBUTE_DESCRIPTION': $stmt->bindValue($identifier, $this->attribute_description, PDO::PARAM_STR); break; - case 'ATTRIBUTE_POSTSCRIPTUMN': - $stmt->bindValue($identifier, $this->attribute_postscriptumn, PDO::PARAM_STR); + case 'ATTRIBUTE_POSTSCRIPTUM': + $stmt->bindValue($identifier, $this->attribute_postscriptum, PDO::PARAM_STR); break; case 'ATTRIBUTE_AV_TITLE': $stmt->bindValue($identifier, $this->attribute_av_title, PDO::PARAM_STR); @@ -1284,7 +1284,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface return $this->getAttributeDescription(); break; case 5: - return $this->getAttributePostscriptumn(); + return $this->getAttributePostscriptum(); break; case 6: return $this->getAttributeAvTitle(); @@ -1338,7 +1338,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface $keys[2] => $this->getAttributeTitle(), $keys[3] => $this->getAttributeChapo(), $keys[4] => $this->getAttributeDescription(), - $keys[5] => $this->getAttributePostscriptumn(), + $keys[5] => $this->getAttributePostscriptum(), $keys[6] => $this->getAttributeAvTitle(), $keys[7] => $this->getAttributeAvChapo(), $keys[8] => $this->getAttributeAvDescription(), @@ -1406,7 +1406,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface $this->setAttributeDescription($value); break; case 5: - $this->setAttributePostscriptumn($value); + $this->setAttributePostscriptum($value); break; case 6: $this->setAttributeAvTitle($value); @@ -1455,7 +1455,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface if (array_key_exists($keys[2], $arr)) $this->setAttributeTitle($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setAttributeChapo($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setAttributeDescription($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setAttributePostscriptumn($arr[$keys[5]]); + if (array_key_exists($keys[5], $arr)) $this->setAttributePostscriptum($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setAttributeAvTitle($arr[$keys[6]]); if (array_key_exists($keys[7], $arr)) $this->setAttributeAvChapo($arr[$keys[7]]); if (array_key_exists($keys[8], $arr)) $this->setAttributeAvDescription($arr[$keys[8]]); @@ -1478,7 +1478,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE, $this->attribute_title); if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO, $this->attribute_chapo); if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION, $this->attribute_description); - if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN, $this->attribute_postscriptumn); + if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM, $this->attribute_postscriptum); if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE, $this->attribute_av_title); if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO, $this->attribute_av_chapo); if ($this->isColumnModified(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION)) $criteria->add(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION, $this->attribute_av_description); @@ -1552,7 +1552,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface $copyObj->setAttributeTitle($this->getAttributeTitle()); $copyObj->setAttributeChapo($this->getAttributeChapo()); $copyObj->setAttributeDescription($this->getAttributeDescription()); - $copyObj->setAttributePostscriptumn($this->getAttributePostscriptumn()); + $copyObj->setAttributePostscriptum($this->getAttributePostscriptum()); $copyObj->setAttributeAvTitle($this->getAttributeAvTitle()); $copyObj->setAttributeAvChapo($this->getAttributeAvChapo()); $copyObj->setAttributeAvDescription($this->getAttributeAvDescription()); @@ -1648,7 +1648,7 @@ abstract class OrderProductAttributeCombination implements ActiveRecordInterface $this->attribute_title = null; $this->attribute_chapo = null; $this->attribute_description = null; - $this->attribute_postscriptumn = null; + $this->attribute_postscriptum = null; $this->attribute_av_title = null; $this->attribute_av_chapo = null; $this->attribute_av_description = null; diff --git a/core/lib/Thelia/Model/Base/OrderProductAttributeCombinationQuery.php b/core/lib/Thelia/Model/Base/OrderProductAttributeCombinationQuery.php index 9e8298aa5..886b75c5f 100644 --- a/core/lib/Thelia/Model/Base/OrderProductAttributeCombinationQuery.php +++ b/core/lib/Thelia/Model/Base/OrderProductAttributeCombinationQuery.php @@ -26,7 +26,7 @@ use Thelia\Model\Map\OrderProductAttributeCombinationTableMap; * @method ChildOrderProductAttributeCombinationQuery orderByAttributeTitle($order = Criteria::ASC) Order by the attribute_title column * @method ChildOrderProductAttributeCombinationQuery orderByAttributeChapo($order = Criteria::ASC) Order by the attribute_chapo column * @method ChildOrderProductAttributeCombinationQuery orderByAttributeDescription($order = Criteria::ASC) Order by the attribute_description column - * @method ChildOrderProductAttributeCombinationQuery orderByAttributePostscriptumn($order = Criteria::ASC) Order by the attribute_postscriptumn column + * @method ChildOrderProductAttributeCombinationQuery orderByAttributePostscriptum($order = Criteria::ASC) Order by the attribute_postscriptum column * @method ChildOrderProductAttributeCombinationQuery orderByAttributeAvTitle($order = Criteria::ASC) Order by the attribute_av_title column * @method ChildOrderProductAttributeCombinationQuery orderByAttributeAvChapo($order = Criteria::ASC) Order by the attribute_av_chapo column * @method ChildOrderProductAttributeCombinationQuery orderByAttributeAvDescription($order = Criteria::ASC) Order by the attribute_av_description column @@ -39,7 +39,7 @@ use Thelia\Model\Map\OrderProductAttributeCombinationTableMap; * @method ChildOrderProductAttributeCombinationQuery groupByAttributeTitle() Group by the attribute_title column * @method ChildOrderProductAttributeCombinationQuery groupByAttributeChapo() Group by the attribute_chapo column * @method ChildOrderProductAttributeCombinationQuery groupByAttributeDescription() Group by the attribute_description column - * @method ChildOrderProductAttributeCombinationQuery groupByAttributePostscriptumn() Group by the attribute_postscriptumn column + * @method ChildOrderProductAttributeCombinationQuery groupByAttributePostscriptum() Group by the attribute_postscriptum column * @method ChildOrderProductAttributeCombinationQuery groupByAttributeAvTitle() Group by the attribute_av_title column * @method ChildOrderProductAttributeCombinationQuery groupByAttributeAvChapo() Group by the attribute_av_chapo column * @method ChildOrderProductAttributeCombinationQuery groupByAttributeAvDescription() Group by the attribute_av_description column @@ -63,7 +63,7 @@ use Thelia\Model\Map\OrderProductAttributeCombinationTableMap; * @method ChildOrderProductAttributeCombination findOneByAttributeTitle(string $attribute_title) Return the first ChildOrderProductAttributeCombination filtered by the attribute_title column * @method ChildOrderProductAttributeCombination findOneByAttributeChapo(string $attribute_chapo) Return the first ChildOrderProductAttributeCombination filtered by the attribute_chapo column * @method ChildOrderProductAttributeCombination findOneByAttributeDescription(string $attribute_description) Return the first ChildOrderProductAttributeCombination filtered by the attribute_description column - * @method ChildOrderProductAttributeCombination findOneByAttributePostscriptumn(string $attribute_postscriptumn) Return the first ChildOrderProductAttributeCombination filtered by the attribute_postscriptumn column + * @method ChildOrderProductAttributeCombination findOneByAttributePostscriptum(string $attribute_postscriptum) Return the first ChildOrderProductAttributeCombination filtered by the attribute_postscriptum column * @method ChildOrderProductAttributeCombination findOneByAttributeAvTitle(string $attribute_av_title) Return the first ChildOrderProductAttributeCombination filtered by the attribute_av_title column * @method ChildOrderProductAttributeCombination findOneByAttributeAvChapo(string $attribute_av_chapo) Return the first ChildOrderProductAttributeCombination filtered by the attribute_av_chapo column * @method ChildOrderProductAttributeCombination findOneByAttributeAvDescription(string $attribute_av_description) Return the first ChildOrderProductAttributeCombination filtered by the attribute_av_description column @@ -76,7 +76,7 @@ use Thelia\Model\Map\OrderProductAttributeCombinationTableMap; * @method array findByAttributeTitle(string $attribute_title) Return ChildOrderProductAttributeCombination objects filtered by the attribute_title column * @method array findByAttributeChapo(string $attribute_chapo) Return ChildOrderProductAttributeCombination objects filtered by the attribute_chapo column * @method array findByAttributeDescription(string $attribute_description) Return ChildOrderProductAttributeCombination objects filtered by the attribute_description column - * @method array findByAttributePostscriptumn(string $attribute_postscriptumn) Return ChildOrderProductAttributeCombination objects filtered by the attribute_postscriptumn column + * @method array findByAttributePostscriptum(string $attribute_postscriptum) Return ChildOrderProductAttributeCombination objects filtered by the attribute_postscriptum column * @method array findByAttributeAvTitle(string $attribute_av_title) Return ChildOrderProductAttributeCombination objects filtered by the attribute_av_title column * @method array findByAttributeAvChapo(string $attribute_av_chapo) Return ChildOrderProductAttributeCombination objects filtered by the attribute_av_chapo column * @method array findByAttributeAvDescription(string $attribute_av_description) Return ChildOrderProductAttributeCombination objects filtered by the attribute_av_description column @@ -171,7 +171,7 @@ abstract class OrderProductAttributeCombinationQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, ORDER_PRODUCT_ID, ATTRIBUTE_TITLE, ATTRIBUTE_CHAPO, ATTRIBUTE_DESCRIPTION, ATTRIBUTE_POSTSCRIPTUMN, ATTRIBUTE_AV_TITLE, ATTRIBUTE_AV_CHAPO, ATTRIBUTE_AV_DESCRIPTION, ATTRIBUTE_AV_POSTSCRIPTUM, CREATED_AT, UPDATED_AT FROM order_product_attribute_combination WHERE ID = :p0'; + $sql = 'SELECT ID, ORDER_PRODUCT_ID, ATTRIBUTE_TITLE, ATTRIBUTE_CHAPO, ATTRIBUTE_DESCRIPTION, ATTRIBUTE_POSTSCRIPTUM, ATTRIBUTE_AV_TITLE, ATTRIBUTE_AV_CHAPO, ATTRIBUTE_AV_DESCRIPTION, ATTRIBUTE_AV_POSTSCRIPTUM, CREATED_AT, UPDATED_AT FROM order_product_attribute_combination WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -432,32 +432,32 @@ abstract class OrderProductAttributeCombinationQuery extends ModelCriteria } /** - * Filter the query on the attribute_postscriptumn column + * Filter the query on the attribute_postscriptum column * * Example usage: * - * $query->filterByAttributePostscriptumn('fooValue'); // WHERE attribute_postscriptumn = 'fooValue' - * $query->filterByAttributePostscriptumn('%fooValue%'); // WHERE attribute_postscriptumn LIKE '%fooValue%' + * $query->filterByAttributePostscriptum('fooValue'); // WHERE attribute_postscriptum = 'fooValue' + * $query->filterByAttributePostscriptum('%fooValue%'); // WHERE attribute_postscriptum LIKE '%fooValue%' * * - * @param string $attributePostscriptumn The value to use as filter. + * @param string $attributePostscriptum The value to use as filter. * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildOrderProductAttributeCombinationQuery The current query, for fluid interface */ - public function filterByAttributePostscriptumn($attributePostscriptumn = null, $comparison = null) + public function filterByAttributePostscriptum($attributePostscriptum = null, $comparison = null) { if (null === $comparison) { - if (is_array($attributePostscriptumn)) { + if (is_array($attributePostscriptum)) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $attributePostscriptumn)) { - $attributePostscriptumn = str_replace('*', '%', $attributePostscriptumn); + } elseif (preg_match('/[\%\*]/', $attributePostscriptum)) { + $attributePostscriptum = str_replace('*', '%', $attributePostscriptum); $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN, $attributePostscriptumn, $comparison); + return $this->addUsingAlias(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM, $attributePostscriptum, $comparison); } /** diff --git a/core/lib/Thelia/Model/Base/OrderProductTax.php b/core/lib/Thelia/Model/Base/OrderProductTax.php index 544755ff4..6d0807ccf 100644 --- a/core/lib/Thelia/Model/Base/OrderProductTax.php +++ b/core/lib/Thelia/Model/Base/OrderProductTax.php @@ -86,6 +86,12 @@ abstract class OrderProductTax implements ActiveRecordInterface */ protected $amount; + /** + * The value for the promo_amount field. + * @var double + */ + protected $promo_amount; + /** * The value for the created_at field. * @var string @@ -420,6 +426,17 @@ abstract class OrderProductTax implements ActiveRecordInterface return $this->amount; } + /** + * Get the [promo_amount] column value. + * + * @return double + */ + public function getPromoAmount() + { + + return $this->promo_amount; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -569,6 +586,27 @@ abstract class OrderProductTax implements ActiveRecordInterface return $this; } // setAmount() + /** + * Set the value of [promo_amount] column. + * + * @param double $v new value + * @return \Thelia\Model\OrderProductTax The current object (for fluent API support) + */ + public function setPromoAmount($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->promo_amount !== $v) { + $this->promo_amount = $v; + $this->modifiedColumns[] = OrderProductTaxTableMap::PROMO_AMOUNT; + } + + + return $this; + } // setPromoAmount() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -663,13 +701,16 @@ abstract class OrderProductTax implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : OrderProductTaxTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; $this->amount = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : OrderProductTaxTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : OrderProductTaxTableMap::translateFieldName('PromoAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->promo_amount = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : OrderProductTaxTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : OrderProductTaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : OrderProductTaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -682,7 +723,7 @@ abstract class OrderProductTax implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 7; // 7 = OrderProductTaxTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 8; // 8 = OrderProductTaxTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\OrderProductTax object", 0, $e); @@ -933,6 +974,9 @@ abstract class OrderProductTax implements ActiveRecordInterface if ($this->isColumnModified(OrderProductTaxTableMap::AMOUNT)) { $modifiedColumns[':p' . $index++] = 'AMOUNT'; } + if ($this->isColumnModified(OrderProductTaxTableMap::PROMO_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'PROMO_AMOUNT'; + } if ($this->isColumnModified(OrderProductTaxTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -965,6 +1009,9 @@ abstract class OrderProductTax implements ActiveRecordInterface case 'AMOUNT': $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); break; + case 'PROMO_AMOUNT': + $stmt->bindValue($identifier, $this->promo_amount, PDO::PARAM_STR); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1049,9 +1096,12 @@ abstract class OrderProductTax implements ActiveRecordInterface return $this->getAmount(); break; case 5: - return $this->getCreatedAt(); + return $this->getPromoAmount(); break; case 6: + return $this->getCreatedAt(); + break; + case 7: return $this->getUpdatedAt(); break; default: @@ -1088,8 +1138,9 @@ abstract class OrderProductTax implements ActiveRecordInterface $keys[2] => $this->getTitle(), $keys[3] => $this->getDescription(), $keys[4] => $this->getAmount(), - $keys[5] => $this->getCreatedAt(), - $keys[6] => $this->getUpdatedAt(), + $keys[5] => $this->getPromoAmount(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1151,9 +1202,12 @@ abstract class OrderProductTax implements ActiveRecordInterface $this->setAmount($value); break; case 5: - $this->setCreatedAt($value); + $this->setPromoAmount($value); break; case 6: + $this->setCreatedAt($value); + break; + case 7: $this->setUpdatedAt($value); break; } // switch() @@ -1185,8 +1239,9 @@ abstract class OrderProductTax implements ActiveRecordInterface if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setDescription($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setAmount($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); + if (array_key_exists($keys[5], $arr)) $this->setPromoAmount($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); } /** @@ -1203,6 +1258,7 @@ abstract class OrderProductTax implements ActiveRecordInterface if ($this->isColumnModified(OrderProductTaxTableMap::TITLE)) $criteria->add(OrderProductTaxTableMap::TITLE, $this->title); if ($this->isColumnModified(OrderProductTaxTableMap::DESCRIPTION)) $criteria->add(OrderProductTaxTableMap::DESCRIPTION, $this->description); if ($this->isColumnModified(OrderProductTaxTableMap::AMOUNT)) $criteria->add(OrderProductTaxTableMap::AMOUNT, $this->amount); + if ($this->isColumnModified(OrderProductTaxTableMap::PROMO_AMOUNT)) $criteria->add(OrderProductTaxTableMap::PROMO_AMOUNT, $this->promo_amount); if ($this->isColumnModified(OrderProductTaxTableMap::CREATED_AT)) $criteria->add(OrderProductTaxTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(OrderProductTaxTableMap::UPDATED_AT)) $criteria->add(OrderProductTaxTableMap::UPDATED_AT, $this->updated_at); @@ -1272,6 +1328,7 @@ abstract class OrderProductTax implements ActiveRecordInterface $copyObj->setTitle($this->getTitle()); $copyObj->setDescription($this->getDescription()); $copyObj->setAmount($this->getAmount()); + $copyObj->setPromoAmount($this->getPromoAmount()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { @@ -1363,6 +1420,7 @@ abstract class OrderProductTax implements ActiveRecordInterface $this->title = null; $this->description = null; $this->amount = null; + $this->promo_amount = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/OrderProductTaxQuery.php b/core/lib/Thelia/Model/Base/OrderProductTaxQuery.php index d37c2c501..d0153d0cd 100644 --- a/core/lib/Thelia/Model/Base/OrderProductTaxQuery.php +++ b/core/lib/Thelia/Model/Base/OrderProductTaxQuery.php @@ -26,6 +26,7 @@ use Thelia\Model\Map\OrderProductTaxTableMap; * @method ChildOrderProductTaxQuery orderByTitle($order = Criteria::ASC) Order by the title column * @method ChildOrderProductTaxQuery orderByDescription($order = Criteria::ASC) Order by the description column * @method ChildOrderProductTaxQuery orderByAmount($order = Criteria::ASC) Order by the amount column + * @method ChildOrderProductTaxQuery orderByPromoAmount($order = Criteria::ASC) Order by the promo_amount column * @method ChildOrderProductTaxQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildOrderProductTaxQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -34,6 +35,7 @@ use Thelia\Model\Map\OrderProductTaxTableMap; * @method ChildOrderProductTaxQuery groupByTitle() Group by the title column * @method ChildOrderProductTaxQuery groupByDescription() Group by the description column * @method ChildOrderProductTaxQuery groupByAmount() Group by the amount column + * @method ChildOrderProductTaxQuery groupByPromoAmount() Group by the promo_amount column * @method ChildOrderProductTaxQuery groupByCreatedAt() Group by the created_at column * @method ChildOrderProductTaxQuery groupByUpdatedAt() Group by the updated_at column * @@ -53,6 +55,7 @@ use Thelia\Model\Map\OrderProductTaxTableMap; * @method ChildOrderProductTax findOneByTitle(string $title) Return the first ChildOrderProductTax filtered by the title column * @method ChildOrderProductTax findOneByDescription(string $description) Return the first ChildOrderProductTax filtered by the description column * @method ChildOrderProductTax findOneByAmount(double $amount) Return the first ChildOrderProductTax filtered by the amount column + * @method ChildOrderProductTax findOneByPromoAmount(double $promo_amount) Return the first ChildOrderProductTax filtered by the promo_amount column * @method ChildOrderProductTax findOneByCreatedAt(string $created_at) Return the first ChildOrderProductTax filtered by the created_at column * @method ChildOrderProductTax findOneByUpdatedAt(string $updated_at) Return the first ChildOrderProductTax filtered by the updated_at column * @@ -61,6 +64,7 @@ use Thelia\Model\Map\OrderProductTaxTableMap; * @method array findByTitle(string $title) Return ChildOrderProductTax objects filtered by the title column * @method array findByDescription(string $description) Return ChildOrderProductTax objects filtered by the description column * @method array findByAmount(double $amount) Return ChildOrderProductTax objects filtered by the amount column + * @method array findByPromoAmount(double $promo_amount) Return ChildOrderProductTax objects filtered by the promo_amount column * @method array findByCreatedAt(string $created_at) Return ChildOrderProductTax objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildOrderProductTax objects filtered by the updated_at column * @@ -151,7 +155,7 @@ abstract class OrderProductTaxQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, ORDER_PRODUCT_ID, TITLE, DESCRIPTION, AMOUNT, CREATED_AT, UPDATED_AT FROM order_product_tax WHERE ID = :p0'; + $sql = 'SELECT ID, ORDER_PRODUCT_ID, TITLE, DESCRIPTION, AMOUNT, PROMO_AMOUNT, CREATED_AT, UPDATED_AT FROM order_product_tax WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -423,6 +427,47 @@ abstract class OrderProductTaxQuery extends ModelCriteria return $this->addUsingAlias(OrderProductTaxTableMap::AMOUNT, $amount, $comparison); } + /** + * Filter the query on the promo_amount column + * + * Example usage: + * + * $query->filterByPromoAmount(1234); // WHERE promo_amount = 1234 + * $query->filterByPromoAmount(array(12, 34)); // WHERE promo_amount IN (12, 34) + * $query->filterByPromoAmount(array('min' => 12)); // WHERE promo_amount > 12 + * + * + * @param mixed $promoAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderProductTaxQuery The current query, for fluid interface + */ + public function filterByPromoAmount($promoAmount = null, $comparison = null) + { + if (is_array($promoAmount)) { + $useMinMax = false; + if (isset($promoAmount['min'])) { + $this->addUsingAlias(OrderProductTaxTableMap::PROMO_AMOUNT, $promoAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($promoAmount['max'])) { + $this->addUsingAlias(OrderProductTaxTableMap::PROMO_AMOUNT, $promoAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderProductTaxTableMap::PROMO_AMOUNT, $promoAmount, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/ProductSaleElements.php b/core/lib/Thelia/Model/Base/ProductSaleElements.php index fa887dc8a..eb6aa2b1a 100644 --- a/core/lib/Thelia/Model/Base/ProductSaleElements.php +++ b/core/lib/Thelia/Model/Base/ProductSaleElements.php @@ -103,10 +103,18 @@ abstract class ProductSaleElements implements ActiveRecordInterface /** * The value for the weight field. + * Note: this column has a database default value of: 0 * @var double */ protected $weight; + /** + * The value for the is_default field. + * Note: this column has a database default value of: false + * @var boolean + */ + protected $is_default; + /** * The value for the created_at field. * @var string @@ -178,6 +186,8 @@ abstract class ProductSaleElements implements ActiveRecordInterface { $this->promo = 0; $this->newness = 0; + $this->weight = 0; + $this->is_default = false; } /** @@ -513,6 +523,17 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this->weight; } + /** + * Get the [is_default] column value. + * + * @return boolean + */ + public function getIsDefault() + { + + return $this->is_default; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -704,6 +725,35 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this; } // setWeight() + /** + * Sets the value of the [is_default] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \Thelia\Model\ProductSaleElements The current object (for fluent API support) + */ + public function setIsDefault($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->is_default !== $v) { + $this->is_default = $v; + $this->modifiedColumns[] = ProductSaleElementsTableMap::IS_DEFAULT; + } + + + return $this; + } // setIsDefault() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -764,6 +814,14 @@ abstract class ProductSaleElements implements ActiveRecordInterface return false; } + if ($this->weight !== 0) { + return false; + } + + if ($this->is_default !== false) { + return false; + } + // otherwise, everything was equal, so return TRUE return true; } // hasOnlyDefaultValues() @@ -812,13 +870,16 @@ abstract class ProductSaleElements implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductSaleElementsTableMap::translateFieldName('Weight', TableMap::TYPE_PHPNAME, $indexType)]; $this->weight = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('IsDefault', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_default = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductSaleElementsTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -831,7 +892,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 9; // 9 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 10; // 10 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\ProductSaleElements object", 0, $e); @@ -1145,6 +1206,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface if ($this->isColumnModified(ProductSaleElementsTableMap::WEIGHT)) { $modifiedColumns[':p' . $index++] = 'WEIGHT'; } + if ($this->isColumnModified(ProductSaleElementsTableMap::IS_DEFAULT)) { + $modifiedColumns[':p' . $index++] = 'IS_DEFAULT'; + } if ($this->isColumnModified(ProductSaleElementsTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1183,6 +1247,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface case 'WEIGHT': $stmt->bindValue($identifier, $this->weight, PDO::PARAM_STR); break; + case 'IS_DEFAULT': + $stmt->bindValue($identifier, (int) $this->is_default, PDO::PARAM_INT); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1273,9 +1340,12 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this->getWeight(); break; case 7: - return $this->getCreatedAt(); + return $this->getIsDefault(); break; case 8: + return $this->getCreatedAt(); + break; + case 9: return $this->getUpdatedAt(); break; default: @@ -1314,8 +1384,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface $keys[4] => $this->getPromo(), $keys[5] => $this->getNewness(), $keys[6] => $this->getWeight(), - $keys[7] => $this->getCreatedAt(), - $keys[8] => $this->getUpdatedAt(), + $keys[7] => $this->getIsDefault(), + $keys[8] => $this->getCreatedAt(), + $keys[9] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1392,9 +1463,12 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->setWeight($value); break; case 7: - $this->setCreatedAt($value); + $this->setIsDefault($value); break; case 8: + $this->setCreatedAt($value); + break; + case 9: $this->setUpdatedAt($value); break; } // switch() @@ -1428,8 +1502,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface if (array_key_exists($keys[4], $arr)) $this->setPromo($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setNewness($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setWeight($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]); + if (array_key_exists($keys[7], $arr)) $this->setIsDefault($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]); } /** @@ -1448,6 +1523,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface if ($this->isColumnModified(ProductSaleElementsTableMap::PROMO)) $criteria->add(ProductSaleElementsTableMap::PROMO, $this->promo); if ($this->isColumnModified(ProductSaleElementsTableMap::NEWNESS)) $criteria->add(ProductSaleElementsTableMap::NEWNESS, $this->newness); if ($this->isColumnModified(ProductSaleElementsTableMap::WEIGHT)) $criteria->add(ProductSaleElementsTableMap::WEIGHT, $this->weight); + if ($this->isColumnModified(ProductSaleElementsTableMap::IS_DEFAULT)) $criteria->add(ProductSaleElementsTableMap::IS_DEFAULT, $this->is_default); if ($this->isColumnModified(ProductSaleElementsTableMap::CREATED_AT)) $criteria->add(ProductSaleElementsTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ProductSaleElementsTableMap::UPDATED_AT)) $criteria->add(ProductSaleElementsTableMap::UPDATED_AT, $this->updated_at); @@ -1519,6 +1595,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $copyObj->setPromo($this->getPromo()); $copyObj->setNewness($this->getNewness()); $copyObj->setWeight($this->getWeight()); + $copyObj->setIsDefault($this->getIsDefault()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -2445,6 +2522,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->promo = null; $this->newness = null; $this->weight = null; + $this->is_default = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php index 6e9068002..c8201ed0b 100644 --- a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php +++ b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php @@ -28,6 +28,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElementsQuery orderByPromo($order = Criteria::ASC) Order by the promo column * @method ChildProductSaleElementsQuery orderByNewness($order = Criteria::ASC) Order by the newness column * @method ChildProductSaleElementsQuery orderByWeight($order = Criteria::ASC) Order by the weight column + * @method ChildProductSaleElementsQuery orderByIsDefault($order = Criteria::ASC) Order by the is_default column * @method ChildProductSaleElementsQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildProductSaleElementsQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -38,6 +39,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElementsQuery groupByPromo() Group by the promo column * @method ChildProductSaleElementsQuery groupByNewness() Group by the newness column * @method ChildProductSaleElementsQuery groupByWeight() Group by the weight column + * @method ChildProductSaleElementsQuery groupByIsDefault() Group by the is_default column * @method ChildProductSaleElementsQuery groupByCreatedAt() Group by the created_at column * @method ChildProductSaleElementsQuery groupByUpdatedAt() Group by the updated_at column * @@ -71,6 +73,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElements findOneByPromo(int $promo) Return the first ChildProductSaleElements filtered by the promo column * @method ChildProductSaleElements findOneByNewness(int $newness) Return the first ChildProductSaleElements filtered by the newness column * @method ChildProductSaleElements findOneByWeight(double $weight) Return the first ChildProductSaleElements filtered by the weight column + * @method ChildProductSaleElements findOneByIsDefault(boolean $is_default) Return the first ChildProductSaleElements filtered by the is_default column * @method ChildProductSaleElements findOneByCreatedAt(string $created_at) Return the first ChildProductSaleElements filtered by the created_at column * @method ChildProductSaleElements findOneByUpdatedAt(string $updated_at) Return the first ChildProductSaleElements filtered by the updated_at column * @@ -81,6 +84,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method array findByPromo(int $promo) Return ChildProductSaleElements objects filtered by the promo column * @method array findByNewness(int $newness) Return ChildProductSaleElements objects filtered by the newness column * @method array findByWeight(double $weight) Return ChildProductSaleElements objects filtered by the weight column + * @method array findByIsDefault(boolean $is_default) Return ChildProductSaleElements objects filtered by the is_default column * @method array findByCreatedAt(string $created_at) Return ChildProductSaleElements objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildProductSaleElements objects filtered by the updated_at column * @@ -171,7 +175,7 @@ abstract class ProductSaleElementsQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, PRODUCT_ID, REF, QUANTITY, PROMO, NEWNESS, WEIGHT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0'; + $sql = 'SELECT ID, PRODUCT_ID, REF, QUANTITY, PROMO, NEWNESS, WEIGHT, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -537,6 +541,33 @@ abstract class ProductSaleElementsQuery extends ModelCriteria return $this->addUsingAlias(ProductSaleElementsTableMap::WEIGHT, $weight, $comparison); } + /** + * Filter the query on the is_default column + * + * Example usage: + * + * $query->filterByIsDefault(true); // WHERE is_default = true + * $query->filterByIsDefault('yes'); // WHERE is_default = true + * + * + * @param boolean|string $isDefault The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildProductSaleElementsQuery The current query, for fluid interface + */ + public function filterByIsDefault($isDefault = null, $comparison = null) + { + if (is_string($isDefault)) { + $is_default = in_array(strtolower($isDefault), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(ProductSaleElementsTableMap::IS_DEFAULT, $isDefault, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php index 04d3a9a4a..1df6d56c1 100644 --- a/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php +++ b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php @@ -57,7 +57,7 @@ class AttributeTemplateTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 5; + const NUM_COLUMNS = 6; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class AttributeTemplateTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 5; + const NUM_HYDRATE_COLUMNS = 6; /** * the column name for the ID field @@ -84,6 +84,11 @@ class AttributeTemplateTableMap extends TableMap */ const TEMPLATE_ID = 'attribute_template.TEMPLATE_ID'; + /** + * the column name for the POSITION field + */ + const POSITION = 'attribute_template.POSITION'; + /** * the column name for the CREATED_AT field */ @@ -106,12 +111,12 @@ class AttributeTemplateTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::POSITION, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -121,12 +126,12 @@ class AttributeTemplateTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::CREATED_AT => 3, AttributeTemplateTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::POSITION => 3, AttributeTemplateTableMap::CREATED_AT => 4, AttributeTemplateTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -149,6 +154,7 @@ class AttributeTemplateTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER', 'attribute', 'ID', true, null, null); $this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -316,12 +322,14 @@ class AttributeTemplateTableMap extends TableMap $criteria->addSelectColumn(AttributeTemplateTableMap::ID); $criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_ID); $criteria->addSelectColumn(AttributeTemplateTableMap::TEMPLATE_ID); + $criteria->addSelectColumn(AttributeTemplateTableMap::POSITION); $criteria->addSelectColumn(AttributeTemplateTableMap::CREATED_AT); $criteria->addSelectColumn(AttributeTemplateTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_ID'); $criteria->addSelectColumn($alias . '.TEMPLATE_ID'); + $criteria->addSelectColumn($alias . '.POSITION'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/CouponTableMap.php b/core/lib/Thelia/Model/Map/CouponTableMap.php index bd9079be6..70d689a2a 100644 --- a/core/lib/Thelia/Model/Map/CouponTableMap.php +++ b/core/lib/Thelia/Model/Map/CouponTableMap.php @@ -89,11 +89,6 @@ class CouponTableMap extends TableMap */ const AMOUNT = 'coupon.AMOUNT'; - /** - * the column name for the IS_USED field - */ - const IS_USED = 'coupon.IS_USED'; - /** * the column name for the IS_ENABLED field */ @@ -105,9 +100,9 @@ class CouponTableMap extends TableMap const EXPIRATION_DATE = 'coupon.EXPIRATION_DATE'; /** - * the column name for the SERIALIZED_RULES field + * the column name for the MAX_USAGE field */ - const SERIALIZED_RULES = 'coupon.SERIALIZED_RULES'; + const MAX_USAGE = 'coupon.MAX_USAGE'; /** * the column name for the IS_CUMULATIVE field @@ -119,16 +114,21 @@ class CouponTableMap extends TableMap */ const IS_REMOVING_POSTAGE = 'coupon.IS_REMOVING_POSTAGE'; - /** - * the column name for the MAX_USAGE field - */ - const MAX_USAGE = 'coupon.MAX_USAGE'; - /** * the column name for the IS_AVAILABLE_ON_SPECIAL_OFFERS field */ const IS_AVAILABLE_ON_SPECIAL_OFFERS = 'coupon.IS_AVAILABLE_ON_SPECIAL_OFFERS'; + /** + * the column name for the IS_USED field + */ + const IS_USED = 'coupon.IS_USED'; + + /** + * the column name for the SERIALIZED_CONDITIONS field + */ + const SERIALIZED_CONDITIONS = 'coupon.SERIALIZED_CONDITIONS'; + /** * the column name for the CREATED_AT field */ @@ -165,11 +165,11 @@ class CouponTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsUsed', 'IsEnabled', 'ExpirationDate', 'SerializedRules', 'IsCumulative', 'IsRemovingPostage', 'MaxUsage', 'IsAvailableOnSpecialOffers', 'CreatedAt', 'UpdatedAt', 'Version', ), - self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isUsed', 'isEnabled', 'expirationDate', 'serializedRules', 'isCumulative', 'isRemovingPostage', 'maxUsage', 'isAvailableOnSpecialOffers', 'createdAt', 'updatedAt', 'version', ), - self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::AMOUNT, CouponTableMap::IS_USED, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::SERIALIZED_RULES, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ), - self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_USED', 'IS_ENABLED', 'EXPIRATION_DATE', 'SERIALIZED_RULES', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'MAX_USAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), - self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_used', 'is_enabled', 'expiration_date', 'serialized_rules', 'is_cumulative', 'is_removing_postage', 'max_usage', 'is_available_on_special_offers', 'created_at', 'updated_at', 'version', ), + self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), + self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::AMOUNT, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::IS_USED, CouponTableMap::SERIALIZED_CONDITIONS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -180,11 +180,11 @@ class CouponTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsUsed' => 4, 'IsEnabled' => 5, 'ExpirationDate' => 6, 'SerializedRules' => 7, 'IsCumulative' => 8, 'IsRemovingPostage' => 9, 'MaxUsage' => 10, 'IsAvailableOnSpecialOffers' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isUsed' => 4, 'isEnabled' => 5, 'expirationDate' => 6, 'serializedRules' => 7, 'isCumulative' => 8, 'isRemovingPostage' => 9, 'maxUsage' => 10, 'isAvailableOnSpecialOffers' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), - self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::AMOUNT => 3, CouponTableMap::IS_USED => 4, CouponTableMap::IS_ENABLED => 5, CouponTableMap::EXPIRATION_DATE => 6, CouponTableMap::SERIALIZED_RULES => 7, CouponTableMap::IS_CUMULATIVE => 8, CouponTableMap::IS_REMOVING_POSTAGE => 9, CouponTableMap::MAX_USAGE => 10, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_USED' => 4, 'IS_ENABLED' => 5, 'EXPIRATION_DATE' => 6, 'SERIALIZED_RULES' => 7, 'IS_CUMULATIVE' => 8, 'IS_REMOVING_POSTAGE' => 9, 'MAX_USAGE' => 10, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), - self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_used' => 4, 'is_enabled' => 5, 'expiration_date' => 6, 'serialized_rules' => 7, 'is_cumulative' => 8, 'is_removing_postage' => 9, 'max_usage' => 10, 'is_available_on_special_offers' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), + self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::AMOUNT => 3, CouponTableMap::IS_ENABLED => 4, CouponTableMap::EXPIRATION_DATE => 5, CouponTableMap::MAX_USAGE => 6, CouponTableMap::IS_CUMULATIVE => 7, CouponTableMap::IS_REMOVING_POSTAGE => 8, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponTableMap::IS_USED => 10, CouponTableMap::SERIALIZED_CONDITIONS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -208,14 +208,14 @@ class CouponTableMap extends TableMap $this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null); $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null); $this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null); - $this->addColumn('IS_USED', 'IsUsed', 'TINYINT', true, null, null); - $this->addColumn('IS_ENABLED', 'IsEnabled', 'TINYINT', true, null, null); + $this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null); $this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null); - $this->addColumn('SERIALIZED_RULES', 'SerializedRules', 'LONGVARCHAR', true, null, null); - $this->addColumn('IS_CUMULATIVE', 'IsCumulative', 'TINYINT', true, null, null); - $this->addColumn('IS_REMOVING_POSTAGE', 'IsRemovingPostage', 'TINYINT', true, null, null); $this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null); + $this->addColumn('IS_CUMULATIVE', 'IsCumulative', 'BOOLEAN', true, 1, null); + $this->addColumn('IS_REMOVING_POSTAGE', 'IsRemovingPostage', 'BOOLEAN', true, 1, null); $this->addColumn('IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IsAvailableOnSpecialOffers', 'BOOLEAN', true, 1, null); + $this->addColumn('IS_USED', 'IsUsed', 'BOOLEAN', true, 1, null); + $this->addColumn('SERIALIZED_CONDITIONS', 'SerializedConditions', 'LONGVARCHAR', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0); @@ -397,14 +397,14 @@ class CouponTableMap extends TableMap $criteria->addSelectColumn(CouponTableMap::CODE); $criteria->addSelectColumn(CouponTableMap::TYPE); $criteria->addSelectColumn(CouponTableMap::AMOUNT); - $criteria->addSelectColumn(CouponTableMap::IS_USED); $criteria->addSelectColumn(CouponTableMap::IS_ENABLED); $criteria->addSelectColumn(CouponTableMap::EXPIRATION_DATE); - $criteria->addSelectColumn(CouponTableMap::SERIALIZED_RULES); + $criteria->addSelectColumn(CouponTableMap::MAX_USAGE); $criteria->addSelectColumn(CouponTableMap::IS_CUMULATIVE); $criteria->addSelectColumn(CouponTableMap::IS_REMOVING_POSTAGE); - $criteria->addSelectColumn(CouponTableMap::MAX_USAGE); $criteria->addSelectColumn(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS); + $criteria->addSelectColumn(CouponTableMap::IS_USED); + $criteria->addSelectColumn(CouponTableMap::SERIALIZED_CONDITIONS); $criteria->addSelectColumn(CouponTableMap::CREATED_AT); $criteria->addSelectColumn(CouponTableMap::UPDATED_AT); $criteria->addSelectColumn(CouponTableMap::VERSION); @@ -413,14 +413,14 @@ class CouponTableMap extends TableMap $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.TYPE'); $criteria->addSelectColumn($alias . '.AMOUNT'); - $criteria->addSelectColumn($alias . '.IS_USED'); $criteria->addSelectColumn($alias . '.IS_ENABLED'); $criteria->addSelectColumn($alias . '.EXPIRATION_DATE'); - $criteria->addSelectColumn($alias . '.SERIALIZED_RULES'); + $criteria->addSelectColumn($alias . '.MAX_USAGE'); $criteria->addSelectColumn($alias . '.IS_CUMULATIVE'); $criteria->addSelectColumn($alias . '.IS_REMOVING_POSTAGE'); - $criteria->addSelectColumn($alias . '.MAX_USAGE'); $criteria->addSelectColumn($alias . '.IS_AVAILABLE_ON_SPECIAL_OFFERS'); + $criteria->addSelectColumn($alias . '.IS_USED'); + $criteria->addSelectColumn($alias . '.SERIALIZED_CONDITIONS'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.VERSION'); diff --git a/core/lib/Thelia/Model/Map/CouponVersionTableMap.php b/core/lib/Thelia/Model/Map/CouponVersionTableMap.php index 30ce279b8..91e774912 100644 --- a/core/lib/Thelia/Model/Map/CouponVersionTableMap.php +++ b/core/lib/Thelia/Model/Map/CouponVersionTableMap.php @@ -89,11 +89,6 @@ class CouponVersionTableMap extends TableMap */ const AMOUNT = 'coupon_version.AMOUNT'; - /** - * the column name for the IS_USED field - */ - const IS_USED = 'coupon_version.IS_USED'; - /** * the column name for the IS_ENABLED field */ @@ -105,9 +100,9 @@ class CouponVersionTableMap extends TableMap const EXPIRATION_DATE = 'coupon_version.EXPIRATION_DATE'; /** - * the column name for the SERIALIZED_RULES field + * the column name for the MAX_USAGE field */ - const SERIALIZED_RULES = 'coupon_version.SERIALIZED_RULES'; + const MAX_USAGE = 'coupon_version.MAX_USAGE'; /** * the column name for the IS_CUMULATIVE field @@ -119,16 +114,21 @@ class CouponVersionTableMap extends TableMap */ const IS_REMOVING_POSTAGE = 'coupon_version.IS_REMOVING_POSTAGE'; - /** - * the column name for the MAX_USAGE field - */ - const MAX_USAGE = 'coupon_version.MAX_USAGE'; - /** * the column name for the IS_AVAILABLE_ON_SPECIAL_OFFERS field */ const IS_AVAILABLE_ON_SPECIAL_OFFERS = 'coupon_version.IS_AVAILABLE_ON_SPECIAL_OFFERS'; + /** + * the column name for the IS_USED field + */ + const IS_USED = 'coupon_version.IS_USED'; + + /** + * the column name for the SERIALIZED_CONDITIONS field + */ + const SERIALIZED_CONDITIONS = 'coupon_version.SERIALIZED_CONDITIONS'; + /** * the column name for the CREATED_AT field */ @@ -156,11 +156,11 @@ class CouponVersionTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsUsed', 'IsEnabled', 'ExpirationDate', 'SerializedRules', 'IsCumulative', 'IsRemovingPostage', 'MaxUsage', 'IsAvailableOnSpecialOffers', 'CreatedAt', 'UpdatedAt', 'Version', ), - self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isUsed', 'isEnabled', 'expirationDate', 'serializedRules', 'isCumulative', 'isRemovingPostage', 'maxUsage', 'isAvailableOnSpecialOffers', 'createdAt', 'updatedAt', 'version', ), - self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::AMOUNT, CouponVersionTableMap::IS_USED, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::SERIALIZED_RULES, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ), - self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_USED', 'IS_ENABLED', 'EXPIRATION_DATE', 'SERIALIZED_RULES', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'MAX_USAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), - self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_used', 'is_enabled', 'expiration_date', 'serialized_rules', 'is_cumulative', 'is_removing_postage', 'max_usage', 'is_available_on_special_offers', 'created_at', 'updated_at', 'version', ), + self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), + self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::AMOUNT, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::IS_USED, CouponVersionTableMap::SERIALIZED_CONDITIONS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -171,11 +171,11 @@ class CouponVersionTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsUsed' => 4, 'IsEnabled' => 5, 'ExpirationDate' => 6, 'SerializedRules' => 7, 'IsCumulative' => 8, 'IsRemovingPostage' => 9, 'MaxUsage' => 10, 'IsAvailableOnSpecialOffers' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isUsed' => 4, 'isEnabled' => 5, 'expirationDate' => 6, 'serializedRules' => 7, 'isCumulative' => 8, 'isRemovingPostage' => 9, 'maxUsage' => 10, 'isAvailableOnSpecialOffers' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), - self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::AMOUNT => 3, CouponVersionTableMap::IS_USED => 4, CouponVersionTableMap::IS_ENABLED => 5, CouponVersionTableMap::EXPIRATION_DATE => 6, CouponVersionTableMap::SERIALIZED_RULES => 7, CouponVersionTableMap::IS_CUMULATIVE => 8, CouponVersionTableMap::IS_REMOVING_POSTAGE => 9, CouponVersionTableMap::MAX_USAGE => 10, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_USED' => 4, 'IS_ENABLED' => 5, 'EXPIRATION_DATE' => 6, 'SERIALIZED_RULES' => 7, 'IS_CUMULATIVE' => 8, 'IS_REMOVING_POSTAGE' => 9, 'MAX_USAGE' => 10, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), - self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_used' => 4, 'is_enabled' => 5, 'expiration_date' => 6, 'serialized_rules' => 7, 'is_cumulative' => 8, 'is_removing_postage' => 9, 'max_usage' => 10, 'is_available_on_special_offers' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), + self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::AMOUNT => 3, CouponVersionTableMap::IS_ENABLED => 4, CouponVersionTableMap::EXPIRATION_DATE => 5, CouponVersionTableMap::MAX_USAGE => 6, CouponVersionTableMap::IS_CUMULATIVE => 7, CouponVersionTableMap::IS_REMOVING_POSTAGE => 8, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponVersionTableMap::IS_USED => 10, CouponVersionTableMap::SERIALIZED_CONDITIONS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -199,14 +199,14 @@ class CouponVersionTableMap extends TableMap $this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null); $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null); $this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null); - $this->addColumn('IS_USED', 'IsUsed', 'TINYINT', true, null, null); - $this->addColumn('IS_ENABLED', 'IsEnabled', 'TINYINT', true, null, null); + $this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null); $this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null); - $this->addColumn('SERIALIZED_RULES', 'SerializedRules', 'LONGVARCHAR', true, null, null); - $this->addColumn('IS_CUMULATIVE', 'IsCumulative', 'TINYINT', true, null, null); - $this->addColumn('IS_REMOVING_POSTAGE', 'IsRemovingPostage', 'TINYINT', true, null, null); $this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null); + $this->addColumn('IS_CUMULATIVE', 'IsCumulative', 'BOOLEAN', true, 1, null); + $this->addColumn('IS_REMOVING_POSTAGE', 'IsRemovingPostage', 'BOOLEAN', true, 1, null); $this->addColumn('IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IsAvailableOnSpecialOffers', 'BOOLEAN', true, 1, null); + $this->addColumn('IS_USED', 'IsUsed', 'BOOLEAN', true, 1, null); + $this->addColumn('SERIALIZED_CONDITIONS', 'SerializedConditions', 'LONGVARCHAR', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); $this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0); @@ -411,14 +411,14 @@ class CouponVersionTableMap extends TableMap $criteria->addSelectColumn(CouponVersionTableMap::CODE); $criteria->addSelectColumn(CouponVersionTableMap::TYPE); $criteria->addSelectColumn(CouponVersionTableMap::AMOUNT); - $criteria->addSelectColumn(CouponVersionTableMap::IS_USED); $criteria->addSelectColumn(CouponVersionTableMap::IS_ENABLED); $criteria->addSelectColumn(CouponVersionTableMap::EXPIRATION_DATE); - $criteria->addSelectColumn(CouponVersionTableMap::SERIALIZED_RULES); + $criteria->addSelectColumn(CouponVersionTableMap::MAX_USAGE); $criteria->addSelectColumn(CouponVersionTableMap::IS_CUMULATIVE); $criteria->addSelectColumn(CouponVersionTableMap::IS_REMOVING_POSTAGE); - $criteria->addSelectColumn(CouponVersionTableMap::MAX_USAGE); $criteria->addSelectColumn(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS); + $criteria->addSelectColumn(CouponVersionTableMap::IS_USED); + $criteria->addSelectColumn(CouponVersionTableMap::SERIALIZED_CONDITIONS); $criteria->addSelectColumn(CouponVersionTableMap::CREATED_AT); $criteria->addSelectColumn(CouponVersionTableMap::UPDATED_AT); $criteria->addSelectColumn(CouponVersionTableMap::VERSION); @@ -427,14 +427,14 @@ class CouponVersionTableMap extends TableMap $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.TYPE'); $criteria->addSelectColumn($alias . '.AMOUNT'); - $criteria->addSelectColumn($alias . '.IS_USED'); $criteria->addSelectColumn($alias . '.IS_ENABLED'); $criteria->addSelectColumn($alias . '.EXPIRATION_DATE'); - $criteria->addSelectColumn($alias . '.SERIALIZED_RULES'); + $criteria->addSelectColumn($alias . '.MAX_USAGE'); $criteria->addSelectColumn($alias . '.IS_CUMULATIVE'); $criteria->addSelectColumn($alias . '.IS_REMOVING_POSTAGE'); - $criteria->addSelectColumn($alias . '.MAX_USAGE'); $criteria->addSelectColumn($alias . '.IS_AVAILABLE_ON_SPECIAL_OFFERS'); + $criteria->addSelectColumn($alias . '.IS_USED'); + $criteria->addSelectColumn($alias . '.SERIALIZED_CONDITIONS'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.VERSION'); diff --git a/core/lib/Thelia/Model/Map/FeatureProductTableMap.php b/core/lib/Thelia/Model/Map/FeatureProductTableMap.php index f0263b47c..9db4ec441 100644 --- a/core/lib/Thelia/Model/Map/FeatureProductTableMap.php +++ b/core/lib/Thelia/Model/Map/FeatureProductTableMap.php @@ -90,9 +90,9 @@ class FeatureProductTableMap extends TableMap const FEATURE_AV_ID = 'feature_product.FEATURE_AV_ID'; /** - * the column name for the BY_DEFAULT field + * the column name for the FREE_TEXT_VALUE field */ - const BY_DEFAULT = 'feature_product.BY_DEFAULT'; + const FREE_TEXT_VALUE = 'feature_product.FREE_TEXT_VALUE'; /** * the column name for the POSITION field @@ -121,11 +121,11 @@ class FeatureProductTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'ProductId', 'FeatureId', 'FeatureAvId', 'ByDefault', 'Position', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'featureId', 'featureAvId', 'byDefault', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(FeatureProductTableMap::ID, FeatureProductTableMap::PRODUCT_ID, FeatureProductTableMap::FEATURE_ID, FeatureProductTableMap::FEATURE_AV_ID, FeatureProductTableMap::BY_DEFAULT, FeatureProductTableMap::POSITION, FeatureProductTableMap::CREATED_AT, FeatureProductTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'FEATURE_ID', 'FEATURE_AV_ID', 'BY_DEFAULT', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'product_id', 'feature_id', 'feature_av_id', 'by_default', 'position', 'created_at', 'updated_at', ), + self::TYPE_PHPNAME => array('Id', 'ProductId', 'FeatureId', 'FeatureAvId', 'FreeTextValue', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'featureId', 'featureAvId', 'freeTextValue', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(FeatureProductTableMap::ID, FeatureProductTableMap::PRODUCT_ID, FeatureProductTableMap::FEATURE_ID, FeatureProductTableMap::FEATURE_AV_ID, FeatureProductTableMap::FREE_TEXT_VALUE, FeatureProductTableMap::POSITION, FeatureProductTableMap::CREATED_AT, FeatureProductTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'FEATURE_ID', 'FEATURE_AV_ID', 'FREE_TEXT_VALUE', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'product_id', 'feature_id', 'feature_av_id', 'free_text_value', 'position', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); @@ -136,11 +136,11 @@ class FeatureProductTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'FeatureId' => 2, 'FeatureAvId' => 3, 'ByDefault' => 4, 'Position' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'featureId' => 2, 'featureAvId' => 3, 'byDefault' => 4, 'position' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), - self::TYPE_COLNAME => array(FeatureProductTableMap::ID => 0, FeatureProductTableMap::PRODUCT_ID => 1, FeatureProductTableMap::FEATURE_ID => 2, FeatureProductTableMap::FEATURE_AV_ID => 3, FeatureProductTableMap::BY_DEFAULT => 4, FeatureProductTableMap::POSITION => 5, FeatureProductTableMap::CREATED_AT => 6, FeatureProductTableMap::UPDATED_AT => 7, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'FEATURE_ID' => 2, 'FEATURE_AV_ID' => 3, 'BY_DEFAULT' => 4, 'POSITION' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), - self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'feature_id' => 2, 'feature_av_id' => 3, 'by_default' => 4, 'position' => 5, 'created_at' => 6, 'updated_at' => 7, ), + self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'FeatureId' => 2, 'FeatureAvId' => 3, 'FreeTextValue' => 4, 'Position' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'featureId' => 2, 'featureAvId' => 3, 'freeTextValue' => 4, 'position' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), + self::TYPE_COLNAME => array(FeatureProductTableMap::ID => 0, FeatureProductTableMap::PRODUCT_ID => 1, FeatureProductTableMap::FEATURE_ID => 2, FeatureProductTableMap::FEATURE_AV_ID => 3, FeatureProductTableMap::FREE_TEXT_VALUE => 4, FeatureProductTableMap::POSITION => 5, FeatureProductTableMap::CREATED_AT => 6, FeatureProductTableMap::UPDATED_AT => 7, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'FEATURE_ID' => 2, 'FEATURE_AV_ID' => 3, 'FREE_TEXT_VALUE' => 4, 'POSITION' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), + self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'feature_id' => 2, 'feature_av_id' => 3, 'free_text_value' => 4, 'position' => 5, 'created_at' => 6, 'updated_at' => 7, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); @@ -164,7 +164,7 @@ class FeatureProductTableMap extends TableMap $this->addForeignKey('PRODUCT_ID', 'ProductId', 'INTEGER', 'product', 'ID', true, null, null); $this->addForeignKey('FEATURE_ID', 'FeatureId', 'INTEGER', 'feature', 'ID', true, null, null); $this->addForeignKey('FEATURE_AV_ID', 'FeatureAvId', 'INTEGER', 'feature_av', 'ID', false, null, null); - $this->addColumn('BY_DEFAULT', 'ByDefault', 'VARCHAR', false, 255, null); + $this->addColumn('FREE_TEXT_VALUE', 'FreeTextValue', 'LONGVARCHAR', false, null, null); $this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); @@ -335,7 +335,7 @@ class FeatureProductTableMap extends TableMap $criteria->addSelectColumn(FeatureProductTableMap::PRODUCT_ID); $criteria->addSelectColumn(FeatureProductTableMap::FEATURE_ID); $criteria->addSelectColumn(FeatureProductTableMap::FEATURE_AV_ID); - $criteria->addSelectColumn(FeatureProductTableMap::BY_DEFAULT); + $criteria->addSelectColumn(FeatureProductTableMap::FREE_TEXT_VALUE); $criteria->addSelectColumn(FeatureProductTableMap::POSITION); $criteria->addSelectColumn(FeatureProductTableMap::CREATED_AT); $criteria->addSelectColumn(FeatureProductTableMap::UPDATED_AT); @@ -344,7 +344,7 @@ class FeatureProductTableMap extends TableMap $criteria->addSelectColumn($alias . '.PRODUCT_ID'); $criteria->addSelectColumn($alias . '.FEATURE_ID'); $criteria->addSelectColumn($alias . '.FEATURE_AV_ID'); - $criteria->addSelectColumn($alias . '.BY_DEFAULT'); + $criteria->addSelectColumn($alias . '.FREE_TEXT_VALUE'); $criteria->addSelectColumn($alias . '.POSITION'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); diff --git a/core/lib/Thelia/Model/Map/FeatureTableMap.php b/core/lib/Thelia/Model/Map/FeatureTableMap.php index 067a242a3..c6a29e2f4 100644 --- a/core/lib/Thelia/Model/Map/FeatureTableMap.php +++ b/core/lib/Thelia/Model/Map/FeatureTableMap.php @@ -156,7 +156,7 @@ class FeatureTableMap extends TableMap // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('VISIBLE', 'Visible', 'INTEGER', false, null, 0); - $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() diff --git a/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php b/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php index abb1a98b7..68f3b9a24 100644 --- a/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php +++ b/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php @@ -57,7 +57,7 @@ class FeatureTemplateTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 5; + const NUM_COLUMNS = 6; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class FeatureTemplateTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 5; + const NUM_HYDRATE_COLUMNS = 6; /** * the column name for the ID field @@ -84,6 +84,11 @@ class FeatureTemplateTableMap extends TableMap */ const TEMPLATE_ID = 'feature_template.TEMPLATE_ID'; + /** + * the column name for the POSITION field + */ + const POSITION = 'feature_template.POSITION'; + /** * the column name for the CREATED_AT field */ @@ -106,12 +111,12 @@ class FeatureTemplateTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'FeatureId', 'TemplateId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'featureId', 'templateId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID, FeatureTemplateTableMap::FEATURE_ID, FeatureTemplateTableMap::TEMPLATE_ID, FeatureTemplateTableMap::CREATED_AT, FeatureTemplateTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'FEATURE_ID', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'feature_id', 'template_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id', 'FeatureId', 'TemplateId', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'featureId', 'templateId', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID, FeatureTemplateTableMap::FEATURE_ID, FeatureTemplateTableMap::TEMPLATE_ID, FeatureTemplateTableMap::POSITION, FeatureTemplateTableMap::CREATED_AT, FeatureTemplateTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'FEATURE_ID', 'TEMPLATE_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'feature_id', 'template_id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -121,12 +126,12 @@ class FeatureTemplateTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'FeatureId' => 1, 'TemplateId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'featureId' => 1, 'templateId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID => 0, FeatureTemplateTableMap::FEATURE_ID => 1, FeatureTemplateTableMap::TEMPLATE_ID => 2, FeatureTemplateTableMap::CREATED_AT => 3, FeatureTemplateTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'FEATURE_ID' => 1, 'TEMPLATE_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'feature_id' => 1, 'template_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id' => 0, 'FeatureId' => 1, 'TemplateId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'featureId' => 1, 'templateId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID => 0, FeatureTemplateTableMap::FEATURE_ID => 1, FeatureTemplateTableMap::TEMPLATE_ID => 2, FeatureTemplateTableMap::POSITION => 3, FeatureTemplateTableMap::CREATED_AT => 4, FeatureTemplateTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'FEATURE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'feature_id' => 1, 'template_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -149,6 +154,7 @@ class FeatureTemplateTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('FEATURE_ID', 'FeatureId', 'INTEGER', 'feature', 'ID', true, null, null); $this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -316,12 +322,14 @@ class FeatureTemplateTableMap extends TableMap $criteria->addSelectColumn(FeatureTemplateTableMap::ID); $criteria->addSelectColumn(FeatureTemplateTableMap::FEATURE_ID); $criteria->addSelectColumn(FeatureTemplateTableMap::TEMPLATE_ID); + $criteria->addSelectColumn(FeatureTemplateTableMap::POSITION); $criteria->addSelectColumn(FeatureTemplateTableMap::CREATED_AT); $criteria->addSelectColumn(FeatureTemplateTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.FEATURE_ID'); $criteria->addSelectColumn($alias . '.TEMPLATE_ID'); + $criteria->addSelectColumn($alias . '.POSITION'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/OrderProductAttributeCombinationTableMap.php b/core/lib/Thelia/Model/Map/OrderProductAttributeCombinationTableMap.php index 582bd2305..3c3aee2f9 100644 --- a/core/lib/Thelia/Model/Map/OrderProductAttributeCombinationTableMap.php +++ b/core/lib/Thelia/Model/Map/OrderProductAttributeCombinationTableMap.php @@ -95,9 +95,9 @@ class OrderProductAttributeCombinationTableMap extends TableMap const ATTRIBUTE_DESCRIPTION = 'order_product_attribute_combination.ATTRIBUTE_DESCRIPTION'; /** - * the column name for the ATTRIBUTE_POSTSCRIPTUMN field + * the column name for the ATTRIBUTE_POSTSCRIPTUM field */ - const ATTRIBUTE_POSTSCRIPTUMN = 'order_product_attribute_combination.ATTRIBUTE_POSTSCRIPTUMN'; + const ATTRIBUTE_POSTSCRIPTUM = 'order_product_attribute_combination.ATTRIBUTE_POSTSCRIPTUM'; /** * the column name for the ATTRIBUTE_AV_TITLE field @@ -141,11 +141,11 @@ class OrderProductAttributeCombinationTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'OrderProductId', 'AttributeTitle', 'AttributeChapo', 'AttributeDescription', 'AttributePostscriptumn', 'AttributeAvTitle', 'AttributeAvChapo', 'AttributeAvDescription', 'AttributeAvPostscriptum', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'orderProductId', 'attributeTitle', 'attributeChapo', 'attributeDescription', 'attributePostscriptumn', 'attributeAvTitle', 'attributeAvChapo', 'attributeAvDescription', 'attributeAvPostscriptum', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(OrderProductAttributeCombinationTableMap::ID, OrderProductAttributeCombinationTableMap::ORDER_PRODUCT_ID, OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE, OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO, OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION, OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_POSTSCRIPTUM, OrderProductAttributeCombinationTableMap::CREATED_AT, OrderProductAttributeCombinationTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'ORDER_PRODUCT_ID', 'ATTRIBUTE_TITLE', 'ATTRIBUTE_CHAPO', 'ATTRIBUTE_DESCRIPTION', 'ATTRIBUTE_POSTSCRIPTUMN', 'ATTRIBUTE_AV_TITLE', 'ATTRIBUTE_AV_CHAPO', 'ATTRIBUTE_AV_DESCRIPTION', 'ATTRIBUTE_AV_POSTSCRIPTUM', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'order_product_id', 'attribute_title', 'attribute_chapo', 'attribute_description', 'attribute_postscriptumn', 'attribute_av_title', 'attribute_av_chapo', 'attribute_av_description', 'attribute_av_postscriptum', 'created_at', 'updated_at', ), + self::TYPE_PHPNAME => array('Id', 'OrderProductId', 'AttributeTitle', 'AttributeChapo', 'AttributeDescription', 'AttributePostscriptum', 'AttributeAvTitle', 'AttributeAvChapo', 'AttributeAvDescription', 'AttributeAvPostscriptum', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'orderProductId', 'attributeTitle', 'attributeChapo', 'attributeDescription', 'attributePostscriptum', 'attributeAvTitle', 'attributeAvChapo', 'attributeAvDescription', 'attributeAvPostscriptum', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(OrderProductAttributeCombinationTableMap::ID, OrderProductAttributeCombinationTableMap::ORDER_PRODUCT_ID, OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE, OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO, OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION, OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_POSTSCRIPTUM, OrderProductAttributeCombinationTableMap::CREATED_AT, OrderProductAttributeCombinationTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'ORDER_PRODUCT_ID', 'ATTRIBUTE_TITLE', 'ATTRIBUTE_CHAPO', 'ATTRIBUTE_DESCRIPTION', 'ATTRIBUTE_POSTSCRIPTUM', 'ATTRIBUTE_AV_TITLE', 'ATTRIBUTE_AV_CHAPO', 'ATTRIBUTE_AV_DESCRIPTION', 'ATTRIBUTE_AV_POSTSCRIPTUM', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'order_product_id', 'attribute_title', 'attribute_chapo', 'attribute_description', 'attribute_postscriptum', 'attribute_av_title', 'attribute_av_chapo', 'attribute_av_description', 'attribute_av_postscriptum', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ); @@ -156,11 +156,11 @@ class OrderProductAttributeCombinationTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'OrderProductId' => 1, 'AttributeTitle' => 2, 'AttributeChapo' => 3, 'AttributeDescription' => 4, 'AttributePostscriptumn' => 5, 'AttributeAvTitle' => 6, 'AttributeAvChapo' => 7, 'AttributeAvDescription' => 8, 'AttributeAvPostscriptum' => 9, 'CreatedAt' => 10, 'UpdatedAt' => 11, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderProductId' => 1, 'attributeTitle' => 2, 'attributeChapo' => 3, 'attributeDescription' => 4, 'attributePostscriptumn' => 5, 'attributeAvTitle' => 6, 'attributeAvChapo' => 7, 'attributeAvDescription' => 8, 'attributeAvPostscriptum' => 9, 'createdAt' => 10, 'updatedAt' => 11, ), - self::TYPE_COLNAME => array(OrderProductAttributeCombinationTableMap::ID => 0, OrderProductAttributeCombinationTableMap::ORDER_PRODUCT_ID => 1, OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE => 2, OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO => 3, OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION => 4, OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN => 5, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE => 6, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO => 7, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION => 8, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_POSTSCRIPTUM => 9, OrderProductAttributeCombinationTableMap::CREATED_AT => 10, OrderProductAttributeCombinationTableMap::UPDATED_AT => 11, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_PRODUCT_ID' => 1, 'ATTRIBUTE_TITLE' => 2, 'ATTRIBUTE_CHAPO' => 3, 'ATTRIBUTE_DESCRIPTION' => 4, 'ATTRIBUTE_POSTSCRIPTUMN' => 5, 'ATTRIBUTE_AV_TITLE' => 6, 'ATTRIBUTE_AV_CHAPO' => 7, 'ATTRIBUTE_AV_DESCRIPTION' => 8, 'ATTRIBUTE_AV_POSTSCRIPTUM' => 9, 'CREATED_AT' => 10, 'UPDATED_AT' => 11, ), - self::TYPE_FIELDNAME => array('id' => 0, 'order_product_id' => 1, 'attribute_title' => 2, 'attribute_chapo' => 3, 'attribute_description' => 4, 'attribute_postscriptumn' => 5, 'attribute_av_title' => 6, 'attribute_av_chapo' => 7, 'attribute_av_description' => 8, 'attribute_av_postscriptum' => 9, 'created_at' => 10, 'updated_at' => 11, ), + self::TYPE_PHPNAME => array('Id' => 0, 'OrderProductId' => 1, 'AttributeTitle' => 2, 'AttributeChapo' => 3, 'AttributeDescription' => 4, 'AttributePostscriptum' => 5, 'AttributeAvTitle' => 6, 'AttributeAvChapo' => 7, 'AttributeAvDescription' => 8, 'AttributeAvPostscriptum' => 9, 'CreatedAt' => 10, 'UpdatedAt' => 11, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderProductId' => 1, 'attributeTitle' => 2, 'attributeChapo' => 3, 'attributeDescription' => 4, 'attributePostscriptum' => 5, 'attributeAvTitle' => 6, 'attributeAvChapo' => 7, 'attributeAvDescription' => 8, 'attributeAvPostscriptum' => 9, 'createdAt' => 10, 'updatedAt' => 11, ), + self::TYPE_COLNAME => array(OrderProductAttributeCombinationTableMap::ID => 0, OrderProductAttributeCombinationTableMap::ORDER_PRODUCT_ID => 1, OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE => 2, OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO => 3, OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION => 4, OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM => 5, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE => 6, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO => 7, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION => 8, OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_POSTSCRIPTUM => 9, OrderProductAttributeCombinationTableMap::CREATED_AT => 10, OrderProductAttributeCombinationTableMap::UPDATED_AT => 11, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_PRODUCT_ID' => 1, 'ATTRIBUTE_TITLE' => 2, 'ATTRIBUTE_CHAPO' => 3, 'ATTRIBUTE_DESCRIPTION' => 4, 'ATTRIBUTE_POSTSCRIPTUM' => 5, 'ATTRIBUTE_AV_TITLE' => 6, 'ATTRIBUTE_AV_CHAPO' => 7, 'ATTRIBUTE_AV_DESCRIPTION' => 8, 'ATTRIBUTE_AV_POSTSCRIPTUM' => 9, 'CREATED_AT' => 10, 'UPDATED_AT' => 11, ), + self::TYPE_FIELDNAME => array('id' => 0, 'order_product_id' => 1, 'attribute_title' => 2, 'attribute_chapo' => 3, 'attribute_description' => 4, 'attribute_postscriptum' => 5, 'attribute_av_title' => 6, 'attribute_av_chapo' => 7, 'attribute_av_description' => 8, 'attribute_av_postscriptum' => 9, 'created_at' => 10, 'updated_at' => 11, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ); @@ -185,7 +185,7 @@ class OrderProductAttributeCombinationTableMap extends TableMap $this->addColumn('ATTRIBUTE_TITLE', 'AttributeTitle', 'VARCHAR', true, 255, null); $this->addColumn('ATTRIBUTE_CHAPO', 'AttributeChapo', 'LONGVARCHAR', false, null, null); $this->addColumn('ATTRIBUTE_DESCRIPTION', 'AttributeDescription', 'CLOB', false, null, null); - $this->addColumn('ATTRIBUTE_POSTSCRIPTUMN', 'AttributePostscriptumn', 'LONGVARCHAR', false, null, null); + $this->addColumn('ATTRIBUTE_POSTSCRIPTUM', 'AttributePostscriptum', 'LONGVARCHAR', false, null, null); $this->addColumn('ATTRIBUTE_AV_TITLE', 'AttributeAvTitle', 'VARCHAR', true, 255, null); $this->addColumn('ATTRIBUTE_AV_CHAPO', 'AttributeAvChapo', 'LONGVARCHAR', false, null, null); $this->addColumn('ATTRIBUTE_AV_DESCRIPTION', 'AttributeAvDescription', 'CLOB', false, null, null); @@ -358,7 +358,7 @@ class OrderProductAttributeCombinationTableMap extends TableMap $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_TITLE); $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_CHAPO); $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_DESCRIPTION); - $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUMN); + $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_POSTSCRIPTUM); $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_TITLE); $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_CHAPO); $criteria->addSelectColumn(OrderProductAttributeCombinationTableMap::ATTRIBUTE_AV_DESCRIPTION); @@ -371,7 +371,7 @@ class OrderProductAttributeCombinationTableMap extends TableMap $criteria->addSelectColumn($alias . '.ATTRIBUTE_TITLE'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_CHAPO'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_DESCRIPTION'); - $criteria->addSelectColumn($alias . '.ATTRIBUTE_POSTSCRIPTUMN'); + $criteria->addSelectColumn($alias . '.ATTRIBUTE_POSTSCRIPTUM'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_AV_TITLE'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_AV_CHAPO'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_AV_DESCRIPTION'); diff --git a/core/lib/Thelia/Model/Map/OrderProductTaxTableMap.php b/core/lib/Thelia/Model/Map/OrderProductTaxTableMap.php index 2e8460a6a..98994c6e4 100644 --- a/core/lib/Thelia/Model/Map/OrderProductTaxTableMap.php +++ b/core/lib/Thelia/Model/Map/OrderProductTaxTableMap.php @@ -57,7 +57,7 @@ class OrderProductTaxTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 7; + const NUM_COLUMNS = 8; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class OrderProductTaxTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 7; + const NUM_HYDRATE_COLUMNS = 8; /** * the column name for the ID field @@ -94,6 +94,11 @@ class OrderProductTaxTableMap extends TableMap */ const AMOUNT = 'order_product_tax.AMOUNT'; + /** + * the column name for the PROMO_AMOUNT field + */ + const PROMO_AMOUNT = 'order_product_tax.PROMO_AMOUNT'; + /** * the column name for the CREATED_AT field */ @@ -116,12 +121,12 @@ class OrderProductTaxTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'OrderProductId', 'Title', 'Description', 'Amount', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'orderProductId', 'title', 'description', 'amount', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(OrderProductTaxTableMap::ID, OrderProductTaxTableMap::ORDER_PRODUCT_ID, OrderProductTaxTableMap::TITLE, OrderProductTaxTableMap::DESCRIPTION, OrderProductTaxTableMap::AMOUNT, OrderProductTaxTableMap::CREATED_AT, OrderProductTaxTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'ORDER_PRODUCT_ID', 'TITLE', 'DESCRIPTION', 'AMOUNT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'order_product_id', 'title', 'description', 'amount', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + self::TYPE_PHPNAME => array('Id', 'OrderProductId', 'Title', 'Description', 'Amount', 'PromoAmount', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'orderProductId', 'title', 'description', 'amount', 'promoAmount', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(OrderProductTaxTableMap::ID, OrderProductTaxTableMap::ORDER_PRODUCT_ID, OrderProductTaxTableMap::TITLE, OrderProductTaxTableMap::DESCRIPTION, OrderProductTaxTableMap::AMOUNT, OrderProductTaxTableMap::PROMO_AMOUNT, OrderProductTaxTableMap::CREATED_AT, OrderProductTaxTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'ORDER_PRODUCT_ID', 'TITLE', 'DESCRIPTION', 'AMOUNT', 'PROMO_AMOUNT', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'order_product_id', 'title', 'description', 'amount', 'promo_amount', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -131,12 +136,12 @@ class OrderProductTaxTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'OrderProductId' => 1, 'Title' => 2, 'Description' => 3, 'Amount' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderProductId' => 1, 'title' => 2, 'description' => 3, 'amount' => 4, 'createdAt' => 5, 'updatedAt' => 6, ), - self::TYPE_COLNAME => array(OrderProductTaxTableMap::ID => 0, OrderProductTaxTableMap::ORDER_PRODUCT_ID => 1, OrderProductTaxTableMap::TITLE => 2, OrderProductTaxTableMap::DESCRIPTION => 3, OrderProductTaxTableMap::AMOUNT => 4, OrderProductTaxTableMap::CREATED_AT => 5, OrderProductTaxTableMap::UPDATED_AT => 6, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_PRODUCT_ID' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, 'AMOUNT' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ), - self::TYPE_FIELDNAME => array('id' => 0, 'order_product_id' => 1, 'title' => 2, 'description' => 3, 'amount' => 4, 'created_at' => 5, 'updated_at' => 6, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + self::TYPE_PHPNAME => array('Id' => 0, 'OrderProductId' => 1, 'Title' => 2, 'Description' => 3, 'Amount' => 4, 'PromoAmount' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'orderProductId' => 1, 'title' => 2, 'description' => 3, 'amount' => 4, 'promoAmount' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), + self::TYPE_COLNAME => array(OrderProductTaxTableMap::ID => 0, OrderProductTaxTableMap::ORDER_PRODUCT_ID => 1, OrderProductTaxTableMap::TITLE => 2, OrderProductTaxTableMap::DESCRIPTION => 3, OrderProductTaxTableMap::AMOUNT => 4, OrderProductTaxTableMap::PROMO_AMOUNT => 5, OrderProductTaxTableMap::CREATED_AT => 6, OrderProductTaxTableMap::UPDATED_AT => 7, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ORDER_PRODUCT_ID' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, 'AMOUNT' => 4, 'PROMO_AMOUNT' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), + self::TYPE_FIELDNAME => array('id' => 0, 'order_product_id' => 1, 'title' => 2, 'description' => 3, 'amount' => 4, 'promo_amount' => 5, 'created_at' => 6, 'updated_at' => 7, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -160,6 +165,7 @@ class OrderProductTaxTableMap extends TableMap $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); $this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null); + $this->addColumn('PROMO_AMOUNT', 'PromoAmount', 'FLOAT', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -328,6 +334,7 @@ class OrderProductTaxTableMap extends TableMap $criteria->addSelectColumn(OrderProductTaxTableMap::TITLE); $criteria->addSelectColumn(OrderProductTaxTableMap::DESCRIPTION); $criteria->addSelectColumn(OrderProductTaxTableMap::AMOUNT); + $criteria->addSelectColumn(OrderProductTaxTableMap::PROMO_AMOUNT); $criteria->addSelectColumn(OrderProductTaxTableMap::CREATED_AT); $criteria->addSelectColumn(OrderProductTaxTableMap::UPDATED_AT); } else { @@ -336,6 +343,7 @@ class OrderProductTaxTableMap extends TableMap $criteria->addSelectColumn($alias . '.TITLE'); $criteria->addSelectColumn($alias . '.DESCRIPTION'); $criteria->addSelectColumn($alias . '.AMOUNT'); + $criteria->addSelectColumn($alias . '.PROMO_AMOUNT'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php index fc23ae569..1e894ef24 100644 --- a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php @@ -57,7 +57,7 @@ class ProductSaleElementsTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 9; + const NUM_COLUMNS = 10; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class ProductSaleElementsTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 9; + const NUM_HYDRATE_COLUMNS = 10; /** * the column name for the ID field @@ -104,6 +104,11 @@ class ProductSaleElementsTableMap extends TableMap */ const WEIGHT = 'product_sale_elements.WEIGHT'; + /** + * the column name for the IS_DEFAULT field + */ + const IS_DEFAULT = 'product_sale_elements.IS_DEFAULT'; + /** * the column name for the CREATED_AT field */ @@ -126,12 +131,12 @@ class ProductSaleElementsTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'ProductId', 'Ref', 'Quantity', 'Promo', 'Newness', 'Weight', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'ref', 'quantity', 'promo', 'newness', 'weight', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'REF', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'product_id', 'ref', 'quantity', 'promo', 'newness', 'weight', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id', 'ProductId', 'Ref', 'Quantity', 'Promo', 'Newness', 'Weight', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'ref', 'quantity', 'promo', 'newness', 'weight', 'isDefault', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::IS_DEFAULT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'REF', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'product_id', 'ref', 'quantity', 'promo', 'newness', 'weight', 'is_default', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -141,12 +146,12 @@ class ProductSaleElementsTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Ref' => 2, 'Quantity' => 3, 'Promo' => 4, 'Newness' => 5, 'Weight' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'createdAt' => 7, 'updatedAt' => 8, ), - self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::REF => 2, ProductSaleElementsTableMap::QUANTITY => 3, ProductSaleElementsTableMap::PROMO => 4, ProductSaleElementsTableMap::NEWNESS => 5, ProductSaleElementsTableMap::WEIGHT => 6, ProductSaleElementsTableMap::CREATED_AT => 7, ProductSaleElementsTableMap::UPDATED_AT => 8, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'REF' => 2, 'QUANTITY' => 3, 'PROMO' => 4, 'NEWNESS' => 5, 'WEIGHT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ), - self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'created_at' => 7, 'updated_at' => 8, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Ref' => 2, 'Quantity' => 3, 'Promo' => 4, 'Newness' => 5, 'Weight' => 6, 'IsDefault' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'isDefault' => 7, 'createdAt' => 8, 'updatedAt' => 9, ), + self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::REF => 2, ProductSaleElementsTableMap::QUANTITY => 3, ProductSaleElementsTableMap::PROMO => 4, ProductSaleElementsTableMap::NEWNESS => 5, ProductSaleElementsTableMap::WEIGHT => 6, ProductSaleElementsTableMap::IS_DEFAULT => 7, ProductSaleElementsTableMap::CREATED_AT => 8, ProductSaleElementsTableMap::UPDATED_AT => 9, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'REF' => 2, 'QUANTITY' => 3, 'PROMO' => 4, 'NEWNESS' => 5, 'WEIGHT' => 6, 'IS_DEFAULT' => 7, 'CREATED_AT' => 8, 'UPDATED_AT' => 9, ), + self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'is_default' => 7, 'created_at' => 8, 'updated_at' => 9, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -167,11 +172,12 @@ class ProductSaleElementsTableMap extends TableMap // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('PRODUCT_ID', 'ProductId', 'INTEGER', 'product', 'ID', true, null, null); - $this->addColumn('REF', 'Ref', 'VARCHAR', true, 45, null); + $this->addColumn('REF', 'Ref', 'VARCHAR', true, 255, null); $this->addColumn('QUANTITY', 'Quantity', 'FLOAT', true, null, null); $this->addColumn('PROMO', 'Promo', 'TINYINT', false, null, 0); $this->addColumn('NEWNESS', 'Newness', 'TINYINT', false, null, 0); - $this->addColumn('WEIGHT', 'Weight', 'FLOAT', false, null, null); + $this->addColumn('WEIGHT', 'Weight', 'FLOAT', false, null, 0); + $this->addColumn('IS_DEFAULT', 'IsDefault', 'BOOLEAN', false, 1, false); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -355,6 +361,7 @@ class ProductSaleElementsTableMap extends TableMap $criteria->addSelectColumn(ProductSaleElementsTableMap::PROMO); $criteria->addSelectColumn(ProductSaleElementsTableMap::NEWNESS); $criteria->addSelectColumn(ProductSaleElementsTableMap::WEIGHT); + $criteria->addSelectColumn(ProductSaleElementsTableMap::IS_DEFAULT); $criteria->addSelectColumn(ProductSaleElementsTableMap::CREATED_AT); $criteria->addSelectColumn(ProductSaleElementsTableMap::UPDATED_AT); } else { @@ -365,6 +372,7 @@ class ProductSaleElementsTableMap extends TableMap $criteria->addSelectColumn($alias . '.PROMO'); $criteria->addSelectColumn($alias . '.NEWNESS'); $criteria->addSelectColumn($alias . '.WEIGHT'); + $criteria->addSelectColumn($alias . '.IS_DEFAULT'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/install/faker.php b/install/faker.php index 68673394b..1a42dbcee 100755 --- a/install/faker.php +++ b/install/faker.php @@ -662,8 +662,8 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon1->setAmount(10.00); - $coupon1->setIsUsed(1); - $coupon1->setIsEnabled(1); + $coupon1->setIsUsed(true); + $coupon1->setIsEnabled(true); $date = new \DateTime(); $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months"))); @@ -698,9 +698,9 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); $coupon1->setSerializedRules($serializedConditions); $coupon1->setMaxUsage(40); - $coupon1->setIsCumulative(1); - $coupon1->setIsRemovingPostage(0); - $coupon1->setIsAvailableOnSpecialOffers(1); + $coupon1->setIsCumulative(true); + $coupon1->setIsRemovingPostage(false); + $coupon1->setIsAvailableOnSpecialOffers(true); $coupon1->save(); @@ -720,8 +720,8 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon2->setAmount(10.00); - $coupon2->setIsUsed(1); - $coupon2->setIsEnabled(1); + $coupon2->setIsUsed(true); + $coupon2->setIsEnabled(true); $date = new \DateTime(); $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months"))); @@ -742,9 +742,9 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); $coupon2->setSerializedRules($serializedConditions); $coupon2->setMaxUsage(-1); - $coupon2->setIsCumulative(0); - $coupon2->setIsRemovingPostage(1); - $coupon2->setIsAvailableOnSpecialOffers(1); + $coupon2->setIsCumulative(false); + $coupon2->setIsRemovingPostage(true); + $coupon2->setIsAvailableOnSpecialOffers(true); $coupon2->save(); @@ -764,8 +764,8 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon3->setAmount(10.00); - $coupon3->setIsUsed(0); - $coupon3->setIsEnabled(0); + $coupon3->setIsUsed(false); + $coupon3->setIsEnabled(false); $date = new \DateTime(); $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); @@ -782,8 +782,8 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedConditions = $constraintCondition->serializeConditionCollection($conditions); $coupon3->setSerializedRules($serializedConditions); $coupon3->setMaxUsage(-1); - $coupon3->setIsCumulative(1); - $coupon3->setIsRemovingPostage(0); - $coupon3->setIsAvailableOnSpecialOffers(0); + $coupon3->setIsCumulative(true); + $coupon3->setIsRemovingPostage(false); + $coupon3->setIsAvailableOnSpecialOffers(false); $coupon3->save(); } diff --git a/local/config/schema.xml b/local/config/schema.xml index 429a52e3f..ac0051e71 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,1254 +1,1258 @@ - + - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - -
    - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - -
    - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - -
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - -
    - - - - - - - -
    - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - -
    -
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + +
    + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + +
    + \ No newline at end of file diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index a34cc0c08..68cfb42e9 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -1,16 +1,16 @@ $(function($){ - // Manage how coupon and rules are saved + // Manage how coupon and conditions are saved $.couponManager = {}; - // Rule to be saved - $.couponManager.ruleToSave = {}; - $.couponManager.ruleToSave.serviceId = false; - $.couponManager.ruleToSave.operators = {}; - $.couponManager.ruleToSave.values = {}; - // Rules payload to save - $.couponManager.rulesToSave = []; - // Rule being updated id - $.couponManager.ruleToUpdateId = false; + // Condition to be saved + $.couponManager.conditionToSave = {}; + $.couponManager.conditionToSave.serviceId = false; + $.couponManager.conditionToSave.operators = {}; + $.couponManager.conditionToSave.values = {}; + // Conditions payload to save + $.couponManager.conditionsToSave = []; + // Condition being updated id + $.couponManager.conditionToUpdateId = false; // Clean array from deleteValue (undefined) keys Array.prototype.clean = function(deleteValue) { @@ -23,110 +23,109 @@ $(function($){ return this; }; - // Remove 1 Rule then Save Rules AJAX - $.couponManager.removeRuleAjax = function(id) { - // Delete rule in temporary array - delete $.couponManager.rulesToSave[id]; - $.couponManager.rulesToSave.clean(undefined); + // Remove 1 Condition then Save Conditions AJAX + $.couponManager.removeConditionAjax = function(id) { + // Delete condition in temporary array + delete $.couponManager.conditionsToSave[id]; + $.couponManager.conditionsToSave.clean(undefined); // Save - $.couponManager.saveRuleAjax(); + $.couponManager.saveConditionAjax(); }; - // Add 1 Rule / or update the temporary Rules array then Save Rules via AJAX - $.couponManager.createOrUpdateRuleAjax = function() { - var id = $.couponManager.ruleToUpdateId; + // Add 1 Condition / or update the temporary Conditions array then Save Conditions via AJAX + $.couponManager.createOrUpdateConditionAjax = function() { + var id = $.couponManager.conditionToUpdateId; // If create if(!id) { - $.couponManager.rulesToSave.push($.couponManager.ruleToSave); + $.couponManager.conditionsToSave.push($.couponManager.conditionToSave); } else { // else update - $.couponManager.rulesToSave[id] = $.couponManager.ruleToSave; + $.couponManager.conditionsToSave[id] = $.couponManager.conditionToSave; // reset edit mode to off - $.couponManager.ruleToUpdateId = false; + $.couponManager.conditionToUpdateId = false; } // Save - $.couponManager.saveRuleAjax(); + $.couponManager.saveConditionAjax(); }; - // Set rule inputs to allow editing - $.couponManager.updateRuleSelectAjax = function(id) { - $.couponManager.ruleToUpdateId = id; - $.couponManager.ruleToSave = $.couponManager.rulesToSave[id]; + // Set condition inputs to allow editing + $.couponManager.updateConditionSelectAjax = function(id) { + $.couponManager.conditionToUpdateId = id; + $.couponManager.conditionToSave = $.couponManager.conditionsToSave[id]; - // Set the rule selector + // Set the condition selector $("#category-rule option").filter(function() { - return $(this).val() == $.couponManager.ruleToSave.serviceId; + return $(this).val() == $.couponManager.conditionToSave.serviceId; }).prop('selected', true); - // Force rule input refresh - $.couponManager.loadRuleInputs($.couponManager.ruleToSave.serviceId, function() { - $.couponManager.fillInRuleInputs(); + // Force condition input refresh + $.couponManager.loadConditionInputs($.couponManager.conditionToSave.serviceId, function() { + $.couponManager.fillInConditionInputs(); }); }; - // Fill in rule inputs - $.couponManager.fillInRuleInputs = function() { + // Fill in condition inputs + $.couponManager.fillInConditionInputs = function() { var operatorId = null; var valueId = null; var idName = null; - var id = $.couponManager.ruleToUpdateId; + var id = $.couponManager.conditionToUpdateId; if(id) { - $.couponManager.ruleToSave = $.couponManager.rulesToSave[id]; + $.couponManager.conditionToSave = $.couponManager.conditionsToSave[id]; } - for (idName in $.couponManager.ruleToSave.operators) { + for (idName in $.couponManager.conditionToSave.operators) { // Setting idName operator select operatorId = idName + '-operator'; - $('#' + operatorId).val($.couponManager.ruleToSave.operators[idName]); + $('#' + operatorId).val($.couponManager.conditionToSave.operators[idName]); // Setting idName value input valueId = idName + '-value'; - $('#' + valueId).val($.couponManager.ruleToSave.values[idName]); + $('#' + valueId).val($.couponManager.conditionToSave.values[idName]); } }; - // Save rules on click - $.couponManager.onClickSaveRule = function() { + // Save conditions on click + $.couponManager.onClickSaveCondition = function() { $('#constraint-save-btn').on('click', function () { - console.log('constraint-save-btn'); if($('#category-rule').val() == 'thelia.condition.match_for_everyone') { -// // @todo translate + modal +// // @todo translate message + put it in modal var r = confirm("Do you really want to set this coupon available to everyone ?"); if (r == true) { - $.couponManager.createOrUpdateRuleAjax(); + $.couponManager.createOrUpdateConditionAjax(); } } else { - $.couponManager.createOrUpdateRuleAjax(); + $.couponManager.createOrUpdateConditionAjax(); } }); }; - $.couponManager.onClickSaveRule(); + $.couponManager.onClickSaveCondition(); - // Remove rule on click - $.couponManager.onClickDeleteRule = function() { + // Remove condition on click + $.couponManager.onClickDeleteCondition = function() { $('.constraint-delete-btn').on('click', function (e) { e.preventDefault(); var $this = $(this); - $.couponManager.removeRuleAjax($this.attr('data-int')); + $.couponManager.removeConditionAjax($this.attr('data-int')); }); }; - $.couponManager.onClickDeleteRule(); + $.couponManager.onClickDeleteCondition(); - // Update rule on click - $.couponManager.onClickUpdateRule = function() { - $('.constraint-update-btn').on('click', function (e) { + // Update condition on click + $.couponManager.onClickUpdateCondition = function() { + $('.condition-update-btn').on('click', function (e) { e.preventDefault(); var $this = $(this); - $.couponManager.updateRuleSelectAjax($this.attr('data-int')); + $.couponManager.updateConditionSelectAjax($this.attr('data-int')); // Hide row being updated $this.parent().parent().remove(); }); }; - $.couponManager.onClickUpdateRule(); + $.couponManager.onClickUpdateCondition(); // Reload effect inputs when changing effect $.couponManager.onEffectChange = function() { @@ -139,15 +138,15 @@ $(function($){ }; $.couponManager.onEffectChange(); - // Reload rule inputs when changing effect - $.couponManager.onRuleChange = function() { + // Reload condition inputs when changing effect + $.couponManager.onConditionChange = function() { $('#category-rule').on('change', function () { - $.couponManager.loadRuleInputs($(this).val(), function() {}); + $.couponManager.loadConditionInputs($(this).val(), function() {}); }); }; - $.couponManager.onRuleChange(); + $.couponManager.onConditionChange(); - // Fill in ready to be saved rule array + // Fill in ready to be saved condition array // var onInputsChange = function() // In AJAX response diff --git a/templates/admin/default/coupon-create.html b/templates/admin/default/coupon-create.html index 4b23ca118..a5bb21c67 100755 --- a/templates/admin/default/coupon-create.html +++ b/templates/admin/default/coupon-create.html @@ -18,7 +18,7 @@
    {form name="thelia.admin.coupon.creation"} - {include file='coupon/form.html' formAction={url path={$formAction}} noRules=true} + {include file='coupon/form.html' formAction={url path={$formAction}} noConditions=true} {/form}
    diff --git a/templates/admin/default/coupon-read.html b/templates/admin/default/coupon-read.html index aa0bfc5a1..6143fbded 100755 --- a/templates/admin/default/coupon-read.html +++ b/templates/admin/default/coupon-read.html @@ -122,11 +122,11 @@ {intl l='Application field'}
      - {foreach from=$APPLICATION_CONDITIONS item=rule name=rulesForeach} - {if !$smarty.foreach.rulesForeach.first} + {foreach from=$APPLICATION_CONDITIONS item=condition name=conditionsForeach} + {if !$smarty.foreach.conditionsForeach.first}
    • {intl l='And'}
    • {/if} -
    • {$rule nofilter}
    • +
    • {$condition nofilter}
    • {/foreach}
    diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index 1a937cfc1..be9354362 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -18,7 +18,7 @@
    {form name="thelia.admin.coupon.creation"} - {include file='coupon/form.html' formAction={url path={$formAction}} form=$form noRules=false} + {include file='coupon/form.html' formAction={url path={$formAction}} form=$form noConditions=false} {/form} @@ -45,87 +45,87 @@ $(function($){ miniBrowser(0, '/test_to_remove/datas_coupon_edit.json'); - // Init Rules - $.couponManager.initRules = function() { - var rules = []; - {foreach from=$rulesObject key=k item=rule} - // Init rule - var rule = {}; - rule['serviceId'] = '{$rule.serviceId nofilter}'; - rule['operators'] = {}; - rule['values'] = {}; + // Init Conditions + $.couponManager.initConditions = function() { + var conditions = []; + {foreach from=$conditionsObject key=k item=condition} + // Init condition + var condition = {}; + condition['serviceId'] = '{$condition.serviceId nofilter}'; + condition['operators'] = {}; + condition['values'] = {}; - {foreach from=$rule.validators.setOperators key=input item=operator} - rule['operators']['{$input nofilter}'] = '{$operator nofilter}'; - rule['values']['{$input nofilter}'] = '{$rule.validators.setValues[$input] nofilter}'; + {foreach from=$condition.validators.setOperators key=input item=operator} + condition['operators']['{$input nofilter}'] = '{$operator nofilter}'; + condition['values']['{$input nofilter}'] = '{$condition.validators.setValues[$input] nofilter}'; {/foreach} - // Add rule - rules.push(rule); + // Add condition + conditions.push(condition); {/foreach} - return rules; + return conditions; }; - // Save Rules AJAX - $.couponManager.saveRuleAjax = function() { - $('#constraint-add-operators-values').html('
    '); - var $url = '{$urlAjaxUpdateRules}'; + // Save Conditions AJAX + $.couponManager.saveConditionAjax = function() { + $('#condition-add-operators-values').html('
    '); + var $url = '{$urlAjaxUpdateConditions}'; $.ajax({ type: "POST", url: $url, - data: {literal}{{/literal}rules:JSON.stringify($.couponManager.rulesToSave){literal}}{/literal}, + data: {literal}{{/literal}conditions:JSON.stringify($.couponManager.conditionsToSave){literal}}{/literal}, statusCode: { 404: function() { - $('#constraint-add-operators-values').html( + $('#condition-add-operators-values').html( '{intl l='Please retry'}' ); } } }).done(function(data) { - $('#constraint-list').html(data); - $('#constraint-add-operators-values').html(''); - // Set the rule selector - $("#category-rule option").filter(function() { + $('#condition-list').html(data); + $('#condition-add-operators-values').html(''); + // Set the condition selector + $("#category-condition option").filter(function() { return $(this).val() == 'thelia.condition.match_for_everyone'; }).prop('selected', true); - $.couponManager.onClickUpdateRule(); - $.couponManager.onClickDeleteRule(); + $.couponManager.onClickUpdateCondition(); + $.couponManager.onClickDeleteCondition(); }); }; - // Reload rule inputs - $.couponManager.loadRuleInputs = function(ruleId, callBack) { - $('#constraint-add-operators-values').html('
    '); - var url = "{$urlAjaxGetRuleInput}"; - url = url.replace('ruleId', ruleId) + // Reload condition inputs + $.couponManager.loadConditionInputs = function(conditionId, callBack) { + $('#condition-add-operators-values').html('
    '); + var url = "{$urlAjaxGetConditionInput}"; + url = url.replace('conditionId', conditionId) $.ajax({ url: url, statusCode: { 404: function() { - $('#constraint-add-operators-values').html( - '{intl l='Please select another rule'}' + $('#condition-add-operators-values').html( + '{intl l='Please select another condition'}' ); } } }).done(function(data) { - $('#constraint-add-operators-values').html(data); - $.couponManager.ruleToSave.serviceId = ruleId; - if (ruleId == -1) { + $('#condition-add-operators-values').html(data); + $.couponManager.conditionToSave.serviceId = conditionId; + if (conditionId == -1) { // Placeholder can't be saved - $('#constraint-save-btn').hide(); + $('#condition-save-btn').hide(); } else { - $('#constraint-save-btn').show(); + $('#condition-save-btn').show(); } return callBack(); }); }; - // Rules which will be saved - $.couponManager.rulesToSave = $.couponManager.initRules(); + // Conditions which will be saved + $.couponManager.conditionsToSave = $.couponManager.initConditions(); - $('#constraint-save-btn').hide(); + $('#condition-save-btn').hide(); }); diff --git a/templates/admin/default/coupon/condition-input-ajax.html b/templates/admin/default/coupon/condition-input-ajax.html index 50ff64a08..57dd60f5a 100644 --- a/templates/admin/default/coupon/condition-input-ajax.html +++ b/templates/admin/default/coupon/condition-input-ajax.html @@ -71,32 +71,32 @@