Skip to content

Commit

Permalink
NumericField for ProductVariations and casting in Gridfield
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerkrauss committed Feb 26, 2024
1 parent 141979f commit a6f2408
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Extension/ProductVariationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Forms\ListboxField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\FieldType\DBCurrency;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ArrayData;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
Expand Down Expand Up @@ -58,6 +59,11 @@ public function updateCMSFields(FieldList $fields)
)
]);

$variationsDataColumns = $variationsGridField->getConfig()->getComponentByType('SilverStripe\Forms\GridField\GridFieldDataColumns');
$variationsFieldCasting = $variationsDataColumns->getFieldCasting();
$variationsFieldCasting['Price'] = DBCurrency::class . '->Nice';
$variationsDataColumns->setFieldCasting($variationsFieldCasting);

$variationsGridField->getConfig()->addComponent($sort = new GridFieldOrderableRows('Sort'));

if ($this->owner->Variations()->exists()) {
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Variation/Variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverShop\Model\Variation;

use SebastianBergmann\Comparator\NumericComparator;
use SilverShop\Cart\ShoppingCart;
use SilverShop\Model\Buyable;
use SilverShop\Model\Order;
Expand All @@ -10,6 +11,7 @@
use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -127,7 +129,8 @@ public function getCMSFields()
{
$fields = FieldList::create(
TextField::create('InternalItemID', _t('SilverShop\Page\Product.Code', 'Product Code')),
TextField::create('Price', _t('SilverShop\Page\Product.db_BasePrice', 'Price'))
NumericField::create('Price', _t('SilverShop\Page\Product.db_BasePrice', 'Price'))
->setScale(2)
);
//add attributes dropdowns
$attributes = $this->Product()->VariationAttributeTypes();
Expand Down

0 comments on commit a6f2408

Please sign in to comment.