Hello. I am trying to add an order correctly by using remote control . But I cannot place the order with correct options. The products should be added with their correct options related that product.
The code part below gets the product. But the product in my shop has Option Combination. Each product variant has its own product code.
<br />
Example:<br />
* Product ID: 12, code: YKC<br />
* Option combination 1: Product Code: YKC-1<br />
* Option combination 2: Product Code YKC-2<br />
```<br />
<br />
For example I get product with product code "YKC-2", but the product is added with its first options which product code is "YKC-1". So, product which is added correct, but product option that is added to cart in INCORRECT. How can be chosen the correct product option according to product code?<br />
<br />
Below ypou can see the code part I use: ([i]Sorry, I am not good at coding[/i])<br />
<br />
```php
<br />
<br />
$product_code= array('YKC-2','TRED1'); //for example<br />
<br />
foreach ($product_code as $pod) {<br />
//Find product<br />
$product_id = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $pod);<br />
if( empty($product_id) ) { // Try option inventory<br />
$product_id = db_get_field("SELECT product_id FROM ?:product_options_inventory WHERE product_code=?s", $pod);<br />
$option_id = db_get_field("SELECT option_id FROM ?:product_options WHERE product_id = ?i AND option_type = ?s", $product_id, 'S');<br />
}<br />
<br />
<br />
<br />
$option_data = fn_get_product_option_data($option_id, $product_id);<br />
<br />
foreach ($option_data['variants'] as $_k => $_v) {<br />
$c_hash = fn_generate_cart_id($product_id, array('product_options' => array($option_id => $_v['variant_id'])));<br />
$c = fn_get_options_combination(array($option_id => $_v['variant_id']));<br />
$cart['products'][$_k]['product_options'] = $c;<br />
}<br />
<br />
<br />
// Add to cart button was pressed for single product on advanced list<br />
$_REQUEST['product_data'][$product_id]['amount'] = $amount ? $amount : 1;<br />
if( empty($_REQUEST['product_data']) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {<br />
$_REQUEST['product_data'][$product_id] = fn_get_product_data($product_id, $auth);<br />
}<br />
}<br />
<br />
$cart['user_id'] = $user_data['user_id'];<br />
$auth['user_id'] = $cart['user_id'];<br />
$cart['user_data'] = fn_get_user_info($cart['user_id']);<br />
<br />
<br />
$auth['referer'] = 'http://localhost/index.php?dispatch=checkout.checkout';<br />
$auth['points'] = 0;<br />
<br />
//payment method<br />
$cart['payment_id'] = 2;<br />
<br />
//shipping id<br />
$cart['shipping_id'] = 6;<br />
<br />
$cart['payment_surcharge'] = 0;<br />
$cart['chosen_shippings'] = array();<br />
$cart['chosen_shippings'][0] = fn_get_shipping_params(6);<br />
<br />
<br />
fn_checkout_update_shipping($cart, array(6));<br />
fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);<br />
fn_save_cart_content($cart, $auth['user_id']);<br />
$cart['change_cart_products'] = true;<br />
fn_calculate_cart_content($cart, $auth, 'S', false, 'F', false);<br />
<br />
list($order_id, $process_payment) = fn_place_order($cart, $auth, 'save'); <br />
```<br />
<br />
I need help.