Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details

language: php
php:
language: php
php:
- 5.3

env:
Expand All @@ -18,5 +18,5 @@ before_script:
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss

script:
script:
- phpunit googlesitemaps/tests/
40 changes: 20 additions & 20 deletions code/GoogleShoppingFeed.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
/**
* Shopping Feeds are a way to tell Google about pages on your site that they might
* not otherwise discover. In its simplest terms, a XML Sitemap usually called
* a Sitemap, with a capital S—is a list of the pages on your website.
*
* Creating and submitting a Sitemap helps make sure that Google knows about
* all the pages on your site, including URLs that may not be discoverable by
* Shopping Feeds are a way to tell Google about pages on your site that they might
* not otherwise discover. In its simplest terms, a XML Sitemap usually called
* a Sitemap, with a capital S—is a list of the pages on your website.
*
* Creating and submitting a Sitemap helps make sure that Google knows about
* all the pages on your site, including URLs that may not be discoverable by
* Google's normal crawling process.
*
*
* The GoogleSitemap handle requests to 'sitemap.xml'
* the other two classes are used to render the sitemap.
*
*
* You can notify ("ping") Google about a changed sitemap
* automatically whenever a new page is published or unpublished.
* By default, Google is not notified, and will pick up your new
* sitemap whenever the GoogleBot visits your website.
*
*
* To Enable notification of Google after every publish set google_notification_enabled
* to true in the googlesitemaps.yml config file.
* This file is usually located in the _config folder of your project folder.
Expand All @@ -31,9 +31,9 @@
* google_notification_enabled: true
* use_show_in_search: true
* </example>
*
*
* @see http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=34609
*
*
* @package googlesitemaps
*/
class GoogleShoppingFeed
Expand All @@ -59,11 +59,11 @@ public static function register_dataobject($className)
{
if (!self::is_registered($className)) {
$className::add_extension('GoogleShoppingFeedExtension');

self::$dataobjects[] = $className;
}
}

/**
* Registers multiple dataobjects in a single line. See {@link register_dataobject}
* for the heavy lifting
Expand All @@ -83,14 +83,14 @@ public static function register_dataobjects($dataobjects)
* Checks whether the given class name is already registered or not.
*
* @param string $className Name of DataObject to check
*
*
* @return bool
*/
public static function is_registered($className)
{
return isset(self::$dataobjects[$className]);
}

/**
* Unregisters a class from the sitemap. Mostly used for the test suite
*
Expand All @@ -110,7 +110,7 @@ public static function clear_registered_dataobjects()
{
self::$dataobjects = array();
}


/**
* Constructs the list of data to include in the rendered feed. Links
Expand All @@ -129,7 +129,7 @@ public static function get_items()
$disabled_filter = Config::inst()->get('GoogleShoppingFeed', 'use_disabled');
$filter = array();

// todo migrate to extension hook or DI point for other modules to
// todo migrate to extension hook or DI point for other modules to
// modify state filters
if (class_exists('Translatable')) {
Translatable::disable_locale_filter();
Expand All @@ -142,7 +142,7 @@ public static function get_items()
$instances = Versioned::get_by_stage('SiteTree', 'Live', $search_filter);
} elseif ($class == "Product") {
$instances = $class::get();

if ($disabled_filter) {
$instances->filter("Disabled", 0);
}
Expand All @@ -161,10 +161,10 @@ public static function get_items()

return $output;
}

/**
* Returns the string frequency of edits for a particular dataobject class.
*
*
* Frequency for {@link SiteTree} objects can be determined from the version
* history.
*
Expand Down
12 changes: 6 additions & 6 deletions code/controllers/GoogleShoppingFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ class GoogleShoppingFeedController extends Controller
private static $allowed_actions = array(
'index'
);

/**
* Specific controller action for displaying a particular list of links
* Specific controller action for displaying a particular list of links
* for a class
*
*
* @return mixed
*/
public function index()
{
if (GoogleShoppingFeed::enabled()) {
Config::inst()->update('SSViewer', 'set_source_file_comments', false);

$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');

$items = GoogleShoppingFeed::get_items();

$currency = new Zend_Currency(i18n::get_locale());

$this->extend('updateGoogleShoppingFeedItems', $items);

return array(
Expand Down
30 changes: 15 additions & 15 deletions code/extensions/GoogleShoppingFeedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@

class GoogleShoppingFeedExtension extends DataExtension
{

/**
* @var array
*/
private static $db = array(
"RemoveFromShoppingFeed" => "Boolean"
);


/**
* @param FieldList
*/
public function updateSettingsFields(FieldList $fields)
{
$tabset = $fields->findOrMakeTab('Root.Settings');

$tabset->push(new HeaderField(_t(
'GoogleShoppingFeed.GoogleShoppingFeed',
'Google Shopping Feed'
)));

$tabset->push(new CheckboxField("RemoveFromShoppingFeed"));
}


/**
* @param FieldList
*/
public function updateCMSFields(FieldList $fields)
{
if (!method_exists($this->owner, "getSettingsFields")) {
$tabset = $fields->findOrMakeTab('Root.Settings');

$tabset->push(new HeaderField(_t(
'GoogleShoppingFeed.GoogleShoppingFeed',
'Google Shopping Feed'
)));

$tabset->push(new CheckboxField("RemoveFromShoppingFeed"));
}
}


/**
* Can we add this object to a shopping feed?
*
*
* @return boolean
*/
public function canIncludeInGoogleShoppingFeed()
Expand All @@ -66,17 +66,17 @@ public function canIncludeInGoogleShoppingFeed()
} else {
$can = false;
}

// If no price or title.
if (!$this->owner->Title || !$this->owner->Price || !$this->owner->Condition || !$this->owner->Availability || !$this->owner->Brand || !$this->owner->MPN) {
$can = false;
}

// Can any user view this item
if ($can) {
$can = $this->owner->canView();
}

if ($can && $this->owner->RemoveFromShoppingFeed) {
$can = false;
}
Expand Down
8 changes: 4 additions & 4 deletions templates/GoogleShoppingFeedController.ss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<title>$SiteConfig.Title</title>
<link>$BaseHref</link>
<description>$SiteConfig.Tagline</description>
<% loop $Items %>

<% loop $Items %>
<item>
<g:id><% if $StockID %>$StockID<% else %>$ID<% end_if %></g:id>
<g:title>$Title</g:title>
Expand All @@ -18,7 +18,7 @@
<g:availability>$Availability</g:availability>
<g:brand>$Brand</g:brand>
<g:mpn>$MPN</g:mpn>

<% loop $Shipping %>
<g:shipping>
<g:country>$Country</g:country>
Expand All @@ -28,6 +28,6 @@
<% end_loop %>
</item>
<% end_loop %>

</channel>
</rss>
22 changes: 11 additions & 11 deletions tests/GoogleShoppingFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GoogleShoppingFeedTest extends FunctionalTest
public function setUp()
{
parent::setUp();

GoogleShoppingFeed::clear_registered_dataobjects();
}

Expand Down Expand Up @@ -48,7 +48,7 @@ public function testAccessingXMLFile()
// dataobject as it hasn't been registered
$expected = "<g:id>ip-123</g:id>";
$this->assertEquals(1, substr_count($body, $expected), 'Product with code ip-123 exists');

$expected = "<g:id>cb-123</g:id>";
$this->assertEquals(1, substr_count($body, $expected), 'Product with code cb-123 exists');

Expand All @@ -59,28 +59,28 @@ public function testAccessingXMLFile()
public function testAccess()
{
Config::inst()->update('GoogleShoppingFeed', 'enabled', true);

$response = $this->get('shoppingfeed.xml');

$this->assertEquals(200, $response->getStatusCode(), 'Feed returns a 200 success when enabled');
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));

GoogleShoppingFeed::register_dataobject("GoogleShoppingFeedTest_Product");
$response = $this->get('shoppingfeed.xml');
$this->assertEquals(200, $response->getStatusCode(), 'Feed returns a 200 success when enabled with products');
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));

Config::inst()->remove('GoogleShoppingFeed', 'enabled');
Config::inst()->update('GoogleShoppingFeed', 'enabled', false);

$response = $this->get('shoppingfeed.xml');
$this->assertEquals(404, $response->getStatusCode(), 'Feed returns a 404 when disabled');
}

public function testRemoveFromFeed()
{
Config::inst()->update('GoogleShoppingFeed', 'enabled', true);

$response = $this->get('shoppingfeed.xml');
$body = $response->getBody();

Expand All @@ -97,7 +97,7 @@ public function testRemoveFromFeed()
*/
class GoogleShoppingFeedTest_Product extends DataObject implements TestOnly
{

public static $db = array(
"Title" => "Varchar",
"Price" => "Currency",
Expand All @@ -110,11 +110,11 @@ class GoogleShoppingFeedTest_Product extends DataObject implements TestOnly
"MPN" => "Varchar",
"RemoveFromShoppingFeed" => "Boolean"
);

public static $has_one = array(
"Image" => "Image"
);

public static $many_many = array(
"Shipping" => "GoogleShoppingFeedTest_Shipping"
);
Expand Down Expand Up @@ -142,7 +142,7 @@ class GoogleShoppingFeedTest_Shipping extends DataObject implements TestOnly
'Price' => 'Currency',
'Country' => 'Varchar(2)'
);

public static $belongs_many_many = array(
"Products" => "GoogleShoppingFeedTest_Product"
);
Expand Down
2 changes: 1 addition & 1 deletion tests/GoogleShoppingFeedTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GoogleShoppingFeedTest_Shipping:
Price: 5.99
Country: US

GoogleShoppingFeedTest_Product:
GoogleShoppingFeedTest_Product:
iphone:
Title: "iPhone"
Price: 400.00
Expand Down