Skip to content

Commit

Permalink
SilverStripe 4 and migration updates (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Oct 16, 2018
1 parent 57a0cea commit 8e5c7bf
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Features include:
* Two-way Single Sign On with FoxyCart
* HMAC Product Validation

Read more about [Using FoxyStripe](docs/en/Use.MD) and [Advanced Features](docs/en/Features.MD)
Read more about [Using FoxyStripe](docs/en/userguide/index.md), [Advanced Features](docs/en/userguide/features.md) and [Migrating from SilverStripe 3.x to 4.x](docs/en/userguide/migration.md)


## Installation
Expand Down
4 changes: 4 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ See the [using FoxyStripe](userguide/index.md) document.

See the [advanced features](userguide/features.md) document.

### Migrating from SilverStripe 3.x to 4.x

See the [SilverStripe 4 migration](userguide/migration.md) document.

### Recommended Add-Ons

The following add-ons are optional, but will enhance FoxyStripe when installed:
Expand Down
20 changes: 20 additions & 0 deletions docs/en/userguide/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# FoxyStripe

## Migration

### Migrate your settings from SilverStripe 3.x to 4.x

FoxyStripe 4 introduces a new class `FoxyStripeSetting` to store your FoxyCart store settings. To migrate your settings from `SiteConfig` to `FoxyStripeSetting`, do the following:

1. Apply the `SiteConfigMigration` DataExtension to `SiteConfig`

```
SilverStripe\SiteConfig\SiteConfig:
extensions:
- Dynamic\FoxyStripe\ORM\SiteConfigMigration
```
2. Open Settings in the CMS - [http://example.com/admin/settings](http://example.com/admin/settings)
3. Hit 'Save'. The data will save to the current `FoxyStripeSetting` via `onAfterWrite()` on `SiteConfig`
4. Remove the `SiteConfigMigration` DataExtension from `SiteConfig`

Your FoxyCart settings should now be viewable in the FoxyStripe admin.
58 changes: 58 additions & 0 deletions src/Migration/SiteConfigMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Dynamic\FoxyStripe\ORM;

use Dynamic\FoxyStripe\Model\FoxyStripeSetting;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;

/**
* Class SiteConfigMigration
*
* Apply this DataExtension to SiteConfig and hit Save. Data will be migrated to FoxyStripeSetting
* via the onAfterWrite() function.
*
* @package Dynamic\FoxyStripe\ORM
*/
class SiteConfigMigration extends DataExtension
{
/**
* @var array
*/
private static $db = array(
'StoreName' => 'Varchar(255)',
'StoreKey' => 'Varchar(60)',
'MultiGroup' => 'Boolean',
'ProductLimit' => 'Int',
'CartValidation' => 'Boolean',
'MaxQuantity' => 'Int',
'CustomSSL' => 'Boolean',
'RemoteDomain' => 'Varchar(255)',
);

/**
*
*/
public function onAfterWrite()
{
parent::onAfterWrite();

$config = FoxyStripeSetting::current_foxystripe_setting();

$config->StoreName = $this->owner->StoreName;
$config->StoreKey = $this->owner->StoreKey;
$config->MultiGroup = $this->owner->MultiGroup;
$config->ProductLimit = $this->owner->ProductLimit;
$config->CartValidation = $this->owner->CartValidation;
$config->MaxQuantity = $this->owner->MaxQuantity;
$config->CustomSSL = $this->owner->CustomSSL;
$config->RemoteDomain = $this->owner->RemoteDomain;

$config->write();
}
}
2 changes: 1 addition & 1 deletion src/Model/FoxyStripeSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class FoxyStripeSetting extends DataObject implements PermissionProvider, Templa
/**
* @var string
*/
private static $table_name = 'FS_FoxyStripeSetting';
private static $table_name = 'FoxyStripeSetting';

/**
* Default permission to check for 'LoggedInUsers' to create or edit pages.
Expand Down
2 changes: 1 addition & 1 deletion src/Model/OptionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OptionGroup extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_OptionGroup';
private static $table_name = 'OptionGroup';

/**
* @throws \SilverStripe\ORM\ValidationException
Expand Down
2 changes: 1 addition & 1 deletion src/Model/OptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OptionItem extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_OptionItem';
private static $table_name = 'OptionItem';

/**
* @return FieldList
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Order extends DataObject implements PermissionProvider
*/
private static $summary_fields = array(
'Order_ID',
'TransactionDate.NiceUS',
'TransactionDate.Nice',
'Member.Name',
'ProductTotal.Nice',
'ShippingTotal.Nice',
Expand Down Expand Up @@ -127,7 +127,7 @@ class Order extends DataObject implements PermissionProvider
/**
* @var string
*/
private static $table_name = 'FS_Order';
private static $table_name = 'Order';

/**
* @param bool $includerelations
Expand Down
2 changes: 1 addition & 1 deletion src/Model/OrderDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class OrderDetail extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_OrderDetail';
private static $table_name = 'OrderDetail';

/**
* @return FieldList
Expand Down
2 changes: 1 addition & 1 deletion src/Model/OrderOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ class OrderOption extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_OrderOption';
private static $table_name = 'OrderOption';
}
2 changes: 1 addition & 1 deletion src/Model/ProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ProductCategory extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_ProductCategory';
private static $table_name = 'ProductCategory';

/**
* @return FieldList
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ProductImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProductImage extends DataObject
/**
* @var string
*/
private static $table_name = 'FS_ProductImage';
private static $table_name = 'ProductImage';

/**
* @return \SilverStripe\Forms\FieldList
Expand Down
5 changes: 5 additions & 0 deletions src/Page/DonationProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class DonationProduct extends ProductPage
*/
private static $can_be_root = true;

/**
* @var string
*/
private static $table_name = 'DonationProduct';

/**
* @return FieldList
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Page/ProductHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProductHolder extends \Page
/**
* @var string
*/
private static $table_name = 'FS_ProductHolder';
private static $table_name = 'ProductHolder';

/**
* @return FieldList
Expand Down
2 changes: 1 addition & 1 deletion src/Page/ProductPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ProductPage extends \Page implements PermissionProvider
/**
* @var string
*/
private static $table_name = 'FS_ProductPage';
private static $table_name = 'ProductPage';

/**
* @param bool $includerelations
Expand Down
4 changes: 2 additions & 2 deletions tests/ProductPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testProductDeletion()
$product2->write();
$this->assertTrue($product2->exists());

$versions = DB::query('Select * FROM "FS_ProductPage_Versions" WHERE "RecordID" = '.$productID);
$versions = DB::query('Select * FROM "ProductPage_Versions" WHERE "RecordID" = '.$productID);
$versionsPostPublish = array();
foreach ($versions as $versionRow) {
$versionsPostPublish[] = $versionRow;
Expand All @@ -60,7 +60,7 @@ public function testProductDeletion()
$product2->delete();
$this->assertTrue(!$product2->exists());

$versions = DB::query('Select * FROM "FS_ProductPage_Versions" WHERE "RecordID" = '.$productID);
$versions = DB::query('Select * FROM "ProductPage_Versions" WHERE "RecordID" = '.$productID);
$versionsPostDelete = array();
foreach ($versions as $versionRow) {
$versionsPostDelete[] = $versionRow;
Expand Down

0 comments on commit 8e5c7bf

Please sign in to comment.