
Originally Posted by
Malaperth
but basically what I want to happen is that if there are items available, complete the if statement, but if the stock is 0, change the code in red so it removes that entire attribute from the database. Anyone care to help a senile old fart, or point me in a direction so I can figure it out by myself? l
What you are trying to do here is not exactly an "easy" task.
About the best I can do with the time available to me is direct you to how the SBA module itself does this. In simple terms, the SAB page/code itself
/admin/products_with_attributes_stock.php creates links to the attribute to be deleted.
These links read like:
<a href="http://yourdomain.com/youradmin/products_with_attributes_stock.php?action=delete&products_id=1234&attributes=543 21">Delete Variant</a>
So in theory, it is a matter of determining the products_id and the attributes value from the page where your code is found, inserting these into this URL and then having your code load the /products_with_attributes_stock.php page.
In practice this isn't going to work though, firstly because this is admin related code it won't work from the store front unless you are a logged in admin.
Secondly, if you could run this code from the location indicated it would take the customer away from thier current page to the attributes deletion code, and you'll then need some way to direct them back to where they were, so as I say, this method won't work.
Now having said that, the /products_with_attributes_stock.php code itself has everything that is needed to safely perform these deletions, so you could copy the relevant part of the code and create a 'function' from it specifically for this task, and that will overcome the problems I've just mentioned.
Your code snippet could then be coded something like:
Code:
if($products_options->fields['products_quantity'] > 0){ $PWA_STOCK_QTY = PWA_STOCK_QTY . $products_options->fields['products_quantity'] . ' ';
}
else{
my_delete_function($productID, $arributeValue) ;
}
Now having said that, do you *really* want the attributed product deleted, or are you happy for them to simply not been shown to the customer?
Although difficult to say without testing/checking, if you are happy to just have them not be shown, you could probably just comment out your line
that reads
$products_options->fields['products_options_values_name'] = PWA_OUT_OF_STOCK . $products_options->fields['products_options_values_name'];
and the out of stock item(s) won't appear in the list.
At least that's the theory.
Cheers
RodG
Bookmarks