1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\EcommerceGoogleShoppingFeed\Controllers; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\ContentNegotiator; |
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use SilverStripe\Core\ClassInfo; |
8
|
|
|
use SilverStripe\Core\Config\Config; |
9
|
|
|
use SilverStripe\View\SSViewer; |
10
|
|
|
use Sunnysideup\EcommerceGoogleShoppingFeed\Api\ProductCollectionForGoogleShoppingFeed; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Controller for displaying the xml feed. |
14
|
|
|
* |
15
|
|
|
* <code> |
16
|
|
|
* http://site.com/shoppingfeed.xml |
17
|
|
|
* </code> |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class GoogleShoppingFeedController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $allowed_actions = [ |
26
|
|
|
'index', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
private static $api_class = ProductCollectionForGoogleShoppingFeed::class; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Specific controller action for displaying a particular list of links |
33
|
|
|
* for a class. |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
|
public function index() |
38
|
|
|
{ |
39
|
|
|
Config::modify()->set(SSViewer::class, 'set_source_file_comments', false); |
40
|
|
|
Config::modify()->set(ContentNegotiator::class, 'enabled', false); |
41
|
|
|
// response header |
42
|
|
|
$header = $this->getResponse(); |
43
|
|
|
$header->addHeader('Pragma', 'no-cache'); |
44
|
|
|
$header->addHeader('Expires', 0); |
45
|
|
|
$header->addHeader('Content-Type', $this->getContentType()); |
|
|
|
|
46
|
|
|
$header->addHeader('Content-Disposition', 'attachment; filename=' . $this->getFilename()); |
47
|
|
|
$header->addHeader('X-Robots-Tag', 'noindex'); |
48
|
|
|
|
49
|
|
|
return $this->renderWith(ClassInfo::shortName(static::class)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getFileName(): string |
53
|
|
|
{ |
54
|
|
|
return 'shoppingfeed.' . $this->getExtension(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|