Option Veriants

Hi


I’m trying to get the status of option variants on the detail product page for an addon that I’m doing, on the func.php for the addon I have the following code to get the information from the DB.


$product[‘option_variants’] = db_get_field(‘SELECT status FROM ?:product_option_variants WHERE variant_id = ?i’, $params[‘variant_id’]);


But it isn’t working, can anyone help me with it?

Hi

I’m trying to get the status of option variants on the detail product page for an addon that I’m doing, on the func.php for the addon I have the following code to get the information from the DB.

$product['option_variants'] = db_get_field('SELECT status FROM ?:product_option_variants WHERE variant_id = ?i', $params['variant_id']);

But it isn’t working, can anyone help me with it?

Hello!

Please send us the full function.

Try to add after your line of code

fn_print_r($params['variant_id'], $product['option_variants']);

and check

Hi

I tried :

fn_print_r($params['variant_id'], $product['option_variants']);

But it didn't work.

The function code that I have is:

    if ($product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['options_inventory'] = db_get_field('SELECT MAX(amount) FROM ?:product_options_inventory WHERE product_id = ?i', $params['product_id']);	
        $product['variant_status'] = db_get_field('SELECT status FROM ?:product_option_variants WHERE variant_id = ?i', $params['variant_id']);
    $displaying_options = array(
        'INSTOCK' => ($product['amount'] > 0 && $product['out_of_stock_actions'] != 'B') ? 'Y' : 'N',
        'OUTSTOCK' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
    );

The only thing I can't get to work is the status for the variant, I want it to only take in to account active variants and not disabled ones.

Hi

I tried :

fn_print_r($params['variant_id'], $product['option_variants']);

But it didn't work.

The function code that I have is:

    if ($product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['options_inventory'] = db_get_field('SELECT MAX(amount) FROM ?:product_options_inventory WHERE product_id = ?i', $params['product_id']);	
        $product['variant_status'] = db_get_field('SELECT status FROM ?:product_option_variants WHERE variant_id = ?i', $params['variant_id']);
    $displaying_options = array(
        'INSTOCK' => ($product['amount'] > 0 && $product['out_of_stock_actions'] != 'B') ? 'Y' : 'N',
        'OUTSTOCK' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
    );

The only thing I can't get to work is the status for the variant, I want it to only take in to account active variants and not disabled ones.

Hello!

How do you get $params['variant_id'] ?

Hi

I tried :

What do you mean by "But it didn't work"? Did you receive error message or empty results?

What do you mean by "But it didn't work"? Did you receive error message or empty results?

When I tried putting:

fn_print_r($params['variant_id'], $product['option_variants']);

I just get broken page on the store front.

[attachment=12933:Screen Shot 2018-01-05 at 12.28.48.png]

Screen Shot 2018-01-05 at 12.28.48.png

From this screenshot I see that $params['variant_id'] is empty. So the final result is empty as well

From this screenshot I see that $params['variant_id'] is empty. So the final result is empty as well



I'm actually working from one of your addons as a templet, product_stickers, this section:

    if ($single_product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['price'] = db_get_field('SELECT price FROM ?:product_prices WHERE product_id = ?i AND lower_limit = ?i', $params['product_id'], 1);
        $product['popularity'] = db_get_field('SELECT total FROM ?:product_popularity WHERE product_id = ?i', $params['product_id']);
    $sticker_displaying_options = array(
        'NOT' => 'Y',
        'TOP' => (Registry::get('addons.discussion.status') == 'A') ? 'Y' : 'N',
        'OUT' => ($product['amount'] < $product['min_qty']) ? 'Y' : 'N',
        'NEW' => 'Y',
        'POP' => 'Y',
        'SHP' => ($product['free_shipping'] == 'Y') ? 'Y' : 'N',
        'DSC' => (isset($product['list_price']) && $product['list_price'] > $product['price']) ? 'Y' : 'N',
        'CMS' => ($product['avail_since'] > 0) ? 'Y' : 'N',
        'BST' => 'Y',
        'PRE' => ($product['out_of_stock_actions'] == 'B') ? 'Y' : 'N',
        'AGE' => (Registry::get('addons.age_verification.status') == 'A' && $product['age_verification'] == 'Y') ? 'Y' : 'N',
        'WHL' => (!empty($product['prices'])) ? 'Y' : 'N',
        'DIG' => ($product['is_edp'] == 'Y') ? 'Y' : 'N',
    );


This section:

'OUT' => ($product['amount'] < $product['min_qty']) ? 'Y' : 'N',


Doesn't take in to account product option with inventory. now I've worked this part out:

'OUT' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',

The only problem is that if a variant has 1 in stock, but that variant is disabled it doesn't take in to account that the variant is disabled so it comes up as in stock.

This is my full code for the section:

    if ($single_product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['price'] = db_get_field('SELECT price FROM ?:product_prices WHERE product_id = ?i AND lower_limit = ?i', $params['product_id'], 1);
        $product['popularity'] = db_get_field('SELECT total FROM ?:product_popularity WHERE product_id = ?i', $params['product_id']);
        $product['options_inventory'] = db_get_field('SELECT MAX(amount) FROM ?:product_options_inventory WHERE product_id = ?i', $params['product_id']);	
        $product['variant_status'] = db_get_field('SELECT status FROM ?:product_option_variants WHERE variant_id = ?i', $params['variant_id']);
    $sticker_displaying_options = array(
        'NOT' => 'Y',
        'TOP' => (Registry::get('addons.discussion.status') == 'A') ? 'Y' : 'N',
        'IST' => (($product['amount'] > 0 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] > 0 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
        'OUT' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
        'AVA' => ($product['tracking'] == 'D') ? 'Y' : 'N',
        'NEW' => 'Y',
        'POP' => 'Y',
        'SHP' => ($product['free_shipping'] == 'Y') ? 'Y' : 'N',
        'DSC' => (isset($product['list_price']) && $product['list_price'] > $product['price']) ? 'Y' : 'N',
        'CMS' => ($product['avail_since'] > 0) ? 'Y' : 'N',
        'BST' => 'Y',
        'PRE' => ($product['out_of_stock_actions'] == 'B') ? 'Y' : 'N',
        'AGE' => (Registry::get('addons.age_verification.status') == 'A' && $product['age_verification'] == 'Y') ? 'Y' : 'N',
        'WHL' => (!empty($product['prices'])) ? 'Y' : 'N',
        'DIG' => ($product['is_edp'] == 'Y') ? 'Y' : 'N',
    );  



I'm actually working from one of your addons as a templet, product_stickers, this section:

    if ($single_product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['price'] = db_get_field('SELECT price FROM ?:product_prices WHERE product_id = ?i AND lower_limit = ?i', $params['product_id'], 1);
        $product['popularity'] = db_get_field('SELECT total FROM ?:product_popularity WHERE product_id = ?i', $params['product_id']);
    $sticker_displaying_options = array(
        'NOT' => 'Y',
        'TOP' => (Registry::get('addons.discussion.status') == 'A') ? 'Y' : 'N',
        'OUT' => ($product['amount'] < $product['min_qty']) ? 'Y' : 'N',
        'NEW' => 'Y',
        'POP' => 'Y',
        'SHP' => ($product['free_shipping'] == 'Y') ? 'Y' : 'N',
        'DSC' => (isset($product['list_price']) && $product['list_price'] > $product['price']) ? 'Y' : 'N',
        'CMS' => ($product['avail_since'] > 0) ? 'Y' : 'N',
        'BST' => 'Y',
        'PRE' => ($product['out_of_stock_actions'] == 'B') ? 'Y' : 'N',
        'AGE' => (Registry::get('addons.age_verification.status') == 'A' && $product['age_verification'] == 'Y') ? 'Y' : 'N',
        'WHL' => (!empty($product['prices'])) ? 'Y' : 'N',
        'DIG' => ($product['is_edp'] == 'Y') ? 'Y' : 'N',
    );


This section:

'OUT' => ($product['amount'] < $product['min_qty']) ? 'Y' : 'N',


Doesn't take in to account product option with inventory. now I've worked this part out:

'OUT' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',

The only problem is that if a variant has 1 in stock, but that variant is disabled it doesn't take in to account that the variant is disabled so it comes up as in stock.

This is my full code for the section:

    if ($single_product) {
        $product = db_get_row('SELECT * FROM ?:products WHERE product_id = ?i', $params['product_id']);
        $product['price'] = db_get_field('SELECT price FROM ?:product_prices WHERE product_id = ?i AND lower_limit = ?i', $params['product_id'], 1);
        $product['popularity'] = db_get_field('SELECT total FROM ?:product_popularity WHERE product_id = ?i', $params['product_id']);
        $product['options_inventory'] = db_get_field('SELECT MAX(amount) FROM ?:product_options_inventory WHERE product_id = ?i', $params['product_id']);	
        $product['variant_status'] = db_get_field('SELECT status FROM ?:product_option_variants WHERE variant_id = ?i', $params['variant_id']);
    $sticker_displaying_options = array(
        'NOT' => 'Y',
        'TOP' => (Registry::get('addons.discussion.status') == 'A') ? 'Y' : 'N',
        'IST' => (($product['amount'] > 0 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] > 0 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
        'OUT' => (($product['amount'] < 1 && $product['tracking'] == 'B') || ($product['variant_status'] == 'A' && $product['options_inventory'] < 1 && $product['tracking'] == 'O') && ($product['out_of_stock_actions'] != 'B')) ? 'Y' : 'N',
        'AVA' => ($product['tracking'] == 'D') ? 'Y' : 'N',
        'NEW' => 'Y',
        'POP' => 'Y',
        'SHP' => ($product['free_shipping'] == 'Y') ? 'Y' : 'N',
        'DSC' => (isset($product['list_price']) && $product['list_price'] > $product['price']) ? 'Y' : 'N',
        'CMS' => ($product['avail_since'] > 0) ? 'Y' : 'N',
        'BST' => 'Y',
        'PRE' => ($product['out_of_stock_actions'] == 'B') ? 'Y' : 'N',
        'AGE' => (Registry::get('addons.age_verification.status') == 'A' && $product['age_verification'] == 'Y') ? 'Y' : 'N',
        'WHL' => (!empty($product['prices'])) ? 'Y' : 'N',
        'DIG' => ($product['is_edp'] == 'Y') ? 'Y' : 'N',
    );  

You need to print $params array first to see if there is variant_id.

Do you know how I can do that? I’ve tried many things but it just isn’t happening.

Do you know how I can do that? I’ve tried many things but it just isn’t happening.

Please try this:

fn_print_r($params);

Why don't you send your ideas to the add-on developer? It might be useful for other store owners as well.


I'm actually working from one of your addons as a templet, product_stickers, this section:

Please post a ticket at https://www.ecom-labs.com/index.php?dispatch=crm.tickets so that we can help you