Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GridField editing relations to products #2

Open
samthejarvis opened this issue Dec 7, 2013 · 12 comments
Open

GridField editing relations to products #2

samthejarvis opened this issue Dec 7, 2013 · 12 comments

Comments

@samthejarvis
Copy link

Latest SS3.1, apparent in fresh installs w/ latest categories module
Using a GridField to manage a relation between a Page and Product, getting:

Fatal error: Call to a member function stat() on a non-object in C:\wamp\www\framework\model\DataObject.php on line 3226

Removing the searchable_fields from ProductCategory_Extension fixed this as calling ->relObject('Category') on a Product returns null, can't figure out why.

Changing 'Category' in searchable_fields to 'ProductCategories' (the actual name of the belongs_many_many relation) throws the same error.

Any ideas?

@frankmullenger
Copy link
Contributor

Hi Sam, thanks for reporting this. Not entirely sure what the issue might be, which version of Silverstripe are you using exactly? Also, do you have a code snippet?

@frankmullenger
Copy link
Contributor

Hi @samthejarvis, I've tested SwipeStripe with 3.1.2 and categories appear to be working for me on Product pages. Have not tried in GridField but this issue may be more closely related to GridField, at this point I'm not sure what the issue might be - could be a good idea to ask on IRC or the forums. Will close for now.

@threesquared
Copy link

Getting this same error when trying to manage a Product to Product relationship with GridField. Removing the searchable_fields from ProductCategory_Extension fixed it.

@stevie-mayhew
Copy link
Member

Yeah we have had this problem as well, I've also had to remove the searchable fields. @frankmullenger can you reopen this one?

@frankmullenger
Copy link
Contributor

Guess this needs a little more investigation 😄

@dhensby
Copy link

dhensby commented Jun 11, 2014

+1 I'm getting this too

It appears to be an issue with the ProductCategory_Extension::$searchable_fields

It works if I change it to:

    public static $searchable_fields = array(
-       'Category' => array(
+       'ProductCategories.Title' => array(
            'field' => 'TextField',
            'filter' => 'ProductCategory_SearchFilter',
            'title' => 'Category'
        )
    );

Edit: You can replicate this by setting up a many_many with a Product and some other DataObject and the automatic CMSFields that are generated cause the error

@dhensby
Copy link

dhensby commented Jun 12, 2014

A very nasty workaround in the mean-time is:

mysite/_config.php

$searchableFields = Config::inst()->get('Product', 'searchable_fields');
$searchableFields['ProductCategories.Title'] = $searchableFields['Category'];
unset($searchableFields['Category']);
Config::inst()->remove('Product', 'searchable_fields');
Config::inst()->update('Product', 'searchable_fields', $searchableFields);
unset($searchableFields);

@dhensby
Copy link

dhensby commented Jun 12, 2014

This "fix" actually causes another problem with the GridFieldAddExistingAutocompleter.

So if you want to use the GridFieldAddExistingAutocompleter to relate Products to another object the SQL query generated has no "from" clause defined.

This is something to do with the apply function in ProductCategory_SearchFilter as it's using SiteTree_Live and doing an inner join. This appears to be knocking the SiteTree table out of the from clause and into a join.

When I do this in my config, it all works as expected:

$searchableFields = Config::inst()->get('Product', 'searchable_fields');
//$searchableFields['ProductCategories.Title'] = $searchableFields['Category'];
unset($searchableFields['Category']);
Config::inst()->remove('Product', 'searchable_fields');
Config::inst()->update('Product', 'searchable_fields', $searchableFields);
unset($searchableFields);

@stevie-mayhew
Copy link
Member

We should also get #1 merged into the 2.1 branch, as well as change the public declarations within the DataExtension to private.

@frankmullenger
Copy link
Contributor

"You can replicate this by setting up a many_many with a Product and some other DataObject and the automatic CMSFields that are generated cause the error" - I still couldn't replicate for some reason, does anyone have some boilerplate code for replicating this issue?

@dhensby
Copy link

dhensby commented Jun 13, 2014

@frankmullenger

class Material extends DataObject {
    private static
        $db = array(
            'Title' => 'Varchar(255)',
        ),
        $many_many = array(
            'Products' => 'Product',
        );
}

class ProductExtension extends DataExtension {
    private static $belongs_many_many = array(
        'Materials' => 'Material',
    );
}

This is the basic idea. If you go to the CMS to create a Material and then try to use the auto complete field on the grid for managing the Material -> Product relation it will error.

@anhld
Copy link

anhld commented Jul 7, 2014

I am getting same error here, sample code from @dhensby , SS 3.1.5. Is it able to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants