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,544

Results 2,681 to 2,700 of 3,609
7 Feb 2017, 1:22 PM
#2681
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

ttfan:

Here is the code you requested:

function updateNotifyOrderProcessingStockDecrementBegin(&$callingClass, $notifier, $paramsArray, &$stock_values, &$attribute_stock_left = 0){
global $db; //, $pwas_class;

$this->_stock_values = $stock_values;

if ($this->_orderIsSBA && $stock_values->RecordCount() > 0) {
  // kuroi: Begin Stock by Attributes additions
  // added to update quantities of products with attributes
  // $stock_attributes_search = array();
  $attribute_stock_left = STOCK_REORDER_LEVEL + 1;  // kuroi: prevent false low stock triggers
  $this->_attribute_stock_left = $attribute_stock_left;

  // mc12345678 If the has attibutes then perform the following work.
  if(isset($this->_productI['attributes']) and sizeof($this->_productI['attributes']) > 0){
    // Need to identify which records in the PWAS table need to be updated to remove stock from
      // them.  Ie. provide a list of attributes and get a list of stock_ids from pwas.
      // Then process that list of stock_ids to decrement based on their impact on stock.  This
      // all should be a consistent application.
    // mc12345678 Identify a list of attributes associated with the product
    $stock_attributes_search = $_SESSION['pwas_class2']->zen_get_sba_stock_attribute(zen_get_prid($this->_productI['id']), $this->_productI['attributes'], 'order');
    $stock_attributes_search_new = $_SESSION['pwas_class2']->zen_get_sba_attribute_info($this->_productI['id'], $this->_productI['attributes'], 'order', 'ids');
      if (isset($stock_attributes_search_new) && $stock_attributes_search_new === false) {
          
      } elseif (isset($stock_attributes_search_new) && is_array($stock_attributes_search_new) && count($stock_attributes_search_new) == 0) {
          
      } elseif (isset($stock_attributes_search_new) && $stock_attributes_search_new && count($stock_attributes_search_new) > 0) {
          foreach ($stock_attributes_search_new as $stock_id) {
              // @todo: address in PWAS table whether particular variant should be altered with stock quantities.
              $get_quantity_query = 'SELECT quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id=' . zen_get_prid($this->_productI['id']) . ' and stock_id=' . (int)$stock_id;
              $attribute_stock_available = $db->Execute($get_quantity_query, false, false, 0, true);
              if (true) { // Goal here is to identify if the particular attribute/stock item should be affected by a stock change.  If it is not, then this should be false or not performed.
                  $attribute_stock_left_test = $attribute_stock_available->fields['quantity'] - $this->_productI['qty'];
                  $attribute_update_query = 'UPDATE ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' SET quantity="'.$attribute_stock_left_test.'" where products_id=' . zen_get_prid($this->_productI['id']) . ' and stock_id=' . (int)$stock_id;
                  $db->Execute($attribute_update_query, false, false, 0, true);
                  if ($attribute_stock_left_test < $attribute_stock_left) {
                      $this->_attribute_stock_left = min($attribute_stock_left_test, $this->_attribute_stock_left);
                      $attribute_stock_left = $this->_attribute_stock_left;
                  }
              }
          }
      }

/* $get_quantity_query = 'select quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id="' . zen_get_prid($this->_productI['id']) . '" and stock_attributes="' . $stock_attributes_search . '"';
$get_quantity = $_SESSION['pwas_class2']->zen_get_sba_attribute_info($this->_productI['id'], $this->_productI['attributes'], 'products', 'stock');

    // mc12345678 Identify the stock available from SBA.
    $attribute_stock_available = $db->Execute($get_quantity_query, false, false, 0, true);  
    // mc12345678 Identify the stock remaining for the overall stock by removing the number of the current product from the number available for the attributes_id. 
    $attribute_stock_left = *//*$attribute_stock_available->fields['quantity']*//* $get_quantity - $this->_productI['qty'];

    // mc12345678 Update the SBA table to reflect the stock remaining based on the above.
    $attribute_update_query = 'update ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' set quantity='.$attribute_stock_left.' where products_id="' . zen_get_prid($this->_productI['id']) . '" and stock_attributes="' . $stock_attributes_search . '"';
    $db->Execute($attribute_update_query, false, false, 0, true);  
    //$this->_attribute_stock_left = $attribute_stock_left;*/
  }
  $attribute_stock_left = $this->_attribute_stock_left;
}

}

/*

  • Function that is activated when NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END is encountered as a notifier.
    /
    // Line 776
    /
    *
    • @param $callingClass
    • @param $notifier
    • @param $paramsArray
      */
> 
> Very few plugins are installed at this stage, as we're still trying to get things working. The plugins are: CK editor & image handler, as well as stock by attributes of course.
> 
> I can see no commonalities between orders that pass/fail, except that the ones fails always have the atrributes discussed above. Items with no attributes work properly.

That appears to be the latest code which supports the rewritten stock decrement functionality for all three variant styles of:
1) One option name for a product with one option value per variant entry.
2) Multiple option names, each option name's value listed one time such that no two option values are combined in one entry.
3) Multiple option names with combinations of option values from different option names all entered in a single variant.

So, that said, I tried to look through the code to find something that might cause a spurious result and found two queries "buried" in the process that do not clear the query cache.  Is that the cause? I don't know because haven't been able to repeat the issue and no further information has yet been provided/analyzed to be able to verify that the problem has been resolved.  In fact, I'm not even sure that by making the changes (or not) if there is a way to validate that the problem has been solved, but anyways...

The suggested fix is available from: <https://github.com/mc12345678/Stock_By_Attributes_Combined/commit/18fa6fb75b20048f41b79fa7973ab46ef5a4aa0e>
and affects only one file in two places.  The file is: includes/classes/class.products_with_attributes_class_stock.php

The lines affected are 416 and 1506 with the same fix applied to both of effectively adding to the query: ```
, false, false, 0, true
``` as can be seen at the above link.

Feedback would be appreciated.
7 Feb 2017, 10:09 PM
#2682
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

Thank you so much!

I have implemented the 2 changes. I've tested it myself, and it seems to work fine, so now I'll wait for the orders to come in, so that I can check it's all working. I'll report back here.

7 Feb 2017, 10:20 PM
#2683
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

ttfan:

Thank you so much!

I have implemented the 2 changes. I've tested it myself, and it seems to work fine, so now I'll wait for the orders to come in, so that I can check it's all working. I'll report back here.
Would be interesting to see if it happens again, though by not knowing any information about how it occurred the first time(s) there's really little to be able to tell that the issue is resolved...

That said, the condition I could possibly see under the previous code and maybe causing the reported result is if a product was in the cart that was not tracked by SBA and after that a product was present that was tracked by SBA but caching recordered it "not" being SBA. The other is that data was returned for a different product and either no decrement occurred, or a different product's quantity was reduced.

Haven't yet been able to reproduce either situation but it is something conceptually possible if caching were the cause of the issue(s).

Look forward to results!

8 Feb 2017, 2:16 PM
#2684
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

Unfortunately it did not work. The very next order failed to update the quantity of the attribute, while the total quantity was reduced properly.

8 Feb 2017, 2:44 PM
#2685
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

I just had one thought though, it may not be related. When I test the module, I always use the 'bank deposit' payment option, as this goes straight through, and I don't have to make a dummy payment via paypal. However at least some of the orders that failed (possible all, I did not take note), were using payment via paypal. A Paypal payment forces the user to go to the paypal site to make the payment, then return to the shop to update the order and empty the cart. So perhaps this is where the attributes fails to update?

8 Feb 2017, 2:48 PM
#2686
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

ttfan:

Unfortunately it did not work. The very next order failed to update the quantity of the attribute, while the total quantity was reduced properly.

Okay, so can you tell me about the order, the product and the particular setup?
Ie. How many products were in the order?
When thinking about the product from the perspective of SBA, which had attributes, what attribute(s), what type of attribute(s)?
In the pwas table under catalog, if you search for the products_id of the product in question, what are all of the variants (rows) listed for the product?
What was the quantity of each product ordered? How many were present before the order?
What are the settings for the product in relation to mixed quantity? Is there a maximum applied for the product?

Need details of how I can reproduce the issue so that I can fix the issue.

I don't need to know things like the products_description or what it does/is, just "data", sort orders, setup. If you can provide that, then perhaps I can repeat the situation.

BTW, any error logs in your logs directory possibly as a result of the purchase/sale?

8 Feb 2017, 3:08 PM
#2687
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

ttfan:

I just had one thought though, it may not be related. When I test the module, I always use the 'bank deposit' payment option, as this goes straight through, and I don't have to make a dummy payment via paypal. However at least some of the orders that failed (possible all, I did not take note), were using payment via paypal. A Paypal payment forces the user to go to the paypal site to make the payment, then return to the shop to update the order and empty the cart. So perhaps this is where the attributes fails to update?
What method of PayPal is enabled?

Though that doesn't make sense either, because the only place that stock is reduced is through the includes/classes/order.php file which (should have) has the notifiers present to trigger the SBA decrement and if the total quantity went down, that should mean that the applicable SBA code would execute. But that said, I'll have to take a look at how session data is managed along that path, because currently the decrement code is session related and if in the process that is removed, then two things: 1) an error should be generated because the code can't be found, and 2) the stock wouldn't decrease. But, I thought that in previous review of what happens with the session, is that only PayPal and possibly cart related session data was modified. :/

8 Feb 2017, 10:29 PM
#2688
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

Here is one warning from the log file, the only one that seems related:
#1 trim() called at [/includes/functions/general.php:441]
#2 zen_not_null() called at [includes/classes/upload.php:61]
#3 upload->parse() called at [attributes_controller.php:310]

[08-Feb-2017 17:03:46 Australia/Sydney] PHP Warning: trim() expects parameter 1 to be string, object given in /includes/functions/general.php on line 441

I'm using the Paypal Website Payment Standard only.

8 Feb 2017, 11:36 PM
#2689
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

ttfan:

Here is one warning from the log file, the only one that seems related:
#1 trim() called at [/includes/functions/general.php:441]
#2 zen_not_null() called at [includes/classes/upload.php:61]
#3 upload->parse() called at [attributes_controller.php:310]

[08-Feb-2017 17:03:46 Australia/Sydney] PHP Warning: trim() expects parameter 1 to be string, object given in /includes/functions/general.php on line 441

I'm using the Paypal Website Payment Standard only.

Okay, so with regards to using PayPal standard do you consistently receive the email from the store and PayPal with the full order being stored in the database, or do you find that you sometimes have to go back and request the purchaser to provide more information or any related issue(s)?

9 Feb 2017, 1:18 AM
#2690
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

mc12345678:

Okay, so with regards to using PayPal standard do you consistently receive the email from the store and PayPal with the full order being stored in the database, or do you find that you sometimes have to go back and request the purchaser to provide more information or any related issue(s)?
Yes the full information is in the Paypal Email, including the attributes.
After looking at the orders over the last 24h, I can confirm that only the orders that were paid via paypal fail to update the attributes, the ones paid via other methods (none of which use an external website), all work properly.

9 Feb 2017, 1:37 AM
#2691
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

ttfan:

Yes the full information is in the Paypal Email, including the attributes.
After looking at the orders over the last 24h, I can confirm that only the orders that were paid via paypal fail to update the attributes, the ones paid via other methods (none of which use an external website), all work properly.

What's the business reason for not using PayPal Express?

You say you get the PayPal email, but your store is supposed to send out an email as well, is it not? Do you receive that email when someone pays using PayPal Standard?

9 Feb 2017, 2:12 AM
#2692
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

mc12345678:

What's the business reason for not using PayPal Express?
No business reason, just haven't got around to it yet. I certainly will do it as soon as this issue is sorted.

mc12345678:

You say you get the PayPal email, but your store is supposed to send out an email as well, is it not? Do you receive that email when someone pays using PayPal Standard?
Yes I get an Email from both the store and paypal, both contain all the details and attributes.

9 Feb 2017, 3:43 AM
#2693
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

ttfan:

No business reason, just haven't got around to it yet. I certainly will do it as soon as this issue is sorted.

Yes I get an Email from both the store and paypal, both contain all the details and attributes.
Right now I'm thinking that the problem would be resolved by using PayPal express, so perhaps at an impass...

It certainly gives me reason to re-consider the use of the session to store the functions that are used again and again, but generally speaking PayPal standard is discouraged in favor of PayPal express for a number of reasons.

In order for me to rewrite the code to not use the session style, I'd have to do a good bit of testing because the leap from before to now was easily made but going backwards in that regards and not having everything offered up as an extra function (ie. Compartmentalizing the code so that is possibly less of a system burden means a decent amount of verification.) it's also not something that is going to be revised overnight.

Again, considering that the only identified (as of the last 24 hours) possible consistency has been the use of PayPal standard, my suggestion would be (whether there had been a problem or not) to use PayPal express if PayPal is going to be used for a general store.

9 Feb 2017, 3:52 AM
#2694
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

Does Paypal Express still allow you to pay with a credit card directly (using the paypal gateway, not a paypal account), or only payment with a Paypal account? This is important to us, as we prefer not to use another site just for processing credit cards.

I'll certainly install Paypal Express and test it, hopefully it will resolve this issue.

Just in case I did not mention it earlier, I really appreciate the time and effort you've spent helping me, a big THANK YOU from me! :blush:

9 Feb 2017, 4:11 AM
#2695
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

ttfan:

Does Paypal Express still allow you to pay with a credit card directly (using the paypal gateway, not a paypal account), or only payment with a Paypal account? This is important to us, as we prefer not to use another site just for processing credit cards.

I'll certainly install Paypal Express and test it, hopefully it will resolve this issue.

Just in case I did not mention it earlier, I really appreciate the time and effort you've spent helping me, a big THANK YOU from me! :blush:

So I recently saw someone say that when using PayPal express with in context payment that possibly the customer was forced to have, get, or use a PayPal account, because of a setting in the code that supposedly (per a PayPal tech) is no longer required to be set/written the way it is. That said, in my testing with PayPal express, I have been able to select/enter a credit card without being required to have, get, or use a PayPal account. Of course they want you to create/have/use one, but doesn't mean they necessarily limit operation to its use. Oh, and my testing included full use of PayPal in context.

As for the assistance, hopefully you understand also that I sort of have a vested interest in it working as written. Any and all that have chosen to use it are likely questioning it's operation at the moment and why questions have been asked to be answered. The less people to which the issue applies, the more at ease they are to be. Mind you I have pushed some minor changes to github, just in case there might have been something odd with the queries (ensured a space to each side of an equals when dealing with a SQL script.), I hadn't pushed the execute query changes from earlier yet to the master because they didn't fix the current issue, therefore I didn't see a necessarily good reason to clear the cache for those two items. At least not yet. :)

10 Feb 2017, 6:26 AM
#2696
ttfan avatar

ttfan

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
231
Plugin Contributions:
0

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

I'm happy to report that it appears to be working fine now, when I replaced the old Paypal module with the Paypal Express one!:smile:

10 Feb 2017, 10:12 AM
#2697
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

ttfan:

I'm happy to report that it appears to be working fine now, when I replaced the old Paypal module with the Paypal Express one!:smile:

Glad to hear/see! And thank you for reporting your finding(s) on both sides of issue found and a solution that works!

25 Mar 2017, 7:41 PM
#2698
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

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

ttfan:

Does Paypal Express still allow you to pay with a credit card directly (using the paypal gateway, not a paypal account), or only payment with a Paypal account? This is important to us, as we prefer not to use another site just for processing credit cards.

I'll certainly install Paypal Express and test it, hopefully it will resolve this issue.

Just in case I did not mention it earlier, I really appreciate the time and effort you've spent helping me, a big THANK YOU from me! :blush:

Depends on which Paypal you are using.

There is Paypal paments (what you traditionally think of as Paypal) and then there is Paypal Merchant Processing.

Paypal Merchant Processing (ie: PayPal Payments Pro) will stay on your site.

Paypal Payments (like Express Checkout, or the very old PayPal Standard) will take you to Paypal. Once on Paypal you can either use your Paypal account or just enter a credit card.

29 Mar 2017, 8:47 PM
#2699
jodean avatar

jodean

Totally Zenned

Join Date:
May 2011
Location:
Tennessee
Posts:
511
Plugin Contributions:
0

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

I installed the 1.5.1 version on my 1.5.1 Zen Cart. I can create quantities for attributes in admin but when viewing the product it states that it is out of stock when it is not out of stock. I have synced the quantities and they are correct.

Any ideas?

29 Mar 2017, 8:56 PM
#2700
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

jodean:

I installed the 1.5.1 version on my 1.5.1 Zen Cart. I can create quantities for attributes in admin but when viewing the product it states that it is out of stock when it is not out of stock. I have synced the quantities and they are correct.

Any ideas?

Sure that all parts of the software were installed, and I assume (right or wrong) that the github version was used? Regarding the install, were files "blindly" replaced, or where the file existed were the changes made for SBA incorporated into the existing file(s)?

After/along with that: please identify the characteristics involved: ie. one attribute (option name) or more than one? Are the default settings for dynamic dropdowns being used? Out-of-stock, showing where? Each attribute? Full product? If the product is showing out of stock I'd be surprised as nothing really is modified that would cause that.

Might have more questions, but answers to those should at least guide to something.