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 Mar 5, 2024
1 parent 141979f commit 52eff1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Extension/ProductVariationsExtension.php
Expand Up @@ -57,7 +57,7 @@ public function updateCMSFields(FieldList $fields)
GridFieldConfig_RecordEditor::create(100)
)
]);

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

if ($this->owner->Variations()->exists()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Model/Variation/Variation.php
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 @@ -82,7 +84,7 @@ class Variation extends DataObject implements Buyable
'InternalItemID' => 'Product Code',
//'Product.Title' => 'Product',
'Title' => 'Variation',
'Price' => 'Price'
'Price.Nice' => 'Price'
];

private static $searchable_fields = [
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 52eff1f

Please sign in to comment.