how status of Product in Magento get changed/saved? - file

I am eager to know how status of Product in Magento get changed/saved?
Requirement-:
Suppose there are existing products which are enabled in Magento...Now If admin Disable particular product from Backend then I need to catch that particular product's Id through code in Magento file system?
So from where Can I get disabled product's id in Magento code? What is the file location & function name for the same? how Can I get that particular id?
Please guide me...

I think the down voting here is a bit unfair. The op is only asking one question - how to get the product id and status of a product after it has been saved.
#Sam - in Magento, instead of finding the exact point in code where a product is being saved, you would typically hook into an event by creating a custom module and use the Magento event/observer facility from within that module.
Have a look through this tutorial which will guide you through the process of creating a module with event/observers: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
Specifically related to your question: the event you are looking for is catalog_product_save_after.
The xml for your event would look similar to this:
<events>
<catalog_product_save_after>
<observers>
<yourmodule>
<class>Yourcompany_Yourmodule_Model_Observer</class>
<method>catalog_product_save_after</method>
</yourmodule>
</observers>
</catalog_product_save_after>
</events>
Your observer is going to look similar to this:
class Yourcompany_Yourmodule_Model_Observer
{
public function catalog_product_save_after($observer)
{
$product = $obvserver->getEvent()->getProduct();
$productStatus = $product->getStatus();
$productId = $product->getId();
}
}
Note - code is untested

Related

Abp One to many Relationship

I have Book and Author Entity.
I tried to establish a relationship between Book and Author, but the AuthorId key did not appear. I wonder how it is done.
enter image description here
First of all, I think you are looking at the tutorials part of the ABP framework document. If you haven't looked, I think you should look at this.
As explained in the document, you can do this as follows:
Open the BookStoreDbContextModelCreatingExtensions class under the EntityFrameworkCore folder of the Acme.BookStore.EntityFrameworkCore project and change the builder.Entity part as shown below
builder.Entity<Book>(b =>
{
b.ToTable(BookStoreConsts.DbTablePrefix + "Books", BookStoreConsts.DbSchema);
b.ConfigureByConvention(); //auto configure for the base class props
b.Property(x => x.Name).IsRequired().HasMaxLength(128);
// ADD THE MAPPING FOR THE RELATION
b.HasOne<Author>().WithMany().HasForeignKey(x => x.AuthorId).IsRequired();
});

CakePHP: Scaffolding after having written edit/view/add

I have an application in which we give a very friendly interface for managing data. This is done through many controllers' add/edit/view functions. But now the requirement has come that we should have "super admins" able to edit anything, and scaffolding will give them a quick and dirty manner of changing data. Since scaffolding uses add/edit/view by default, I've unintentionally overwritten the ability to scaffold.
I can't just go and change all my calls to edit/add for our "user friendly" data managing. So I want to essentially ignore the add/edit/view when, for example, a user has a flag of "yes, please let me scaffold". I imagined it would be something like:
public function edit($id) {
if (admin_user) {
$scaffold;
} else {
[user-friendly version code]
}
}
But no dice. How can I achieve what I want?
suppose you already have admin users and you want to scaffold only super-user:
Also suppose you store the information about beeing a super-user or not in a column named super in the users table
in your core.php
Configure::write('Routing.prefixes', array('admin', 'super));
in your appController
public $scaffold = 'super';
beforFilter() {
if($this->Auth->user('super') && !isset($this->params['super'])
$this->redirect(array('super' => true));
}
Now I can't try this code but the idea should work.
edit: we need to check if we are already in a super_action to avoid infinite redirect

updating a field on contact whenever a new event is created?

Here is the problem I'm trying to solve:
When a new TASK/EVENT is created, if the user is a certain profile - we want to update a field on CONTACT with the day the T/E was created.
I tried doing a workflow rule and field update- but I couldn't get it to work... I think since this is a Standard -Standard object relationship via lookup, it might have a problem doing a field update. Any other ideas?? I'd prefer to use the platform for this one...
HALP!
Thanks
We have done exactly what you are talking about via an Apex trigger. Something like this...
//I'm sure this doesn't compile, but it gives you the idea
trigger taskTrigger on Task( after insert, after update ){
Task t = trigger.new ;
Contact contact = [Select Id from Contact where Id = :t.whoId] ;
contact.yourfield = t.AcitivityDate ;
update contact ;
}

Django Model Filter

I've spent the last few hours looking at Django Docs and similar questions on here but I'm still unclear on how to tackle the problem...
In essense I want to access the list of email addresses relevent to a certain group, so I can send an email to these customers who are part of this group (named group_one, group_two etc)
class Group(models.Model):
name = models.CharField(primary_key=True)
mailing_list = models.ManyToManyField("Customer", null=True)
class Customer(models.Model):
name = models.CharField()
email = models.EmailField(primary_key=True)
I've tried
group_mail_list = Group.objects.filter(name=group_two)
And this returns an Query Object for group_two but when I try to do a __contains filter I get a error:
TypeError: Related Field has invalid lookup: contains
Anyone help me out? Not sure if it's because it's a many-to-many relationship perhaps?
Thanks in advance :)
What you really want is Customers, then. It seems counter-intuitive on the surface, because you're wanting emails for a Group, but that field is on Customer not Group:
Customer.objects.filter(group__name='group_two').values_list('email')

Adding a 1 to many file upload to CRUD

My app has sales listing functionality that will allow the user to add 1 or more photos for the product that they want to sell.
I'm attempting to use the upload/filestore_image of ATK with a Join table to create the relationship - my models:
class Model_Listing extends Model_Table {
public $entity_code='listing';
function init(){
parent::init();
$this->addField('name');
$this->addField('body')->type('text');
$this->addField('status');
$this->addField('showStatus')->calculated(true);
}
function calculate_showStatus(){
return ($this->status == 1) ? "Sold" : "For Sale" ;
}
}
class Model_listingimages extends Model_Table {
public $entity_code='listing_images';
function init(){
parent::init();
$this->addField('listing_id')->refModel('Model_Listing');
$this->addField('filestore_image_id')->refModel('Model_Filestore_Image');
}
}
In my page manager class I have added the file upload to the crud:
class page_manager extends Page {
function init(){
parent::init();
$tabs=$this->add('Tabs');
$s = $tabs->addTab('Sales')->add('CRUD');
$s->setModel('Listing',array('name','body','status'),array('name','status'));
if ($s->form) {
$f = $s->form;
$f->addField('upload','Add Photos')->setModel('Filestore_Image');
$f->add('FileGrid')->setModel('Filestore_Image');
}
}
}
My questions:
I am getting a "Unable to include FileGrid.php" error - I want the user to be able to see the images that they have uploaded and hoped that this would be the best way to do so - by adding the file grid to bottom of the form. - EDIT - ignore this question, I created a FileGrid class based on the code in the example link below - that fixed the issue.
How do I make the association between the CRUD form so that a submit will save the uploaded files and create entries in the join table?
I have installed the latest release of ATK4, added the 4 filestore tables to the db and referenced the following page in the documentation http://codepad.agiletoolkit.org/image
TIA
PG
By creating model based on Filestore_File
You need to specify a proper model. By proper I mean:
It must be extending Model_Filestore_File
It must have MasterField set to link it with your entry
In this case, however you must know the referenced ID when the images are being uploaded, so it won't work if you upload image before creating record. Just to give you idea the code would look
$mymodel=$this->add('Model_listingimages');
$mymodel->setMasterField('listing_id',$listing_id);
$upload_field->setModel($mymodel);
$upload_field->allowMultiple();
This way all the images uploaded through the field will automatically be associated with your listing. You will need to inherit model from Model_Filestore_File. The Model_Filestore_Image is a really great example which you can use. You should add related entity (join) and define fields in that table.
There is other way too:
By doing some extra work in linking images
When form is submitted, you can retrieve list of file IDs by simply getting them.
$form->get('add_photos')
Inside form submission handler you can perform some manual insertion into listingimages.
$form->onSubmit(function($form) uses($listing_id){
$photos = explode(',',$form->get('add_photos'));
$m=$form->add('Model_listingimages');
foreach($photos as $photo_id){
$m->unloadDdata()->set('listing_id',$listing_id)
->set('filestore_image_id',$photo_id)->update();
}
}); // I'm not sure if this will be called by CRUD, which has
// it's own form submit handler, but give it a try.
You must be careful, through, if you use global model inside the upload field without restrictions, then user can access or delete images uploaded by other users. If you use file model with MVCGrid you should see what files they can theoretically get access to. That's normal and that's why I recommend using the first method described above.
NOTE: you should not use spaces in file name, 2nd argument to addField, it breaks javascript.

Resources