Hi Mike!
Sorry, it took me longer than expected to send you code sample. Here we go though.
1) Have a look at the HTML code that represents options selector in store-front. It is something similar to:
Code:
<ul class="attribute-values">
<li>
<span class="title">color</span>
<select class="form-control" name="attribute_values[51]" data-attribute-id="51">
<option value="248">white</option>
<option selected="selected" value="249">black</option>
</select>
</li>
<li>
<span class="title">size</span>
<select class="form-control" name="attribute_values[52]" data-attribute-id="52">
<option selected="selected" value="250">s</option>
<option value="251">m</option>
<option value="252">l</option>
</select>
</li>
</ul>
Values marked by
green are IDs of product attributes. In other words, they are IDs of attribute Color and attribute Size.
Values marked by
red are IDs of product attribute values. In other words, they are IDs of White, Black, S, M and L attribute values.
2) Below is a test script that gives you an idea of how to check availability of a variant with given attribute values:
PHP Code:
<?php
//X-Cart initializtion
require_once 'top.inc.php';
require_once 'top.inc.additional.php';
$product = \XLite\Core\Database::getRepo('\XLite\Model\Product')->find(5);
$attributes = array(
51 => 248,
52 => 250,
);
$preparedAttributes = $product->prepareAttributeValues($attributes);
$pVariant = $product->getVariant($preparedAttributes);
$result = $pVariant->isOutOfStock();
var_dump($result);
This script assumes that you check attribute combination for product with ID = 5:
PHP Code:
$product = \XLite\Core\Database::getRepo('\XLite\Model\Product')->find(5);
It also assumes that the script will be run from root folder of X-Cart 5.
Please, let me know if this code sample is helpful.
Tony.