Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Admin Stock Status Change OnClick with AJAX

    I'm wanting to practice/learn AJAX by making the stock status of a product change OnClick w/o a page reload in the admin. Any pointers?

    I installed Add to Cart w/ AJAX to get a glimpse at it, but I also had one page check-out installed and felt a bit lost in the thousands of lines of code haha.

    Disclaimer: I might be a little early in asking advice on this, because I haven't tried much of anything yet.

    Should I add a separate custom admin/changestock.php or just try to squeeze it into admin/categories.php? Any security issues that might make this harder to learn with?

    Thanks,
    b

  2. #2
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Admin Stock Status Change OnClick with AJAX

    To maybe address the last first, generally it takes more than a single file to incorporate ajax related code at least to maintain the structure generally expected. There's the javascript/jquery to "collect" the information, then there's a file that is accessed based on the ajax call which then digs into the php side with the result provided back to the javascript/jquery to be processed.

    There is always some amount of security items to be considered or concerned about; however, by starting in your admin area there is a little bit less concern because the file(s) are not directly accessible from outside the admin folder.

    As to other examples that perhaps are less involved, there's Dynamic Price Updater (https://www.zen-cart.com/downloads.php?do=file&id=1301) that uses ajax style calls (haven't received authoritative feedback of the quality of its use), and there is a little more convoluted/involved is product attribute image replaces main product image: https://www.zen-cart.com/downloads.php?do=file&id=699.

    As to the overall concept, if understand correctly you want to be able to click on the quantity, modify it and then when you move away from it you want that to be the value seen by customers. For what it's worth I think there is already a plugin that does that or similar I think called quick status update, though I think it still uses/expects a "save" button to be pressed to cause the update action. My concern with such a "quick" update by moving away from the text block is that the number could be accidentally saved with whatever was entered which could be grossly large or small. Too large and someone could overpurchase, too small (0?) and a product will appear as out-of-stock. Having a sort of "save" button at least forces some level of thought in the modification. The other part of all that is how the system responds just at the verge of the session ending...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Admin Stock Status Change OnClick with AJAX

    Quote Originally Posted by mc12345678 View Post
    To maybe address the last first, generally it takes more than a single file to incorporate ajax related code at least to maintain the structure generally expected. There's the javascript/jquery to "collect" the information, then there's a file that is accessed based on the ajax call which then digs into the php side with the result provided back to the javascript/jquery to be processed.

    There is always some amount of security items to be considered or concerned about; however, by starting in your admin area there is a little bit less concern because the file(s) are not directly accessible from outside the admin folder.

    As to other examples that perhaps are less involved, there's Dynamic Price Updater (https://www.zen-cart.com/downloads.php?do=file&id=1301) that uses ajax style calls (haven't received authoritative feedback of the quality of its use), and there is a little more convoluted/involved is product attribute image replaces main product image: https://www.zen-cart.com/downloads.php?do=file&id=699.

    As to the overall concept, if understand correctly you want to be able to click on the quantity, modify it and then when you move away from it you want that to be the value seen by customers. For what it's worth I think there is already a plugin that does that or similar I think called quick status update, though I think it still uses/expects a "save" button to be pressed to cause the update action. My concern with such a "quick" update by moving away from the text block is that the number could be accidentally saved with whatever was entered which could be grossly large or small. Too large and someone could overpurchase, too small (0?) and a product will appear as out-of-stock. Having a sort of "save" button at least forces some level of thought in the modification. The other part of all that is how the system responds just at the verge of the session ending...
    Thanks for all the info, I'm mostly interested in just changing the status from the "in-stock" (or 1) to "out-of-stock" (to 0). Which is represented in the admin as a green check or red x. I suppose changing the quantity would be interesting to do too, but I tend to not change that value w/o creating a new product.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Admin Stock Status Change OnClick with AJAX

    Quote Originally Posted by wolfderby View Post
    Thanks for all the info, I'm mostly interested in just changing the status from the "in-stock" (or 1) to "out-of-stock" (to 0). Which is represented in the admin as a green check or red x. I suppose changing the quantity would be interesting to do too, but I tend to not change that value w/o creating a new product.
    That *does* make more sense now. I was wondering how just the onclick event alone would support stock level modifications and also would be an improvement for the admin screen. One thing that I've seen in using ajax style calls in the admin though and I haven't gone chasing it relates to meeting/exceeding the timeout at the point the "button" is clicked and how the system responds. Ie. In one specific application whether written properly or not was that the "data area" turned into a login screen that then returned back to the work area causing a work area within a work area instead of refreshing the screen to be one "logical" view instead of one within another... not likely a particular result expected to be seen, but the same "thought" would exist, did the "value" really get updated or what should happen at that point?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,669
    Plugin Contributions
    9

    Default Re: Admin Stock Status Change OnClick with AJAX

    Quote Originally Posted by mc12345678 View Post
    There is always some amount of security items to be considered or concerned about; however, by starting in your admin area there is a little bit less concern because the file(s) are not directly accessible from outside the admin folder.
    only true if the first lines of code are something like:

    PHP Code:
    <?php

    require('includes/application_top.php');
    i have the turning on and off of items available from the categories.php page. not sure if that is a base ZC function or something from a plugin or something i added. in addition, i also created a separate inventory page which allows you turn off an item and/or update the inventory value for a group of items.

    none of these, however, were done using ajax.

    i suppose if you are having page load time issues on the admin side, i would investigate where the holdup might be. if on the other hand, you are doing this project to better familiarize yourself with ajax calls and how they work, i am all for it!

    good luck!
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Admin Stock Status Change OnClick with AJAX

    I saw a second or third reason to support something like this besides the educational value.

    If the number of items or height or whatever would cause the screen position to change by clicking on the default "button" or it is desired to perform the action on multiple items (likely affected by the above) then an in place operation would be more desirable and provide an improved work flow.

    Simple things can make it better and I'm pretty sure that the dev team would consider the result for further incorporation.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Admin Stock Status Change OnClick with AJAX

    Quote Originally Posted by mc12345678 View Post
    I saw a second or third reason to support something like this besides the educational value.

    If the number of items or height or whatever would cause the screen position to change by clicking on the default "button" or it is desired to perform the action on multiple items (likely affected by the above) then an in place operation would be more desirable and provide an improved work flow.

    Simple things can make it better and I'm pretty sure that the dev team would consider the result for further incorporation.
    Yeah I think it could/would be a good improvement to core functionality. It is definitely just something small that I'm hoping to work on just for the educational value added by using ajax.

  8. #8
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Admin Stock Status Change OnClick with AJAX

    So I finally figured this out, I just need to find time to clean up my results before I can share them, will probably double check changes against a fresh install first, then share.

 

 

Similar Threads

  1. Replies: 146
    Last Post: 13 Dec 2020, 09:52 AM
  2. Change the sold out status from 0 in stock to -1
    By PatF in forum General Questions
    Replies: 2
    Last Post: 4 Sep 2011, 09:55 PM
  3. Changing case with onClick
    By mdegrandis in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 24 Apr 2009, 10:29 PM
  4. Change status drop downs in customer admin
    By heimskr75 in forum General Questions
    Replies: 3
    Last Post: 21 Oct 2008, 02:43 AM
  5. Problem With Units In Stock Status Message
    By IronMac in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 5 Jul 2007, 01:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR