1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Controller; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Form\AddToCartForm; |
6
|
|
|
use Dynamic\Foxy\Model\FoxyHelper; |
7
|
|
|
use Dynamic\Foxy\Model\Setting; |
8
|
|
|
use SilverStripe\View\Requirements; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
class ProductController extends \PageController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private static $allowed_actions = [ |
|
|
|
|
19
|
|
|
'AddToCartForm', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
public function init() |
26
|
|
|
{ |
27
|
|
|
parent::init(); |
28
|
|
|
|
29
|
|
|
if ($this->hasMethod('getIsAvailable')) { |
30
|
|
|
if ($this->data()->getIsAvailable()) { |
31
|
|
|
if ($this->data()->Variations()->count()) { |
32
|
|
|
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js'); |
33
|
|
|
Requirements::javascript('dynamic/silverstripe-foxy: client/dist/javascript/product_options.js'); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$config = Setting::current_foxy_setting(); |
39
|
|
|
$helper = FoxyHelper::create(); |
40
|
|
|
|
41
|
|
|
if ($config->EnableSidecart) { |
42
|
|
|
Requirements::javascript( |
43
|
|
|
"https://cdn.foxycart.com/" . $helper->getStoreCartURL() . "/loader.js", |
44
|
|
|
[ |
45
|
|
|
"async" => true, |
46
|
|
|
"defer" => true, |
47
|
|
|
] |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return AddToCartForm |
54
|
|
|
*/ |
55
|
|
|
public function AddToCartForm() |
56
|
|
|
{ |
57
|
|
|
if ($this->data()->getIsAvailable()) { |
58
|
|
|
$form = AddToCartForm::create($this, __FUNCTION__, null, null, null, $this->data()); |
59
|
|
|
} else { |
60
|
|
|
$form = false; |
61
|
|
|
} |
62
|
|
|
$this->extend('updateAddToCartForm', $form); |
63
|
|
|
|
64
|
|
|
return $form; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function StoreURL() |
71
|
|
|
{ |
72
|
|
|
$helper = FoxyHelper::create(); |
73
|
|
|
|
74
|
|
|
return $helper::StoreURL(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|