1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\FoxyStripe\ORM; |
4
|
|
|
|
5
|
|
|
use Dynamic\FoxyStripe\Page\ProductPage; |
6
|
|
|
use SilverStripe\Core\Extension; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\Forms\HeaderField; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class FoxyStripeInventoryManagerExtension |
13
|
|
|
* @package Dynamic\FoxyStripe\ORM |
14
|
|
|
* |
15
|
|
|
* @property ProductPage|\Dynamic\FoxyStripe\ORM\FoxyStripeInventoryManager $owner |
16
|
|
|
*/ |
17
|
|
|
class FoxyStripeInventoryManagerExtension extends Extension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param \SilverStripe\Forms\Form $form |
21
|
|
|
*/ |
22
|
1 |
|
public function updateFoxyStripePurchaseForm(&$form) |
23
|
|
|
{ |
24
|
1 |
|
if ($this->owner->Available && !$this->owner->getIsProductAvailable()) { |
|
|
|
|
25
|
|
|
$form->setFields(FieldList::create([ |
26
|
|
|
HeaderField::create('OutOfStock', 'Currently Out of Stock', 4), |
27
|
|
|
])); |
28
|
|
|
if ($submit = $form->Actions()->fieldByName('')) { |
29
|
|
|
$submit->setAttribute('Disabled', true); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
if ($this->owner->getHasInventory()) { |
35
|
1 |
|
$quantityMax = $this->owner->getNumberAvailable(); |
36
|
1 |
|
$count = 1; |
37
|
1 |
|
$quantity = array(); |
38
|
1 |
|
while ($count <= $quantityMax) { |
39
|
1 |
|
$countVal = ProductPage::getGeneratedValue($this->owner->Code, 'quantity', $count, 'value'); |
|
|
|
|
40
|
1 |
|
$quantity[$countVal] = $count; |
41
|
1 |
|
$count++; |
42
|
|
|
} |
43
|
1 |
|
$fields = $form->Fields(); |
44
|
1 |
|
$fields->replaceField('quantity', DropdownField::create('quantity', 'Quantity', $quantity)); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|