Page 342 of 342 FirstFirst ... 242292332340341342
Results 3,411 to 3,418 of 3418
  1. #3411
    Join Date
    Jul 2012
    Posts
    16,040
    Plugin Contributions
    17

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by Dave224 View Post
    This post picks up following the discussion of "How to control extra_cart_actions file loading order" in the General Questions forum.

    The offer for mc... to add a notifier in the includes/extra_cart_actions/stock_by_attributes.php file would most likely solve my problem, but I'm not sure it's the best solution. If a notifier is added, it should be at the start of the file.

    I need to bring up a form and process the customer's responses to the form when a certain product with attributes is added to the shopping cart. So my extra_cart_actions file detects the product being added to the cart, saves the $_POST variables (because $_POST data is lost on redirect), and redirects to files that display the form and when the form is submitted, processes the responses. For reasons that escape me at the moment, the $_POST variables are not restored until the extra_cart_actions file is executed again later in the add product to cart process. When I developed this code, SBA did not have an extra_cart_action file, so the missing $_POST data was not missed by other extra_cart_actions files. But now, SBA has a file there, and it runs before my file, and it doesn't like missing $_POST data. I get a undefined index products_id notice on or about lines 372, 492, and 513.

    So while a notifier in SBA could trigger an observer that restores the $_POST data if not present, I think a better solution is to try and display the form, process the results, and restore $_POST (if necessary) all at once, instead of over two cycles through extra_cart_actions. I'm not sure I can accomplish that but that's what I'm going to try.

    Dave
    So, one way I could see this working is actually through script detection on the product page such that if the conditions to show the form exist, pressing the add-to-cart button would trigger your alternate form (along with capturing the existing $_POST and related data) which then upon submission would push all of the data forwards to the shopping cart... But... This relies heavily on the visitor *not* having disabled javascript/jQuery.

    So, looking through the standard ZC code some more for the shopping_cart class, there appear to be notifiers within the add_cart method both relatively early in its execution and also further downstream when exiting the function and then there are multiple notifiers throughout the operation...

    Yes, $_POST data is lost on any new/subsequent page load. To "pass it along" the previously received $_POST data can be captured (session wise or stored on a page that is then/again $_POSTed) and a method (probably complicated) could be used to withdraw $_POST data to prevent some level of operation and then later restore it back in follow-on processing...

    I may ask, why can the data not be collected after the item(s) have been added or in some other "series/sequence" (asking to possibly identify other solutions, not that the one proposed is necessarily an issue)? Such as when displaying the shopping_cart page (store setup has the option to "stay" on the product page upon adding the item to the cart or to go to the shopping_cart) or when moving away from the shopping_cart page to the checkout process... Again, only exploring other alternatives/areas of flexibility... From my side, it's not difficult to add a notifier towards the top of the file (likely would add one at the bottom as well)... It does make me question if the operation in the extra_cart_actions file shouldn't just be put into an observer; however, I would suspect that the same issue of file load sequence would occur there as well if two or more observers were listening to the same notifier and loaded with the same basic file load operation...

    Resummary: goal is to interrupt customer checkout to obtain additional information pertinent to the product at the point the product is added to the cart (not using attributes associated with the product that could be captured at the point of adding the product to the cart and of any type of data input) in such a way that collected data from the point of selecting the product to it actually being added to the cart is not lost as a result of page movement/$_POST data.. I don't yet have information about why it is important to collect the information at the point of clicking add to cart (instead of as presented on screen) or why the data collection couldn't occur at a later point or for that matter how that collected data impacts the product "processing". The information related to that only helps in working together on a path forwards.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  2. #3412
    Join Date
    Jun 2012
    Posts
    307
    Plugin Contributions
    0

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    A notifier at or near the beginning of add_cart method could possibly be used. When my code was written, I may have been wary of using notifiers/observers based on my skills, but now I'm much more comfortable with them. One possible gotcha is that the product id is changed to pick up a different price for three different combinations of attributes, but not all combinations (so I can't use built in price deltas for a single specific attribute). When my code was written, I didn't want to get involved with that issue inside the shopping cart class.

    I didn't want to bring up the form after the item was added to the cart because I thought it might be confusing to the customer. I wanted "add to cart" to bring up the form when the attribute combination required it, get the data, and then bring up the shopping cart page with the item in it. Seems more logical to me.

    Further, I didn't want to bring up an alternate product info page with the form in it. I don't see a reason why that approach wouldn't work though, it just seems more logical to me to bring up the form when the add product to cart button is clicked.

    Thank you for your alternate ideas!

    Dave

  3. #3413
    Join Date
    Jul 2012
    Posts
    16,040
    Plugin Contributions
    17

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by Dave224 View Post
    A notifier at or near the beginning of add_cart method could possibly be used. When my code was written, I may have been wary of using notifiers/observers based on my skills, but now I'm much more comfortable with them. One possible gotcha is that the product id is changed to pick up a different price for three different combinations of attributes, but not all combinations (so I can't use built in price deltas for a single specific attribute). When my code was written, I didn't want to get involved with that issue inside the shopping cart class.

    I didn't want to bring up the form after the item was added to the cart because I thought it might be confusing to the customer. I wanted "add to cart" to bring up the form when the attribute combination required it, get the data, and then bring up the shopping cart page with the item in it. Seems more logical to me.

    Further, I didn't want to bring up an alternate product info page with the form in it. I don't see a reason why that approach wouldn't work though, it just seems more logical to me to bring up the form when the add product to cart button is clicked.

    Thank you for your alternate ideas!

    Dave
    When say that the "products_id" is changed, is it that from product X:abcdef to product Y:abcdef or is more like from product X:abcdef to product X:ghijk? (Recognizing that possibly all "characters" get changed, but trying to keep it simple.) The former represents a completely different product than what was shown to the customer, the second represents a different selection of attributes.

    Note though that part of the intention of the file that used in extra_cart_actions is to validate that the selections made/submitted exist as valid selections effectively in the SBA table... Depending on the changes made in this internal/form process, the "product" submitted may be evaluated as an incorrect product and prevented from being added to the cart... I understand the "price" issue as something to address and it is something I would like to see also expanded upon in the software, but... It may be that the actual add_cart method within the shopping_cart class be interrupted, with a full collection of the data, then when "resuming" go directly/straight to the add_cart method providing it all of the data? I *am* at the moment trying to recall if in processing an SBA tracked item if processing ever really makes it to the remainder of the natural part of the shopping_cart process or if it is basically short-cut by the included file... I don't like that at the moment I can not recall, though I haven't had to consider operational sequences like this... Product got added, or it didn't...

    But since I am starting to understand better, is it something like there are three option names with whatever number of option values for each and one or more particular combinations of any of the selections results in a need to "select" a fourth and/or subsequent option? With that additional "selection" captured on the form?

    To that I was wondering if the sequenced dropdown population and a potential override of the remaining selections would be possible? The thought I'm having here is that with those combinations that require additional information, they are included in a variant as required for that combination and the others that don't meet that requirement do not include those additional selections? But in both cases/combinations the information is collected as part of adding the product to the cart? (Yes I do also see some other potential (inventory) complications of this, but am also trying to consider methods to expand on the software and how those might be used assuming that not just a "one off"...)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #3414
    Join Date
    Jun 2012
    Posts
    307
    Plugin Contributions
    0

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    The product is a membership to our organization. There are four attribute options and values for each as follows:
    • transaction type: new or renewal
    • membership classification: (six membership levels from student to life membership)
    • location: US or non-US
    • Gift?: yes or no

    Each membership level has a different price. If the customer is non-US, a surcharge is applied to three of the six membership classifications to partially cover increased mailing costs for our quarterly magazine. If the surcharge was applied to all six classifications I could use the attribute option price delta feature. Since it's not, I set up two identical products, one with the price for each classification without the surcharge, and another with the surcharge applied to the three classifications. Only one product is shown to the customer, and no prices for each classification are shown where the attributes are selected. Prices are disclosed in the product description. My file in extra_cart_actions detects the membership product being added to the cart, and changes the product to the surcharged membership if the surcharge applies, that is, to one of the three membership classifications that get the surcharge and if the customer is non-US. A message is displayed to the customer if the surcharge is applied.

    If a gift membership (new or renewal, any classification, any location), the same file brings up the form we have been discussing, asking for name, address, email, etc. A discussion of the process and how I got to this point is located in the General Questions forum titled "Custom form doesn't work", dated Jan 5, 2020.

    The membership product(s) are not SBA products, that is, I don't track inventory for each possible combination of attributes, or for a subset of those attributes. I only track inventory at the product_id level for these two products.

    Dave
    Last edited by Dave224; 24 Jul 2021 at 08:10 PM.

  5. #3415
    Join Date
    Nov 2005
    Posts
    500
    Plugin Contributions
    6

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by mc12345678 View Post
    To add the following that is in blue:
    Code:
    // $total = 0.00;
    
    if (!class_exists('products_with_attributes_class_stock')) {
        include_once DIR_FS_CATALOG . DIR_WS_CLASSES . 'class.products_with_attributes_class_stock.php';
    }
    if (empty($_SESSION['pwas_class2'])) {
        $_SESSION['pwas_class2'] = new products_with_attributes_class_stock();
    }
    
    for ($i = 0; $i < sizeof($this->products); $i++) {
        $attribute_customid = '';
        $attribute_names = array();
        $x = strip_tags($this->products[$i]['name']);
        
        // Process attributes
        if (isset($this->products[$i]['attributes']) && sizeof($this->products[$i]['attributes']) > 0) {
            foreach ($this->products[$i]['attributes'] as $attributes) {
                $attribute_names[] = $attributes['option'] . ': ' . $attributes['value'];
            
                $attribute_customid = $_SESSION['pwas_class2']->zen_get_customid($this->products[$i]['id'], array($attributes['value_id']));
            }
            
            if (isset($attribute_names) && is_array($attribute_names)) {
                $attribute_string = implode(', ', $attribute_names);
                $x .= ' ' . $attribute_string;
            }
        }
        
        $y = $this->products[$i]['qty'];
        $z = ($this->products[$i]['final_price'] > 0 ? $this->products[$i]['final_price'] : $this->products[$i]['price']);
        $t = $this->products[$i]['tax'];
        $m = ($this->products[$i]['model'] == '' && $attribute_customid != '' ? $attribute_customid : $this->products[$i]['model']);
        $x = str_replace("<br>", "", $x );
    
        $itemname = "$y x $x";
        $totalexvat = $z * $y;
        $totalcost = (zen_add_tax($z, $t) * $y) + zen_add_tax($this->products[$i]['onetime_charges'], $t);
    
        $thistax = zen_calculate_tax($z, $t);
        $pwt = $z + $thistax;
        // $totaltax += zen_calculate_tax($z, $t) * $this->products[$i]['qty'];
        
        $z = number_format($z, 2, '.', '');
        $totalcost = number_format($totalcost, 2, '.', '');
        $pwt = number_format($pwt, 2, '.', '');
        // $totaltax = number_format($totaltax, 2, '.', '');
        $totalexvat = number_format($totalexvat, 2, '.', '');
        $t = $t . "%";
        // $total += $totalcost;
        $lines[$i] = "$itemname|$m|$t|$pwt|$totalcost";
    }
    Just reporting back that this resolved the issue. No further errors were logged over the weekend.
    Thank you for your assistance.

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

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by Dave224 View Post
    The product is a membership to our organization. There are four attribute options and values for each as follows:
    • transaction type: new or renewal
    • membership classification: (six membership levels from student to life membership)
    • location: US or non-US
    • Gift?: yes or no

    Each membership level has a different price. If the customer is non-US, a surcharge is applied to three of the six membership classifications to partially cover increased mailing costs for our quarterly magazine. If the surcharge was applied to all six classifications I could use the attribute option price delta feature. Since it's not, I set up two identical products, one with the price for each classification without the surcharge, and another with the surcharge applied to the three classifications. Only one product is shown to the customer, and no prices for each classification are shown where the attributes are selected. Prices are disclosed in the product description. My file in extra_cart_actions detects the membership product being added to the cart, and changes the product to the surcharged membership if the surcharge applies, that is, to one of the three membership classifications that get the surcharge and if the customer is non-US. A message is displayed to the customer if the surcharge is applied.

    If a gift membership (new or renewal, any classification, any location), the same file brings up the form we have been discussing, asking for name, address, email, etc. A discussion of the process and how I got to this point is located in the General Questions forum titled "Custom form doesn't work", dated Jan 5, 2020.

    The membership product(s) are not SBA products, that is, I don't track inventory for each possible combination of attributes, or for a subset of those attributes. I only track inventory at the product_id level for these two products.

    Dave
    So, I'm curious, if the product are not SBA tracked, how is it that the SBA extra_cart_actions file interacts with your product and/or causes an issue, it seems like it *should not* do anything on the provided data? (if it does, then perhaps there is a separate issue to address rather than the presence/absence of an additional notifier...

    Are there remnant records about attributes to these products_id values in the SBA table? Such a relationship should be visible in the admin menu for Products with Attributes Stock (SBA) when filtered on the associated products_id.

    Are attributes displayed in an unusual way that might invoke action against the attribute grid logic?

    BTW, providing a link directly to such related discussions tends to be better than a textual description about it, but no harm there. :) The custom form doesn't work thread discussed above is located at: https://www.zen-cart.com/showthread....m-doesn-t-work
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #3417
    Join Date
    Jun 2012
    Posts
    307
    Plugin Contributions
    0

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by mc12345678 View Post
    So, I'm curious, if the product are not SBA tracked, how is it that the SBA extra_cart_actions file interacts with your product and/or causes an issue, it seems like it *should not* do anything on the provided data? (if it does, then perhaps there is a separate issue to address rather than the presence/absence of an additional notifier...

    Are there remnant records about attributes to these products_id values in the SBA table? Such a relationship should be visible in the admin menu for Products with Attributes Stock (SBA) when filtered on the associated products_id.

    Are attributes displayed in an unusual way that might invoke action against the attribute grid logic?

    BTW, providing a link directly to such related discussions tends to be better than a textual description about it, but no harm there. :) The custom form doesn't work thread discussed above is located at: https://www.zen-cart.com/showthread....m-doesn-t-work
    There are no remnant records or unusual way the attributes are displayed. I will try and find what triggers entrance to the SBA extra_cart_actions.
    Dave

  8. #3418
    Join Date
    Jul 2012
    Posts
    16,040
    Plugin Contributions
    17

    Default Re: Stock by Attribute v4.0 for Zen Cart 1.5.1+

    Quote Originally Posted by Dave224 View Post
    There are no remnant records or unusual way the attributes are displayed. I will try and find what triggers entrance to the SBA extra_cart_actions.
    Dave
    Fyi, based on discussion of how your existing code operated, I fully expect(ed) that the SBA extra_cart_actions file would be loaded, I'm trying to figure out what problem that causes. I ask, because even if the "loop" of loading it multiple times wasn't performed, it seems that any such issue would occur on the first load as well as any subsequent load... That shouldn't be an issue in either case and if it is, I'd like to prevent it from being an issue...

    Provided to be sure that investigation is for the right thing not just "why is the file loaded"...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Problems with addon: Dynamic Drop Downs for Stock By Attribute
    By Dunk in forum All Other Contributions/Addons
    Replies: 56
    Last Post: 30 Apr 2014, 07:55 PM
  2. MySQL Problem with Product with Attribute Stock addon
    By rtwingfield in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 20 Sep 2011, 03:35 PM
  3. Hide Zero Quantity Attributes with attribute-stock addon
    By leevil123 in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 11 Feb 2010, 05:06 PM
  4. Replies: 4
    Last Post: 22 Jan 2010, 10:43 PM
  5. Price Products in the grid by 'Stock by Attribute' addon?
    By Salixia in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 27 Oct 2009, 06:03 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