I get the following SQL error:
SQL Error: 1066: Not unique table/alias: 'I18n__name'
when doing a simple find query.
Any ideas on possible situations that may have caused this??
I'm using a bindModel method to retrieve the data is that related?
This is my code:
$this->Project->bindModel(array(
'hasOne' => array(
'ProjectsCategories',
'FilterCategory' => array(
'className' => 'Category',
'foreignKey' => false,
'conditions' => array('FilterCategory.id = ProjectsCategories.category_id')
))));
$prlist = $this->Project->find('all', array(
'fields' => array('DISTINCT slug','name'),
'conditions' => array('FilterCategory.slug !='=>'uncategorised')
))
You have not used or initialized the required table/model you are using in your controller. Use var $uses = array('your_table_name');
I do not have a direct answer to my problem. However after some research I came to the following conclusion.
I've decided to change my methodology and stop using the translate behavior in cakephp.
I've found another behavior called i18n which works much better when dealing with associated models. You can read about it http://www.palivoda.eu/2008/04/i18n-in-cakephp-12-database-content-translation-part-2/#comment-1380
In cakephp book it says :
"Note that only fields of the model
you are directly doing find on will
be translated. Models attached via
associations won't be translated
because triggering callbacks on
associated models is currently not
supported."
I'm not sure if I made the right choice however I have been struggling to get the translate behavior to work in cakephp and this solution at least makes the project I'm working functional.
Related
I made a custom field in prestashop.
I would like to know if there is some way to make this field only required on the frontend and not for administrators.
this is my code in Customer class
array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
Thanks in advance
Can't think of a quick way to make this possible exactly as you want it, so here are two suggestions:
1 - Remove the 'required' => true from the definition and create some kind of custom validation like if (Tools::getValue('type ') == "") { return false; } in an override of the front office AuthController (Warning: code is completely untested and should definitely be improved, also according to your particular PS version).
2 - Use frontend validation by giving the frontend form field the required attribute (you should do this even if oyu use 1)
I've got a problem with sorting on a many-to-many relationship. What I'm trying to achieve seems like it should be fairly straightforward, but after a lot of banging my head against Fuel, I still can't get it to work.
(Incidentally, I realise more-or-less this question has been asked before, but since (a) at that time it wasn't possible to sort on a lazy-loading relationship, and (b) I've got a lot more detail of the exact problem I'm having, I thought it would be worth asking as a separate question...)
Here's the problem I'm having:
I have an "Item" model. Items can have children (which are also items), joined via a many-to-many relationship through an "items_items" table with a 'parent_id' and 'child_id' column. The "items_items" table also has a "sortorder" column, so that the order of the child items can be set.
Creating a separate model for this relationship seemed like overkill to me, so the order is updated by an observer that updates child items' sortorder when the parent is saved (via an "_event_after_save" method on Model_Item). This seems to work fine.
However, the problem I'm having is that I can get sort order working either with lazy loading or with eager loading, but not both. Whichever one works, the other throws Fuel errors, so the only way currently of getting both eager and lazy loading to work is to scrap the 'order_by' clause when eager-loading. Here are the three ways I've tried defining the 'children' relationship:
Approach #1
This is the approach that the relevant page in FuelPHP's documentation suggests should work.
No errors on eager or lazy load, but either way, order_by is not respected (child items are ordered by id, not by sortorder)
'children' => array(
'table_through' => 'items_items',
'key_through_from' => 'parent_id',
'key_through_to' => 'child_id',
'model_to' => 'Model_Item',
'order_by' => array(
'items_items.sortorder' => 'ASC'
),
)
Approach #2
Works as desired with eager loading
Causes Fuel error with lazy loading ("Column not found: 1054 Unknown column 'items_items.sortorder' in 'order clause'")
This seems to be because items_items is aliased to 't0_through' in the JOIN clause, but not in the ORDER BY clause.
'children' => array(
'table_through' => 'items_items',
'key_through_from' => 'parent_id',
'key_through_to' => 'child_id',
'model_to' => 'Model_Item',
'conditions' => array(
'order_by' => array(
'items_items.sortorder' => 'ASC'
),
)
)
Approach #3
Works as desired with lazy loading
Causes Fuel error with eager loading (effectively the reverse of take #2, above)
'children' => array(
'table_through' => 'items_items',
'key_through_from' => 'parent_id',
'key_through_to' => 'child_id',
'model_to' => 'Model_Item',
'conditions' => array(
'order_by' => array(
't0_through.sortorder' => 'ASC'
),
)
)
In a slightly desperate hack, I tried combining approaches 2 and 3 above by defining two separate relationships ('children' and 'child') - one for eager loading, the other for lazy loading, but it still breaks my app, because it makes the delete process throw similar errors. I could attempt to fix this, but I feel like that would just be piling hack upon hack. What I'd like instead is a solid way of ordering child items that works whether they were eager or lazy loaded. Fuel's docs suggest this should be doable (approach #1, above), but I just can't get that to work...
Any help would be very much appreciated!
From the ORM's point of view, the "through_table" does not exist. It is only defined so it can construct the SQL needed to make the relation work. That also means that additional fields in the "through_table" are not supported, it can only contain key values.
If you want attributes (additional columns) in the through table, it becomes a standard table in your database, for which a model is required. Your many-2-many relation then breaks down into two one-2-many relations.
Note that both can exist at the same time, so you can still use the many-to-many if you don't need to query or use columns in the through table.
I've finally managed to fix this issue. It turned out to be a problem with the current release of Fuel's ORM (version 1.7).
What worked for me was to update the ORM to a more recent development version (60cc4eb576 on the ORM's 1.8/develop branch), and then to set the 'order_by' on the many-to-many relation like this:
...
'conditions' => array(
'order_by' => array(
'items_items.sortorder' => 'ASC'
),
)
...
This is a combination of approaches 2 and 3 above, and not quite the syntax that the documentation currently suggests, but seems to work as expected / desired for both eager- and lazy-loading.
here is the code that runs and that results in two sentmessage objects getting added to the table:
$sentmessage = null;
//add entry into sent message table Tx_BpsMessagecentre_Domain_Model_Sentmessage
$sentmessage = $this->objectManager->create('Tx_BpsMessagecentre_Domain_Model_Sentmessage');
//now just fill in the object
$sentmessage->setBpsmessageid($bPSMessage->getUid());
$sentmessage->setBody($bPSMessage->getBody());
$sentmessage->setSubject($bPSMessage->getSubject());
$sentmessage->setCouponlist($bPSMessage->getCouponlist());
$sentmessage->setHallname($bPSMessage->getHall()->getHall());
$sentmessage->setHalladdress($bPSMessage->getHall()->getAddress());
$sentmessage->setHallurl($bPSMessage->getHall()->getUrl());
$sentmessage->setBanner($bPSMessage->getBanner());
$this->sentmessageRepository->add($sentmessage);
$this->objectManager->get('Tx_Extbase_Persistence_Manager')->persistAll();
die; //if I take out this die and the persist call above I still get two records added
I am using typo3 v 4.5.32 with extbase 1.3.
The sentmessage object is one I had to create manually - ie without extension builder, so there might be some misconfiguration in the TCA somewhere but I have no idea what would cause this.
Thanks
PS: a piece of my ext_localconf.php showing some of my plugins
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Bpsmonthly',
array(
'BPSMessage' => 'cronMonthlys'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Bpsbirthdays',
array(
'BPSMessage' => 'cronBirthdays'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'BpsAnnuals',
array(
'BPSMessage' => 'cronAnnuals'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Ok, found the bug, it was actually caused by my debug code that spit some url out to the page, the url got resolved by the browser to hit the action again (probably a url in an img tag) and boom. so the bug only exists while debugging. I love programming.
Is there a way to delete my dumbest questions from stackoverflow?
most probably you have the two plugins from the same extension in your website - therefore everything is processed twice.
Maybe persisting your changes takes a loooooong time (e.g., >30 sec). In such cases, I experienced that under some conditions the browser posts again (!) the query, resulting in what you describe.
As I experienced the same behaviour, but under other circumstances, I'm adding my case as an answer here, maybe it helps someone.
If you're working with multiple records in the same form (model having child records) and they all are not persisted, make sure to not set the parent record on the child records.
This will lead to the multiple-rows behaviour:
$foo = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Foo');
$bar = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Bar');
$bar->setFoo($foo); // <-- Should not be done
$foo->add($bar);
I've got the following problem. I built a PHP file, which reads categories from a file, to impor tthem into Magento. I am able to read the file, no problem. The connection via NuSOAP to the Magento API works aswell. I can get the SessionID and I am able to get data, like Information for a category, also its possible to delete categories.
But, whenever I try to create or update anything, it throws an error. The rights for the user are ok aswell. For example, when I create a category, I add the usual data to the call:
$proxy->call(
$sessionId,
'category.create',
$rootCategory, array(
'name' => "TEST",
'is_active' => '1',
'page_layout' => 'two_columns_right',
'description' => "TEST",
'meta_title' => "TEST",
'meta_description' => '',
'meta_keywords' => "TEST",
'include_in_menu' => '0',
'display_mode' => 'PRODUCTS',
'available_sort_by' => 'price',
'default_sort_by' => 'price',
'is_anchor' => '0'
)
);
All the time, it says:
(
[faultcode] => 102
[faultstring] => Category not exists. )
Which is not true. The $rootCategory is definatly a category, which is existing. I tried all other categories, I tried to add a 'path' to the info, I tried to use less information (only the neccesary stuff), I tried to read existing categories to get their IDs, NOTHING works. It always throws this faultcode.
Same happens, when I try to update a category, or create /update a product. Deleting is no problem at all.
Do you see the problem?
i just compared your NON working exemple and i found this while comparing it with another exemple i has ( i do not pretent to be expert ) ..
but seems like your $new_category, array(blahblha) ...
should be INSIDE an array according to the exemple i already have
like this array($new_category,array(blahblah) ...
this is the mains difference i just saw ..
here is the EXEMPLE i just pulled out of the web ... Adapt to your needs..
$proxy->call(
$sessionId,
'category.create',
array(
3,
array(
'name'=>'New openerp',
'is_active'=>1,
'include_in_menu'=>2,
'available_sort_by'=>'position',
'default_sort_by'=>'position')) );
Have you tried specifying the category_id key in your $rootCategory within the call:
$selectedCategory['category_id'],
array('name'=>'New Category Through Soap')
)
Reference: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category
We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.