• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

Change product status in code

General Discussion
3
8
586
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H
    huckleberry last edited by 31 Aug 2020, 13:16

    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();

    1 Reply Last reply Reply Quote 0
    • V
      Vaishali Agarwal last edited by 31 Aug 2020, 13:43

      @huckleberry
      are you implementing this in Bagisto?

      1 Reply Last reply Reply Quote 0
      • H
        huckleberry last edited by 31 Aug 2020, 19:01

        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.

        1 Reply Last reply Reply Quote 0
        • devansh-webkul
          devansh-webkul last edited by 1 Sept 2020, 07:50

          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 */
          
          1 Reply Last reply Reply Quote 0
          • H
            huckleberry last edited by 1 Sept 2020, 13:05

            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.

            1 Reply Last reply Reply Quote 0
            • devansh-webkul
              devansh-webkul last edited by 1 Sept 2020, 19:14

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • devansh-webkul
                devansh-webkul last edited by devansh-webkul 2 Sept 2020, 05:46 2 Sept 2020, 05:46

                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 use status 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.

                1 Reply Last reply Reply Quote 0
                • H
                  huckleberry last edited by 2 Sept 2020, 12:52

                  OK. that is what I ended up doing, but was hoping there was a better way. thanks for reply.

                  1 Reply Last reply Reply Quote 0
                  5 out of 8
                  • First post
                    5/8
                    Last post