Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
I ran the following sql files
Installation
Full/Upgrade DB Install
Full, makes all script changes to the database (DB) (i.e., adds new SBA table, adds entries into the Admin page, and new entries into the Configuration file).
Upgrade, updates Configuration file and the SBA table as needed. If run again, it will "Clean" table entries and reapply the settings, it will not affect current data in the "products_with_attributes_stock" table.
and Add all Product Attributes
3 Attachment(s)
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
So if for each item I set up the quantity for each color individual it will work. Attachment 18076
If I set just the pick color so it will run SBA Attachment 18077
it only shows pick color in stock and all others are out of stock.
Attachment 18078
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
Quote:
Originally Posted by
cubmanky
So I grabbed the files from
https://github.com/mc12345678/Stock_...butes_Combined and uploaded them to my site. I ran the above script and looking in and the attribute type is set to AV, Still no luck. On test product I have set the qty for each color individual. for test2 product I just made pick a color at 100 units I have in the out of stock that white is out. Still any color i click on will tell me out of stock when i try to click to add it to the cart.
Unfortunately I'm having to look into this as my tests being run in parallel with yours are also not working as expected. I've even gone into the class file and changed the setting that is supposed to determine the attribute stock presence by either first looking at the loaded stock or by looking at the non_stock table and ignore the SBA quantity variant.
I needed to look more at the code with the proposed setup in mind. I couldn't seem to recall if/how other settings came into play such as checking the stock level, reducing stock after purchase, allowance for overselling, etc... I knew that when it was first incorporated and publicized, it worked...
Mind you, when this was first incorporated the primary thought/concern was what was considered the "gift" option. A choice that could be made that would *always* be available when selecting other attributes that were related to the stock of the product... So, what that meant was that there would always be at least 2 attributes (2 option names) with every product except for some specific characteristic type attributes (Files and text boxes)... Well, development was considered for the single attribute product, but it was not completed. Further, I built in a sort of "safety" of overselling product by causing those such options to not support the non-stock characteristics. Could have left just a little more of a note to myself; however, had commented the area about what needed to be done not so much of how it behaved currently.
Anyways, if you go to includes/classes/class.products_with_attributes_class_stock.php and then modify line 1351 from:
to:
Then when the product has a single attribute and the option values/option names are identified as being non-stock, if the option value is not assigned to SBA, it will be possible to select it and add it to the cart. The total available will be identified as the quantity of product as entered in the product information page.
One thing about it though is that I had set aside some comments in that area of things I thought would be valuable to address to ensure that the data pushed would be validated. I'll get to it, but at least you can get through this issue now. There are a few things to consider as I realized when working with a single attribute that if the option value is not captured in SBA then a quantity is displayed, but when I tried to add the product to the cart, the cart notified that the option wasn't available, even though it appeared in the list. I've spent a great deal more on multiple attributes than single attributes, so need to go back and revisit that operation and functionality.
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
First I'm glad its not something on my end as you are having the issue.
I made the change and updated the file on my site
On my test2 product it shows all colors in stock. On white I have it still set as out of stock. I click white color and pick 5 then click add to cart It adds them but tells me 1 available.
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
SO I went in a deleted all variants for test2 then went back and added 100 to pick a color and I get the error Product 23 update failed: IT still shows 100 for each color in the dropdown window
2 Attachment(s)
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
when a product is out of stock, mark_product_out_of_stock it looks at products_quantity to determine this, A splash screen in red shows up and informs the customer, and the products are marked out of stock(Special Ordered) how can i also get it to look at the attribute stock, and show that same splash screen. some of the attributes are instock and some are not but the products quantity has quantity from the ones that do.
this is when no product quantity Attachment 18079
and this is no attribute quantity Attachment 18080
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
i modified a shipping module to detect out of stock to ship another way so having a problem looking at attribute stock to determine
ex.
Code:
// Variable holds information about the products in the order
$this->_products = $_SESSION['cart']->get_products();
$_SESSION['cart']->shopping_stock = 1;
$inStock = 0;
$outStock = 0;
$_SESSION['cart']->in_stock_products = [];
$_SESSION['cart']->out_stock_products = [];
foreach ($this->_products as $product) {
$pid = $product["id"];
$qty = $product["quantity"];
$product_query = "select products_quantity
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$pid . "'";
$product = $db->Execute($product_query);
$quantity = $product->fields["products_quantity"];
if ($quantity < $qty){
$_SESSION['cart']->shopping_stock = 2;
array_push($_SESSION['cart']->out_stock_products,(int)$pid);
$outStock = 1;
}else{
$_SESSION['cart']->shopping_stock = 1;
array_push($_SESSION['cart']->in_stock_products,(int)$pid);
$inStock = 1;
}
}
if($outStock == 1 && $inStock == 1 && count($this->_products) > 0){
$_SESSION['cart']->shopping_stock=3;
}
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
Quote:
Originally Posted by
jimmie
i modified a shipping module to detect out of stock to ship another way so having a problem looking at attribute stock to determine
ex.
Code:
// Variable holds information about the products in the order
$this->_products = $_SESSION['cart']->get_products();
$_SESSION['cart']->shopping_stock = 1;
$inStock = 0;
$outStock = 0;
$_SESSION['cart']->in_stock_products = [];
$_SESSION['cart']->out_stock_products = [];
foreach ($this->_products as $product) {
$pid = $product["id"];
$qty = $product["quantity"];
$product_query = "select products_quantity
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$pid . "'";
$product = $db->Execute($product_query);
$quantity = $product->fields["products_quantity"];
if ($quantity < $qty){
$_SESSION['cart']->shopping_stock = 2;
array_push($_SESSION['cart']->out_stock_products,(int)$pid);
$outStock = 1;
}else{
$_SESSION['cart']->shopping_stock = 1;
array_push($_SESSION['cart']->in_stock_products,(int)$pid);
$inStock = 1;
}
}
if($outStock == 1 && $inStock == 1 && count($this->_products) > 0){
$_SESSION['cart']->shopping_stock=3;
}
There's already a ZC function that determines the stock availability which SBA "hooks" into (reason the includes/functions/functions_lookups.php file requires modification in ZC 1.5.5 and below. In ZC 1.5.6 there is expected to be code that will be in place and won't require modification of that file). There is also a function in the includes/classes file added for SBA that also supports, but I would recommend using the modified SBA function if for any reason SBA is removed.
The modification made to the function is to obtain/use the attributes of the product and from there determine if it is tracked by SBA and what the associated stock is. That function is:
Code:
zen_get_products_stock($products_id, $attributes = null, $dupTest = null)
You only need to pass the first two parameters. I'm not where I can easily identify (and at the moment don't remember) the makeup of the attributes portion off of a cart's entry to say what it takes to pull the attributes off of the product information. I'd have to get back to you if you don't know/find it.
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
Found it:
$_SESSION['cart']->contents[$products_id]['attributes']
or as used above:
$product['attributes']
So something like:
Code:
$attributes = null;
if (isset($product['attributes']) {
$attributes = $product['attributes'];
}
$quantity = zen_get_products_stock($products_id, $attributes);
Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9
Quote:
Originally Posted by
mc12345678
Found it:
$_SESSION['cart']->contents[$products_id]['attributes']
or as used above:
$product['attributes']
So something like:
Code:
$attributes = null;
if (isset($product['attributes'])) {
$attributes = $product['attributes'];
}
$quantity = zen_get_products_stock($products_id, $attributes);
Darnit, forgot a right parenthesis on the if statement line. Just happened to be looking over the code and see the imbalance.
Code:
$attributes = null;
if (isset($product['attributes'])) {
$attributes = $product['attributes'];
}
$quantity = zen_get_products_stock($products_id, $attributes);