Change product status in code
-
I really think this is a simple question and might be an issue with my Laravel knowledge. How do you change a product's status in code. Here is basically what I want to do, but it doesn't work:
$product = Product::find($product_id);
$product->status = false;
$product->Save(); -
@huckleberry
are you implementing this in Bagisto? -
yes, I am trying to update the status of a Bagisto product. I have a package that I am writing and this is in one of my Controllers.
-
Hi @huckleberry,
There is no 'status' column in the products table. You need to check the 'product_flat' table for status.
$product = Product::find($product_id); $flatProducts = $product->product_flats(); /* then save status of specific flat product */
-
So how does the product_flat status work with the attribute status. Do I have to change both to get results? I figured out how to change the attribute status and when you look at the product status is off. But, datagrids and public site still see the product as status = true. If I change product_flat.status, then datagrids and public site see the change. Seems odd that the system would require both status changes in order for something to look Inactive everywhere. Seems like there would be a setter somewhere that would make sure it got everywhere it needed to be.
-
This post is deleted! -
Hi @huckleberry,
Well, that's my mistake, I have not provided proper info.
If you are using the 'Product' model. Then this model is linked with the
attributes
table. If you see the model you will check that there are several methods written to get this.If you are using
ProductFlat
model, then you can usestatus
column.This has been done for avoiding multiple joins in tables. So we have added necessary columns to the
product_flat
table also.At some places, we are using the 'ProductFlat' model and at some places, we are using the
Product
model.So you need to change both the status.
-
OK. that is what I ended up doing, but was hoping there was a better way. thanks for reply.