Joomla: get items modified on setState method - php

I have a component on two websites.
When an user insert, update or delete an item in the first website, the same action must be performed on the second website. I made that using the postSaveHook() method: when an action is performed in the first site, I connect to the database of the second site and replicate the action.
I need to do the same thing when an user changes the items' state: if he/she unpublishes two items, for example, the items must be unpublished in the second site. I tried to change the setState() method to do that, but inside this method I couldn't get any referente to the items changed.
Does anybody know another solution or how to do that with setState()?
P.S. Sorry about my English.

Finally I found the solution: override the method public function publish(&$pks, $value = 1) of the class JModelAdmin. In this method I have all the primary keys of the items changed. Then I was able to get their states and update the items on the second site.

Related

How to keep track of related table id in other controller?

I'm building a module in Prestashop that requires multiple Controllers.
I decided to add them in the Tab, with one visible (the front one), and the others that are related to the first one, in hidden.
When I go to that main admin controller via the menu, it works fine, listing the various elements (renderList) and adding/updating/deleting them also.
Now, when I click on a the view icon, I go to my other admin controller that manage that specific entry (sub list, with it's own form, but related to the parent id).
The problem now, is that I redirect by keeping the correct url, but then, on my sub page, if I click on create for example, I lost the parent_id. And after that, I can't create an entry because it's missing it's parent id.
How can I do to say to this sub controller to keep the id I gave it ?
So far, the only solution I come from is to do like this :
In my sub controller, I should always have id_other_model in the url, so I added this method :
public function initProcess() {
parent::initProcess();
self::$currentIndex .= '&id_other_model='.(int)Tools::getValue('id_other_model');
}
And so far it works well.
If there is a better alternative, I'd appreciate to know it :)

Opencart Modification

I am currently using OpenCart 1.5. I need to display the product purchased in the orders page inside the admin: sales/order. along with the Order_id, customer, status, total, etc...
Should I be able to do this with a module? or can I modify the model (order.php) with another database query. Currently it is called getOrders($data = array()) but it only queries the .order_status database so therefore I can't return the product's name as part of the foreach results in the controller nor the view. Although line 562 in the same model looks pretty familiar to what I want but it is only used after an action is clicked on by the user.
Any help?
You have two choices:
either You make Your edits using the vQmod XML file, while the original code stays intouched
or You make Your edits in the code directly (which may cause problems if You'd decide to upgrade in the future)
Anyway, a module won't do that (unless You think of vQmod edits as a module). You would need to edit the controller - getList() method and the model - getOrders() method. Think wisely how much information You want to display, as products may have other options and You may end up in a juggernaut query and only the list of 20 orders may take few seconds to complete...
Good luck.

Change Product type in magento

I have two products and their type is "Grouped Product" now I want to change this products in to simple product. Is there any way to do so?
Some links says I have to change directly from database. I tried this but nothing changes. Is there any way to do it?
If it's only 2 maybe you should just create 2 new products with same url and change the url of the old ones.
Alternatively you could do some programming.
Maybe start with this class Mage_Catalog_Model_Product_Type_Grouped.
the public function getAssociatedProducts returns an array of associated products which you can simply sort through applying whatever logic before creating your new products.
You have to deal with store scope etc during this process but there's lots of tutorials.
product type cannot be changed in admin!
may be you could go "catalog_product_entity" table and change the type_id from grouped to simple, but i dunno whether it induced new error, but one thing i only know is you must lost the grouped item linkage.
Have you rebuilt the indices (Admin / System / Index Management) and refreshed the cache (Admin / System / Cache Management)?

Symfony 1.3: Need to override backend filter field's set of data

My project is using Symfony 1.3.11, PHP version is 5.3.3.
Let me explain my case and my problem:
We wanted to add another kind of user, not just "user" and "admin" (using sfGuardPlugin). I did add "business" and I did give him permissions to only ONE admin module -- "purchases" (accessing own and under some conditions -- other people's purchases made on the site).
The "business" user can be associated to one or more Partners (firms) registered in the site, effectively allowing us to handle business owners or representatives a wee bit differently.
When the "business" user accesses the admin section, the list of purchases he sees must be this: All Purchases for all Products of all Partners he has associated with him. (Not exactly a trivial query).
I did that, in my opinion, in a stupid manner, but it does work -- namely overriding the "apps/backend/modules/purchase/actions/actions.class.php#executeIndex". I had to first copy-paste some code from the version of that method in the cache.
In short, I did hook myself to the "executeIndex" and added a code to do the proper Criteria, and the code works.
The problem now is this:
The filter field above the list (the one containing the Product list) does contain all possible Products. We want it to only contain all Products for all Partners the current user is associated with.
Thing is, it's my first time having to override the admin's filters and I am lost as to where should I plug my code.
Any help is appreciated. Thanks for your time.
UPDATE: Strangely very unpopular question. Nobody ever had to do this? Wow.
You have to unset the product_list and set another widget with the filtered choices.
Check this post where I explain something like that but using doctrine. In your case the sfGuardUserForm is your somthingFilterForm.
You could also filter data using this method. This is a little more elegant but both would work.

Adding interactions to admin pages generated by the admin generator

I am using Symfony 1.2.9 (with Propel ORM) to create a website. I have started using the admin generator to implement the admin functionality.
I have come accross a slight 'problem' however. My models are related (e.g. one table may have several 1:N relations and N:N relations). I have not found a way to address this satisfactorily yet. As a tactical solution (for list views), I have decided to simply show the parent object, and then add interactions to show the related objects.
I'll use a Blog model to illustrate this.
Here are the relationships for a blog model:
N:M relationship with Blogroll (models a blog roll)
1:N relationship with Blogpost (models a post submitted to a blog)
I had originally intended on displaying the (paged) blogpost list for a blog,, when it was selected, using AJAX, but I am struggling enough with the admin generator as it is, so I have shelved that idea - unless someone is kind enough to shed some light on how to do this.
Instead, what I am now doing (as a tactical/interim soln), is I have added interactions to the list view which allow a user to:
View a list of the blog roll for the
blog on that row
View a list of the posts for the blog on that row
Add a post for the blog on tha row
In all of the above, I have written actions that will basically forward the request to the approriate action (admin generated). However, I need to pass some parameters (like the blog id etc), so that the correct blog roll or blog post list etc is returned.
I am sure there is a better way of doing what I want to do, but in case there isn't here are my questions:
How may I obtain the object that relates to a specific row (of the
clicked link) in the list view (e.g. the blog object in this example)
Once I have the object, I may choose to extract various fields: id etc.
How can I pass these arguments to the admin generated action ?
Regarding the second question, my guess is that this may be the way to do it (I may be wrong)
public function executeMyAddedBlogRollInteractionLink(sfWebRequest $request)
{
// get the object *somehow* (I'm guessing this may work)
$object = $this->getRoute()->getObject();
// retrieve the required parameters from the object, and build a query string
$query_str=$object->getId();
//forward the request to the generated code (action to display blogroll list in this case)
$this->forward('backendmodulename',"getblogrolllistaction?params=$query_string");
}
This feels like a bit of a hack, but I'm not sure how else to go about it. I'm also not to keen on sending params (which may include user_id etc via a GET, even a POST is not that much safer, since it is fairly sraightforward to see what requests a browser is making). if there is a better way than what I suggest above to implement this kind of administration that is required for objects with 1 or more M:N relationships, I will be very glad to hear the "recommended" way of going about it.
I remember reading about marking certain actions as internal. i.e. callable from only within the app. I wonder if that would be useful in this instance?
I'm assuming your application is called backend. Suppose there are two models, BlogPost and BlogPostComment. These are managed using admin generated modules called blog_post and blog_post_comment.
I believe you want a link against each BlogPost displayed on the list page at backend.php/blog_post. The links take you to backend.php/blog_post_comment, which should only show comments related to the relevant BlogPost.
Under apps/backend/blog_post/templates, create a file called _commentslink.php and put this in it:
View Comments
Then in apps/backend/blog_post/config/generator.yml, you need to include this partial in the fields for the list view:
....
param:
config:
list:
display: [ id, title, _commentslink ]
Note the _commentslink - the _ tells it to use a partial instead of looking for the field in the model. Your object is available in this partial as $<name of model> - $blog_post in this case.
Essentially, all this method does is links to the same action as the filter on the comments list normally goes to, passing the relevant condition to it to make it filter by blogpost_id.
If you've got CSRF protection enabled in the backend, you'll need to disable it, or this method won't work. This is set in apps/backend/config/settings.yml. There will be a setting in there called csrf_secret - it should be set to false to disable csrf.
You should try symfony 1.3/1.4 out if you need support for 1:N relationships in forms. 1.3 is in my experience a relatively hassle free upgrade from 1.2.x - 1.4 is the same, but with deprecated features removed.

Categories