Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from creative-commoners/pulls/1.0/item-quantity
NEW Add validation for "add item" requests, implement maximum item quantity in cart
- Loading branch information
Showing
10 changed files
with
231 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
.dms-cart-actions .hidden { | ||
display: none; | ||
visibility: hidden; | ||
.dms-cart-actions .dms-cart-actions-viewcartlink:before { | ||
content: "• " | ||
} | ||
|
||
.dms-cart-actions .dms-bullet-item:before { | ||
content: "• " | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function ($) { | ||
"use strict"; | ||
|
||
$.entwine('ss', function ($) { | ||
$('input.dms-allowed-in-cart').entwine({ | ||
/** | ||
* Toggle the "maximum cart quantity" field visibility depending on whether "allowed in document cart" is checked | ||
*/ | ||
onclick: function (e) { | ||
jQuery('.field.dms-maximum-cart-quantity').toggle(); | ||
this.getElements().removeClass('hide'); | ||
}, | ||
/** | ||
* Initially show the "maximum cart quantity" field visibility if the "allowed in document cart" checkbox | ||
* is checked | ||
*/ | ||
onmatch: function(e) { | ||
if (this.is(':checked')) { | ||
this.getElements().removeClass('hide'); | ||
} | ||
}, | ||
/** | ||
* Returns all DOM elements with the field's class applied | ||
*/ | ||
getElements: function() { | ||
return jQuery('.dms-maximum-cart-quantity'); | ||
} | ||
}); | ||
}); | ||
}(jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
en: | ||
DMSDocumentCart: | ||
ALLOWED_IN_CART: Allowed in document cart | ||
MAXIMUM_CART_QUANTITY: Maximum cart quantity | ||
MAXIMUM_CART_QUANTITY_HELP: If set, this will enforce a maximum number of this item that can be ordered per cart | ||
DMSDocumentCartController: | ||
ERROR_NOT_ALLOWED: You are not allowed to add this document | ||
ERROR_QUANTITY_EXCEEDED: You can't add {quantity} of this document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
class DMSDocumentCartExtensionTest extends SapphireTest | ||
{ | ||
protected $requiredExtensions = array( | ||
'DMSDocument' => array('DMSDocumentCartExtension') | ||
); | ||
|
||
public function testMaximumCartQuantity() | ||
{ | ||
$document = DMSDocument::create(array('AllowedInCart' => true, 'MaximumCartQuantity' => '')); | ||
|
||
$this->assertFalse($document->getHasQuantityLimit()); | ||
|
||
$document->MaximumCartQuantity = 0; | ||
$this->assertFalse($document->getHasQuantityLimit()); | ||
|
||
$document->MaximumCartQuantity = 1; | ||
$this->assertTrue($document->getHasQuantityLimit()); | ||
$this->assertSame(1, $document->getMaximumQuantity()); | ||
|
||
$document->MaximumCartQuantity = 10; | ||
$this->assertSame(10, $document->getMaximumQuantity()); | ||
} | ||
|
||
/** | ||
* The CSS classes are required for the CMS Javascript to work, assert that they are correct | ||
*/ | ||
public function testCmsFieldsHaveRequiredCssClasses() | ||
{ | ||
$fields = DMSDocument::create()->getCMSFields(); | ||
|
||
$allowedInCart = $fields->fieldByName('AllowedInCart'); | ||
$this->assertInstanceOf('CheckboxField', $allowedInCart); | ||
$this->assertTrue((bool) $allowedInCart->hasClass('dms-allowed-in-cart')); | ||
|
||
$allowedInCart = $fields->fieldByName('MaximumCartQuantity'); | ||
$this->assertInstanceOf('TextField', $allowedInCart); | ||
$this->assertTrue((bool) $allowedInCart->hasClass('dms-maximum-cart-quantity')); | ||
} | ||
|
||
/** | ||
* Ensure that validation messages can be retrieved once, cleared, then not again | ||
*/ | ||
public function testGetValidationResult() | ||
{ | ||
Session::set('dms-cart-validation-message', 'testing'); | ||
$this->assertSame('testing', DMSDocument::create()->getValidationResult()); | ||
$this->assertFalse(DMSDocument::create()->getValidationResult()); | ||
} | ||
} |