Zen Cart Logo
Forums / All Other Contributions/Addons / Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Views: 658,360

Results 2,341 to 2,360 of 3,609
17 Dec 2015, 23:02
#2341
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Badarac,

Thank. You for this valuable feedback.

The logged error is because the routne is run where no attrbutes are present to fullfill the internal code. In an effort to remove SBA from modfying so many core files (unfortunately the includes/classes/orders.php file still needs a small modifcation to take advantage of data for future use) it would appear that the low-stock check (and possibly other such sections) needs to verify that the involved product is in fact tracked by SBA. There is a similar check elsewhere in the observer class. Will take a look to see if can suggest applicable code.

18 Dec 2015, 13:21
#2342
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

@badarac, et al.

In includes/classes/observers/class.product_with_attributes_stock.php

Find the function:

Replace with the following:

  /*
   * Function that is activated when NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END is encountered as a notifier.
   */
  // Line 776
  function updateNotifyOrderProcessingStockDecrementEnd(&$callingClass, $notifier, $paramsArray) {

    if (zen_product_is_sba($this->_productI['id'])) { // Only take SBA action on SBA tracked product mc12345678 12-18-2015
      //Need to modify the email that is going out regarding low-stock.
      //paramsArray is $i at time of development.
      if ($callingClass->email_low_stock == '' && $callingClass->doStockDecrement && $this->_stock_values->RecordCount() > 0 && $this->_attribute_stock_left <= STOCK_REORDER_LEVEL) {
        // kuroi: trigger and details for attribute low stock email
        $callingClass->email_low_stock .=  'ID# ' . zen_get_prid($this->_productI['id']) . ', model# ' . $this->_productI['model'] . ', customid ' . $this->_productI['customid'] . ', name ' . $this->_productI['name'] . ', ';
foreach($this->_productI['attributes'] as $attributes){
          $callingClass->email_low_stock .= $attributes['option'] . ': ' . $attributes['value'] . ', ';
        }
        $callingClass->email_low_stock .= 'Stock: ' . $this->_attribute_stock_left . "\n\n";
// kuroi: End Stock by Attribute additions
      }
    }
  }
18 Dec 2015, 13:35
#2343
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Thanks MC. I'll apply that right now to the test site and verify that it works. Get back to you shortly.
RichB

18 Dec 2015, 14:21
#2344
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

MC,
That fixed the problem of the low stock messages but I've discovered other problems. I tested a product that has two attributes. One is a color selection which is identified in SBA. The other is a text attribute to add personalization. There's no information along with the mod on the dynamic dropdown options so I've experimented with them If I select enable dynamic dropdowns the text field becomes a dropdown. Different combinations of the options don't provide an actual text input field. If I turn the dynamic dropdowns off it displays as a text input field but I get an error where rb is the text I entered into the field.

PHP Fatal error:  1054:Unknown column 'rb' in 'where clause' :: select products_attributes_id 
        from zen_products_attributes 
        	where options_values_id in (rb,188) 
      		and products_id= 1165 
  				order by products_attributes_id ==> (as called by) includes/functions/extra_functions/products_with_attributes.php on line 236 <== in includes/classes/db/mysql/query_factory.php on line 155

If you need me to go through all the different combinations on the dynamic dropdown menu in admin I'll do that for you.

18 Dec 2015, 15:17
#2345
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

badarac:

MC,
That fixed the problem of the low stock messages but I've discovered other problems. I tested a product that has two attributes. One is a color selection which is identified in SBA. The other is a text attribute to add personalization. There's no information along with the mod on the dynamic dropdown options so I've experimented with them If I select enable dynamic dropdowns the text field becomes a dropdown. Different combinations of the options don't provide an actual text input field. If I turn the dynamic dropdowns off it displays as a text input field but I get an error where rb is the text I entered into the field.

PHP Fatal error: 1054:Unknown column 'rb' in 'where clause' :: select products_attributes_id
from zen_products_attributes
where options_values_id in (rb,188)
and products_id= 1165
order by products_attributes_id ==> (as called by) includes/functions/extra_functions/products_with_attributes.php on line 236 <== in includes/classes/db/mysql/query_factory.php on line 155

> If you need me to go through all the different combinations on the dynamic dropdown menu in admin I'll do that for you.

Is the text option something that is stock dependent? Ie. if someone enters text, does that affect the stock of tracked product? I ask more to try to quickly work around a somewhat known issue that dynamic dropdowns at this point does not support much more than dropdown related attributes, but is being worked on.  

The lines to be affected are 216 and 222 in includes/functions/extra_functions/products_with_attributes.php

Mainly I perceive that the two if statements would need to be modified to account for text boxes.  To identify exactly what is expected, need to also look back at the  products_with_attributes_stock table population for text fields (appears that it could be possible for an attribute to be passed to this function that is not tracked by SBA which according to the above question of if the text box affects stock it wouldn't matter as the function attempts to compare all attributes as a unit rather than one at a time (this type of comparison is done elsewhere in the code and needs to carry over to here as well) and there is no code yet provided that allows combining 2 or more attributes as a unit and at the same time 1 or more other attributes as unit requiring 3 or more attributes to identify the product by that combination.  At the moment it is either multiple single attributes, or all attributes as a group.  Unfortunately text boxes have not been factored in yet, but is a basic (relatively essential) attribute type to be incorporated.

The additional testing would be beneficial to the continued development, especially since there is an interest to seeing the multiple attributes options fully supported.
18 Dec 2015, 15:29
#2346
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

mc12345678:

Is the text option something that is stock dependent? Ie. if someone enters text, does that affect the stock of tracked product? I ask more to try to quickly work around a somewhat known issue that dynamic dropdowns at this point does not support much more than dropdown related attributes, but is being worked on.

The lines to be affected are 216 and 222 in includes/functions/extra_functions/products_with_attributes.php

Mainly I perceive that the two if statements would need to be modified to account for text boxes. To identify exactly what is expected, need to also look back at the products_with_attributes_stock table population for text fields (appears that it could be possible for an attribute to be passed to this function that is not tracked by SBA which according to the above question of if the text box affects stock it wouldn't matter as the function attempts to compare all attributes as a unit rather than one at a time (this type of comparison is done elsewhere in the code and needs to carry over to here as well) and there is no code yet provided that allows combining 2 or more attributes as a unit and at the same time 1 or more other attributes as unit requiring 3 or more attributes to identify the product by that combination. At the moment it is either multiple single attributes, or all attributes as a group. Unfortunately text boxes have not been factored in yet, but is a basic (relatively essential) attribute type to be incorporated.

The additional testing would be beneficial to the continued development, especially since there is an interest to seeing the multiple attributes options fully supported.
The text attribute does not affect the stock. I can't image how a text attribute ever would though. I would guess that the answer is to modify it to exclude text attributes. If you want me to test anything I'll happily do that.

18 Dec 2015, 17:02
#2347
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I got rid of the error by adding this

        foreach ($attribute_list as $optid => $optvalid) {

          if (true) {
			  // mc12345678 Here is one place where verification can be performed as to whether a particular attribute should be added.  This is probably the best place to do the review because all aspects of the attribute are available.
		   if (is_numeric ($optvalid)) {
           $attributes[] = $optvalid;
		   }
          }
        }

If the text attribute is added to the SBA table with a quantity the order now completes with the text attribute added to the cart. When the order is submitted I receive a low stock email with a stock value of -1. All attributes defined in the sba table have a positive stock value.

If the text attribute is removed from the SBA table it won't allow checkout because an attribute is out of stock.

I guess there must be a better way.

22 Dec 2015, 14:00
#2348
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

@badarac,
How about now? Didn't really work on dynamic dropdowns, but software needs to add the benefit of tracking stock by attribute even when say dynamic dropdowns are disabled.

Worked towards: recognzing text entry fields and upload fields for when submitting product to the cart, also recognition that the selections made do not exist. Ruling for existence at this point is: either all attributes submitted are grouped as a single variant (a shoe that is red, size 10, and has bright yellow laces) and if not grouped that way then are each individually tracked but represent only an attribute not another store product (a gift bag that allows possibly picking two items perhaps a perfume and a specific toy).

I'm thinking though that at the moment that if there are two or more each of either a textbox or upload file option names that the product will fail at adding to the cart though I have a way in mind to address that. Plan is to identify the occurrence of each of those and if one or more is identified then to OR the option_id and option_value_id for each such pair into the query that retrieves the attribute_id(s) for the combination of attributes.

The result of that being something like get the attribute_id(s) where the option_value_id is in the imploded option_value_ids for other attributes that are not specially controlled or foreach specially controlled option_name have the option_id and option_value_id values of that option_name. Also, for expandability to throw in a few well placed notifiers. Just some thoughts...

Sorry to those that have recently downloaded the latest to discover this issue.

24 Dec 2015, 05:17
#2349
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Updated all three locations with code that should now recognize textbox entries (at least when ordering) as well as upload files. Also refined the application of some of the observer actions to only apply when the applicable item should be processed by that observer action generally speaking. In the process identified some typoes and omissions that weren't noticed by others previously.

Looking to verify/update to support ZC 1.5.5 soon.

@badarac, et al. Please confirm issues recently identified are resolved and no new issues generated... There are some known items addressed in github in particular related to read only and other non-dropdown attributes when using dynamic dropdowns as well as some "deeper" things to address such as copying SBA attributes when copying a product, etc...

24 Dec 2015, 12:18
#2350
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

mc12345678:

@badarac, et al. Please confirm issues recently identified are resolved and no new issues generated... There are some known items addressed in github in particular related to read only and other non-dropdown attributes when using dynamic dropdowns as well as some "deeper" things to address such as copying SBA attributes when copying a product, etc...
MC,
I'll download it and install on the test site today. I'll let you know shortly.
RichB

24 Dec 2015, 12:25
#2351
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

MC,
I'm assuming that I'm downloading from the master branch and replacing the files that were updated 12 hours ago correct?

24 Dec 2015, 13:44
#2352
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

MC,
I installed the five updated files and did a test. For products with only physical attributes the entire process worked fine. For products which had a combination of a text attribute and a physical, the product added to the cart but in the cart it showed as out of stock. The product I'm working with has one physical attribute (color) with two choices and one text. The physical attributes are defined in the SBA table with quantities of 15 and 16. The main product has a quantity of 31. It doesn't make any difference whether the text attribute is defined in the SBA table. I added it to test with a quantity of 9999999 and it still displayed as out of stock in the cart. There is no indication what the quantities are for the attributes on the product page and in the cart. When I turn on the dynamic drop down it displays a pop up message on the product page saying all selections of attributes below this one are out of stock. There is no indication which attribute they are referring to. When I click ok and look at the attribute pull downs it shows the display only and text attributes as out of stock. There's no configuration instructions for the mod and it's new features so I may have something set incorrectly. If you need me to provide you with anything or do any further changes or tests let me know.

24 Dec 2015, 16:58
#2353
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Not sure I fully understand the testing conditions of above, but I did go back to see if I affected the option to build a product with attributes where each attribute is added individually. It looks like overall, I changed something to prevent managing product that way. Also wasn't a condition I tested because I didn't think I impacted it.

I had been testing with a product of similar design one selectable attribute and one fill in the field attribute. The setup was though for each combination to be a variant:
Variant1: color X/text 15
Variant2: color Y/text 25

When I tried the individual variant perspective:
Variant1: Color X 15
Variant2: Color Y 25
Variant3: Text 99999

Didn't matter whether Variant3 was text or any other attribute type, I did something that prevented adding a combination like above to the cart... Will be addressing that "corner" of the code now that it has been identified.

Then I should be able to get back to the Dynamic Dropdown part so that it is more robust than originally designed. As for the "instructions" well, the idea is to actually match the functionality more with the existing description... All versions of SBA that I've used in the last 4 years have claimed to handle multiple attributes using the shoe or t-shirt example.... Potteryhouse/jeking were the first that I saw to actually come close to handling both multi- and single attributes in one, though they also mostly went with the version 2 above on variants... I don't use that version, but doesn't mean it shouldn't work.

What I'm getting at is that it really is still in a testing phase to know/understand what limitations and issues exist with it... The goal is pretty much open bore, but there are bound to be a few issues here or there...

The only attribute combination limitation that I know has not been overcome (yet) is such that a product has 3 or more attributes and the variants are built as combinations of 2 or more attributes paired with 1 or more attributes

V1: op_val1-1/op_val2-1
V2: op_val1-1/op_val2-2
V3: op_val1-2/op_val2-1
V4: op_val1-2/op_val2-2
V5: op_val3-1
V6: op_val3-2

Where each of the above variants (V1-V6) has a stock quantity associated...

As to quantities being displayed, well DD when coded to handle other types of attributes will offer some of that, as well as supporting other plugins such as dynamic updating, etc...

The above "abnormal" variants are something to consider in the future, but need to get through the other issues first. :)

24 Dec 2015, 17:02
#2354
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Anything I can do to help just let me know. I'll PM you a link to the product I was referring to so you can see how it's working on a live site. Since it's a client's site I don't want to post it here. PM coming.

24 Dec 2015, 17:22
#2355
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Huh, go figure:

At line 489 of includes/functions/extra_functions/products_with_attributes.php

Change:

             if (!$stockResult->EOF) {
                $notAccounted = true;
              }

To:

             if ($stockResult->EOF) {
                $notAccounted = true;
              }

(Removing the "not" (!) from the if statement.)

24 Dec 2015, 17:58
#2356
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

mc12345678:

Huh, go figure:

At line 489 of includes/functions/extra_functions/products_with_attributes.php

Change:

         if (!$stockResult->EOF) {
            $notAccounted = true;
          }
> To:
> ```
             if ($stockResult->EOF) {
                $notAccounted = true;
              }

(Removing the "not" (!) from the if statement.)

I made the change and it still shows out of stock in the cart. I turned off the dynamic drop downs. With the dynamic drop down active it shows the read only and text attributes out of stock

24 Dec 2015, 18:28
#2357
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

So couple of comments (fyi, was provided links to some "trouble" products), it is expected that attributes be setup as described in the FAQ where if an option name has a "please select" type option that it be marked as display only in the attribute controller. (If that has been done then I need to update the code to not populate the variants with such options or to not consider in DD.)

Secondly, in light of the current functionality and action necessary to fully incoporate the remaining capablity I'm thinking of adding a trigger in the tpl_modules_attributes.php file to disable DD for product that include attribute types not yet supported by DD, to be updated as the functionality is added. Therefore, overall SBA would work on a store, but some functionality would not be available for all product (namely at the moment customer facing added infomation (such as quantity available of a combination or other added "features"), but would still be able to interact with the shopping cart where applicable information could still be presented.

24 Dec 2015, 18:47
#2358
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

badarac:

I made the change and it still shows out of stock in the cart. I turned off the dynamic drop downs. With the dynamic drop down active it shows the read only and text attributes out of stock

Yeah, wanted to be sure could get the product added to the cart first (fix provided above) then would need to apply the same fix to the includes/functions/functions_lookup.php file (ZC 1.5.3/1.5.4 line 252, ZC 1.5.1 line 255).

Afterall, if going to "make a mistake" then be consistent and make it everywhere right? :)

I'll update the three repositories and then will add the "disabling" feature soon.. Want to do it so that it will be easy to upgrade in the future. Need to identify the appropriate combination of DB, constant and code information so that it can be applied "easily" and consistently.. Not an ideal situation, but would support more of the production use of the code in its beta state.

Ie. was asked a while back to submit the code as a formal plugin to ZC; however, I felt that all/most of these multiple attribute issues needed to be addressed before formally submitting it. This may provide a stop-gap to that issue and make it possible for more formal use...

badarac, thank you for identifying this issue and for the additional testing in absence of clear direction. Before submitting will have to catch everything up to the current condition/status...
Also, looks like ZC 1.5.5 is nearing release, so need to grab any changes/issues and incorporate for its use... All the more reason to transition to using http://www.github.com/mc12345678/Stock_By_Attributes_Combined where installation and version maintenance has become a bit simpler... :)

24 Dec 2015, 19:11
#2359
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Github updated to allow adding product to 1) check that the attributes of product being added to the cart are in fact defined by variants present (all listed as a combination in one variant or each attribute listed individually), 2) to manage at least the special cases of fill in the text and upload a file (welcome input if other attribute types are an issue), and 3) for product presenting a text field or upload file when Dynamic Dropdowns is disabled.

Next up, to support the code disabling dynamic dropdowns for the product that do not display accurately for the attributes applied to the product to allow maximum use of the features while development continues to make the dynamic dropdown part more robust.

25 Dec 2015, 09:06
#2360
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Alright, added a function that when fed the appropriate attribute data can determine if dynamic dropdowns should be able to be shown for a product even if DD is turned on for all product. The function can be modified/customised to turn off DD under other certain conditions; however, that seemed to be the basic reason.

As dynamic dropdowns are made more "flexible", the limitations in that function will be reduced, but until then...

Have fun... :)