Bagisto Forum

    Bagisto

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

    Change product status in code

    General Discussion
    3
    8
    602
    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

      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

        @huckleberry
        are you implementing this in Bagisto?

        1 Reply Last reply Reply Quote 0
        • H
          huckleberry last edited by

          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

            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

              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

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • devansh-webkul
                  devansh-webkul last edited by devansh-webkul

                  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

                    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
                    • First post
                      Last post