Forums / All Other Contributions/Addons / StockByAttributes with my stock id - zc1.5

StockByAttributes with my stock id - zc1.5

Views: 1,178

Results 1 to 10 of 10
29 May 2012, 8:29 PM
#1
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

StockByAttributes with my stock id - zc1.5

hi,
installed this mod on 1.5 and it seems to work 90%

if you set up a product with attributes which have stock values like this and add a read only attribute to force a selection of attibute like this

http://catchagrip.co.uk/sba-id/index.php?main_page=product_info&cPath=1&products_id=1

everything works so far as i can see

if you set up a product with attributes which have no stock value like this and add a read only attribute to either force selection of an attribute or at least the no selection required option is selected

http://catchagrip.co.uk/sba-id/index.php?main_page=product_info&cPath=1&products_id=2

everything works so far as i can see

if you set up a product with no attributes

http://catchagrip.co.uk/sba-id/index.php?main_page=product_info&cPath=1&products_id=4

everything seems to work

the only time there is problems is if you create a product with attributes and dont put a read only to force selection and this product is added to cart with no attribute selected then get a blank screen when go to checkout,

i know i could just add the read only to force selection but just wondering if there is maybe an easy fix for items with attributes but selection is not required

thanks and hope this makes sense

bryan

30 May 2012, 7:07 AM
#2
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

Re: StockByAttributes with my stock id - zc1.5

if i add an item that has attributes but no selection is required it adds to shopping cart ok but when i click checkout i get

1065 Query was empty
in:
[]

with strict error reporting on

anybody point me in the right direction

thanks
Bryan

1 Jun 2012, 7:32 AM
#3
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

Re: StockByAttributes with my stock id - zc1.5

now sorted thanks

3 Jun 2012, 7:55 AM
#4
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

Re: StockByAttributes with my stock id - zc1.5

ok heres where i am so far, i am using rhusebys version with product id in version 1.5

i have made the attributes switchable in admin as to whether they are included in sba

so the example i have set up is tshirts in 3 sizes and 3 colours with optional print front and rear

http://catchagrip.co.uk/sba-id/index.php?main_page=product_info&cPath=1&products_id=5

in the original version you would need to set up variants of all combinations but this isnt the way i want it

i want it so if you order a green large with print and a green large without print it reduces the green large t shirt by 2, so far i have everything working fine (i think)

my only problem is the check stock function, i have this working fine so if there is a stock by attributes value it checks it my problem is if i say add a large green t shirt to cart it checks the stock on large green t shirt, if i add another large green t shirt with print on it to the cart it adds it as a new item which is fine, it goes checks the stock of large green t shirt and ignores the attributes which you have told it to ignore,

the problem is i need to go and check the stock of the item also check if there is any green large t shirts in the cart all ready so if i only have 1 green large left and keep only adding 1 at a time to cart it is happy that there is enough stock,

so is there a check stock in cart function so i can do something like quantity in stock - quantity in cart - qty added

hope this makes sense

bn

3 Jun 2012, 12:11 PM
#5
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: StockByAttributes with my stock id - zc1.5

Bryan,
Stangely just working on this anyway. I hadn't thought about that issue. Interesting because:

  1. I have on green shirt in stock
  2. I add a green shirt with front print
  3. It will appear in stock.
  4. I add a green shirt with back print.
  5. At the moment it will appear in stock because the stock check in SBA is 'per product' rather than 'per cart' ( and if you exclude some attributes from the stock calculation then this causes issues )

But the next question is which one of the two items in the cart should be flagged as out of stock? Or should they both be? What actually is the correct behaviour?

Nick
iszent.com

4 Jun 2012, 5:53 AM
#6
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

Re: StockByAttributes with my stock id - zc1.5

i didnt think of it either i just try to cross each problem as i find it,

not sure the correct behavior but i was going to mark both / all items that use the same t shirt

this is the only part im stuck on as i seem to have it reducing the stock all correctly

there is a similar issue in 1.5 here http://www.zen-cart.com/showthread.php?193409-Out-of-Stock-When-Placing-Order-IS-Checking-by-Product-and-Attribute

but it is not based on attributes and i think ajeh is marking them all, i suppose marking them all lets the customer decide which one to remove,

i added switch in attributes controller, this allows you to select which attributes are used for the stock calculation, so gift wrapping an item or not gift wrapping would end up the same item out of stock, or not if you want gift wrapping to be part of the stock equation

good to see a pro is on to it not just me who really just gets everything done by chance / luck and asking questions

bryan

Attachment 10546

4 Jun 2012, 6:36 AM
#7
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: StockByAttributes with my stock id - zc1.5

Bryan,
Well, I did it slightly differently in that I exclude attributes on a separate admin page and do it by option name rather than on a product by product basis. Just because that is what a client needs rather than because it is a better approach. Basically, I am writing an update of version 4.7 which I think is the last version I really liked :-)
Thanks for pointing me at Ajeh's posts. Yes, I think that with a attribute being excluded we will need to add something similar to that to correct the issue that you have spotted. I'll have a play with it in the next couple of days and let you know what I come up with.

Nick
iszent.com

4 Jun 2012, 1:06 PM
#8
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: StockByAttributes with my stock id - zc1.5

Bryan,
yes, you were right. The place to put the code is exactly where Ajeh says ( as always ). The actual code I have used is specific to my own solution. So not sure how much use it is to you. Basically I have recalculated the required stock before the redirect. For eample in checkout_confirmation/header_php.php :

                        if(function_exists(pwas_exclude_cart_total))
                        {
                            $total_stock = pwas_exclude_cart_total($attribute_array);
                        } else {
                            $total_stock = $products[$i]['quantity'];
                        }

                        //echo $total_stock;

			$stock_check_new = zen_check_stock($products[$i]['id'], $total_stock,$attributes);

So the recalculation happens in a function pwas_exclude_cart_total . That just loops through all the products and creates a new total. That bit is pretty specific to the way I have structured things.

Nick
iszent.com

4 Jun 2012, 1:42 PM
#9
bn17311 avatar

bn17311

Zen Follower

Join Date:
Apr 2010
Posts:
319
Plugin Contributions:
0

Re: StockByAttributes with my stock id - zc1.5

any chance your function just in case it helps me

thanks
bryan

4 Jun 2012, 3:57 PM
#10
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: StockByAttributes with my stock id - zc1.5

niccol:

Bryan,
Stangely just working on this anyway. I hadn't thought about that issue. Interesting because:

  1. I have on green shirt in stock
  2. I add a green shirt with front print
  3. It will appear in stock.
  4. I add a green shirt with back print.
  5. At the moment it will appear in stock because the stock check in SBA is 'per product' rather than 'per cart' ( and if you exclude some attributes from the stock calculation then this causes issues )

But the next question is which one of the two items in the cart should be flagged as out of stock? Or should they both be? What actually is the correct behaviour?

If I understand the issue correctly, Zen Cart doesn't remove items from stock until the purchase is final. IMHO, the inventory levels should be reduced based on what is in the cart. I know that major retailers that I've shopped with in the past treat products in the cart as if they have been removed from inventory. I presume this is to prevent two customers from purchasing the same item at the same time.

For example I've shopped online for a pair of shoes where there was only one pair left in stock for a particular color/size combo I select. If I were to want to select another pair of the SAME shoes, the color/size combos in stock will NOT include the one I have added to my cart as it is no longer "in stock". The item will remain out of stock until I complete the purchase or remove the item from my cart.

Of course since Zen Cart will save shopping cart sessions if you add items to your cart and then log out without completing the purchase.. So if this kind of functionality is added, this will have to be accounted for..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.