Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Can't create translations of Product pages #2

Closed
jnckka opened this Issue · 15 comments

3 participants

@jnckka

I've two language website English and French... I'm using silverstripe-shop module with SilverStripe v2.4.7

Product Group translation is working properly but when I translate a product item I get the following error:

RROR [User Error]: Uncaught Exception: Object->__call(): the method 'productgroups_original' does not exist on 'Product'
IN POST /SilverStripe-v2.4.7/admin/getitem?ID=23&locale=fr_FR&ajax=1
Line 724 in D:\server\www\SilverStripe-v2.4.7\sapphire\core\Object.php

Source

715:

716: default :
717: throw new Exception (
718: "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config,
true)
719: );
720: }
721: } else {
722: // Please do not change the exception code number below.
723:

  • 724: throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175); 725: } 726: } 727:
    728: // ----------------------------------------------------------------------------------------------------------------- 729:
    730: /**

Trace

    Object->__call(ProductGroups_original,Array)
    line 117 of HasManyComplexTableField.php

    Product->ProductGroups_original()
    line 117 of HasManyComplexTableField.php

    HasManyComplexTableField->selectedItemIDs()
    line 126 of HasManyComplexTableField.php

    HasManyComplexTableField->ExtraData()
    line 369 of ViewableData.php

    ViewableData->obj(ExtraData,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(ExtraData,,1)
    line 763 of .cache.sapphire.templates.RelationComplexTableField.ss

    include(C:\Windows\Temp\silverstripe-cacheD--server-www-SilverStripe-v2.4.7.cache.sapphire.templates.RelationComplexTableField.ss)
    line 429 of SSViewer.php

    SSViewer->process(ManyManyComplexTableField)
    line 342 of ViewableData.php

    ViewableData->renderWith(RelationComplexTableField)
    line 275 of ComplexTableField.php

    ComplexTableField->FieldHolder()
    line 64 of HasManyComplexTableField.php

    HasManyComplexTableField->FieldHolder()
    line 93 of CompositeField.php

    CompositeField->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 73 of .cache.sapphire.templates.TabSetFieldHolder.ss

    include(C:\Windows\Temp\silverstripe-cacheD--server-www-SilverStripe-v2.4.7.cache.sapphire.templates.TabSetFieldHolder.ss)
    line 429 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 58 of .cache.sapphire.templates.TabSetFieldHolder.ss

    include(C:\Windows\Temp\silverstripe-cacheD--server-www-SilverStripe-v2.4.7.cache.sapphire.templates.TabSetFieldHolder.ss)
    line 429 of SSViewer.php

    SSViewer->process(TabSet)
    line 342 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 80 of TabSet.php

    TabSet->FieldHolder()
    line 369 of ViewableData.php

    ViewableData->obj(FieldHolder,,,1)
    line 446 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 77 of .cache.sapphire.templates.Includes.Form.ss

    include(C:\Windows\Temp\silverstripe-cacheD--server-www-SilverStripe-v2.4.7.cache.sapphire.templates.Includes.Form.ss)
    line 429 of SSViewer.php

    SSViewer->process(Form)
    line 342 of ViewableData.php

    ViewableData->renderWith(Array)
    line 1108 of Form.php

    Form->forTemplate()
    line 1135 of Form.php

    Form->formHtmlContent()
    line 391 of LeftAndMain.php

    LeftAndMain->getitem(SS_HTTPRequest)
    line 193 of Controller.php

    Controller->handleAction(SS_HTTPRequest)
    line 143 of RequestHandler.php

    RequestHandler->handleRequest(SS_HTTPRequest)
    line 147 of Controller.php

    Controller->handleRequest(SS_HTTPRequest)
    line 282 of Director.php

    Director::handleRequest(SS_HTTPRequest,Session)
    line 125 of Director.php

    Director::direct(/admin/getitem)
    line 127 of main.php

    Hope there is a solution for this problem
    Thank you

@jedateach
Owner

Hi jnckka, I'll have a look to see if I can find out what is wrong. If you find a fix, please let me know :)

@jnckka

Hello @jedateach

Hope you can find quick solution for this problem.. It is urgent.
I've accutually launced a client website and I'm in a bad situation now... They cann't translate product page or even can't make a product order in French language :(

translating a product is important for multilingual websites.. Hope you find a fix soon :)

I would like to contribute to SS Shop and I'm Beginner in PHP.

@jedateach
Owner

I think I just need to find out how to exclude certain fields from being translatable...or whatever the alternative is.

@jedateach
Owner

Line 511 of Translatable.php includes all many_many fields as translatable

I'm still trying to figure out why the ProductGroups (ManyManyComplexTableField) field is included for translation. It doesn't need to be.

@jnckka

BTW, I can translate product group and product subgroup , but when I translate product page the above error occurred.

To know the problem more I've added a product in English and I've added the same product in French, so on English front-end when I added the product to the cart and switch back to French and I get the following problem:

Debug (Versioned::get_version() in line 978 of Versioned.php)

SELECT "SiteTree_versions"."ClassName", ....

Debug (Versioned::get_version() in line 979 of Versioned.php)

(bool) false

[User Error] Versioned::get_version: Couldn't get Product.389, version 2
GET /SilverStripe-v2.4.7/products/filter/

Line 980 in D:\server\www\SilverStripe-v2.4.7\sapphire\core\model\Versioned.php
Source

971 Versioned::set_reading_mode('');
972
973 $baseTable = ClassInfo::baseDataClass($class);
974 $query = singleton($class)->buildVersionSQL("\"{$baseTable}\".\"RecordID\" = $id AND \"{$baseTable}\".\"Version\" = $version");
975 $record = $query->execute()->record();
976 $className = $record['ClassName'];
977 if(!$className) {
978 Debug::show($query->sql());
979 Debug::show($record);
980 user_error("Versioned::get_version: Couldn't get $class.$id, version $version", E_USER_ERROR);
981 }
982
983 Versioned::set_reading_mode($oldMode);
984 return new $className($record);
985 }
986

Thank you for your cooperation @jedateach

@jedateach
Owner

I've created issue #6 for the version issue.

@jnckka

Hope we find quick fix for these problems @jedateach.

@jedateach
Owner

@jnckka, Sorry to report I'm no longer going to actively try to resolve this, at least not until a version1.0 release. My current focus isn't on getting translation aspects working.

What I have found is that if you comment out line 511 of sapphire/core/model/Translatable.php, the translating will work for Product pages.

<?php

//from line 506

    function setOwner($owner, $ownerBaseClass = null) {
        parent::setOwner($owner, $ownerBaseClass);

        // setting translatable fields by inspecting owner - this should really be done in the constructor
        if($this->owner && $this->translatableFields === null) {
            $this->translatableFields = array_merge(
                array_keys($this->owner->inheritedDatabaseFields()),
                array_keys($this->owner->has_many())//,
                //array_keys($this->owner->many_many())    //this line here
            );
        }
    }

Asking on the #silverstripe IRC channel, @zauberfisch believes that relations (many_many in our case) shouldn't be translated. It is possible this may be a SilverStripe bug, or I may just not understand how Translatable works well enough.

I'll also note that Translatable has become it's own module, found here:
https://github.com/silverstripe/silverstripe-translatable/blob/master/code/model/Translatable.php#L506
The problematic lines don't appear to have changed. You may be able to ask the contributors if they can help you resolve the issue.

I'll leave the issue open, and mark it to be fixed before version 1.0. I encourage you to continue pursuing a fix, you may be able to find someone who's had the same problem. Sorry I can't be more help.

@jnckka

@jedateach thank you.

Commenting line 511 fixes my problem temporarily :)

@jedateach
Owner

Some discussion in IRC:
http://logs.simon.geek.nz/index.php?date=2012-03-05 - search "Translatable"

@gordonbanderson

I've only just chanced upon this bug report, I came upon this problem a few months ago and resolved it by using the DataObjectManager instead of SilverStripe's core editing tools. I simply changed ManyManyComplexTableField to ManyManyDataObjectManager

git show a8b3a59343317a611ca2f660b2caad1bef85fe95
commit a8b3a59343317a611ca2f660b2caad1bef85fe95
Author: Gordon Anderson <gordon.b.anderson@gmail.com>
Date:   Fri Jan 20 21:53:19 2012 +0700

Products: Fix for translation of products and product groups

diff --git a/ecommerce/code/products/Product.php b/ecommerce/code/products/Product.php
index d23059b..62ee800 100644
--- a/ecommerce/code/products/Product.php
+++ b/ecommerce/code/products/Product.php
@@ -165,7 +165,7 @@ class Product extends Page  implements Mappable {
            $fields->addFieldToTab('Root.Content.Main', $internalLink);

            $fields->addFieldsToTab(
-                       'Root.Content.Product Groups',
+                       'Root.Content.ProductGroups',
                    array(
                            new HeaderField('ProductGroupsHeader', _t('Product.ALSOAPPEARS')),
                            $this->getProductGroupsTable()
@@ -364,7 +364,7 @@ class Product extends Page  implements Mappable {
            }
    }
    protected function getProductGroupsTable() {
-               $tableField = new ManyManyComplexTableField(
+               $tableField = new ManyManyDataObjectManager(
                    $this,
                    'ProductGroups',
                    'ProductGroup',

I realise this adds a dependency on DataObjectManager module though which may be undesirable

@gordonbanderson

It does also suggest a bug in core Silverstripe :(

@jedateach
Owner

Thanks for sharing! Yeah, it does appear to be a SS bug. We might be able to write a custom version of ManyManyComplexTableField to use instead. I'd prefer not to rely on dataobjectmanager.

That might be a suitable workaround...I've done similar with another ss bug - #15

@jedateach
Owner

This should be re-tried now that the shop module is based on SS3.

@jedateach jedateach closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.