|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverShop\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use SilverShop\Cart\ShoppingCart; |
|
6
|
|
|
use SilverShop\Page\CartPage; |
|
7
|
|
|
use SilverShop\Page\CheckoutPage; |
|
8
|
|
|
use SilverShop\Page\ProductCategory; |
|
9
|
|
|
use SilverStripe\Control\Director; |
|
10
|
|
|
use SilverStripe\Core\Extension; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* ViewableData extension that provides access to the cart from anywhere. |
|
14
|
|
|
* Also handles last-minute recalculation, if required. |
|
15
|
|
|
* All order updates: quantities, modifiers etc should be done before |
|
16
|
|
|
* this function is called. |
|
17
|
|
|
* |
|
18
|
|
|
* @package shop |
|
19
|
|
|
*/ |
|
20
|
|
|
class ViewableCartExtension extends Extension |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Get the cart, and do last minute calculation if necessary. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function Cart() |
|
26
|
|
|
{ |
|
27
|
|
|
$order = ShoppingCart::curr(); |
|
28
|
|
|
if (!$order || !$order->Items() || !$order->Items()->exists()) { |
|
|
|
|
|
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return $order; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getContinueLink() |
|
36
|
|
|
{ |
|
37
|
|
|
if ($cartPage = CartPage::get()->first()) { |
|
38
|
|
|
if ($cartPage->ContinuePageID) { |
|
39
|
|
|
return $cartPage->ContinuePage()->Link(); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$maincategory = ProductCategory::get() |
|
44
|
|
|
->sort( |
|
45
|
|
|
[ |
|
46
|
|
|
'ParentID' => 'ASC', |
|
47
|
|
|
'ID' => 'ASC', |
|
48
|
|
|
] |
|
49
|
|
|
)->first(); |
|
50
|
|
|
if ($maincategory) { |
|
51
|
|
|
return $maincategory->Link(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return Director::baseURL(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getCartLink() |
|
58
|
|
|
{ |
|
59
|
|
|
return CartPage::find_link(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getCheckoutLink() |
|
63
|
|
|
{ |
|
64
|
|
|
return CheckoutPage::find_link(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|