'; if (isset($product['full_path'])) { $meta .= ''; } //GET RELATED MEDIA $product_media = ioAPIv2('/v2/products_media/product_id='.$product['rowID'],'',$clientsecret); $product_media = json_decode($product_media,true); // If the user clicked the add to cart button if (isset($_POST['product'])) { //VALIDATE THE INPUT FOR THE SHOPPING CART $payload = json_encode($_POST['product'], JSON_UNESCAPED_UNICODE); $product_to_cart = ioAPIv2('/v2/shopping_cart/',$payload,$clientsecret); $product_to_cart = json_decode($product_to_cart,true); // Check if the product exists (array is not empty) if ($product_to_cart['quantity'] > 0) { // Product exists in database, now we can create/update the session variable for the cart if (!isset($_SESSION['cart'])) { // Shopping cart session variable doesnt exist, create it $_SESSION['cart'] = []; } $cart_product = &get_cart_product($product_to_cart['id'], $product_to_cart['options']); if ($cart_product) { // Product exists in cart, update the quanity $cart_product['quantity'] += $quantity; } else { // Product is not in cart, add it $_SESSION['cart'][] = $product_to_cart; } } // Prevent form resubmission... header('Location: ' . url('index.php?page=cart')); exit; } } else { // Output simple error if the id wasn't specified http_response_code(404); exit('Product does not exist!'); } //LINK to products page: $products_link = url(link_to_collection); $product_link = url('index.php?page=product&id='.($product['url_slug'] ? $product['url_slug'] : $product['rowID'])); /*Notifier - when 1 user ask for product notification $notifier = 0; if (isset($_POST["notifier"])){ $stmt = $pdo->prepare('SELECT * FROM accounts WHERE id = ?'); $stmt->execute([ $_SESSION['account_id'] ]); $account = $stmt->fetch(PDO::FETCH_ASSOC); $email = $account['email']; send_product_notification_email($email, $_POST["product_details"]); $notifier = 1; } */ $view = template_header((${$product['productname']} ?? $product['productname']), $meta); if ($error){ $view .='

'.$error.'

'; } else { $view .='
'.$breadcrum_products.'

/ '.(${$product['productname']} ?? $product['productname']).'

'.(${$product['productname']} ?? $product['productname']).'

'.$breadcrum_products.'

/ '.(${$product['productname']} ?? $product['productname']).'

'.(${$product['productname']} ?? $product['productname']).'

'.currency_code.''.number_format($product['price'],2).''; if ($product['rrp'] > 0){ $view .= ''.currency_code.''.number_format($product['rrp'],2).''; } $view .='
'; //Stock status $stock_status = ($product['quantity'] != 0) ? $product_on_stock : $out_of_stock; $style = ($stock_status == $product_on_stock) ? 'style="color:green;"' : 'style="color:gray;font-weight: lighter;"'; $view .= '

'.$stock_status.'

'; $view .='
'; //FREE SHIPMENT INDICATOR if (free_shipment_indicator){ freeShipment($product['price'],'div'); } $view .='
'; //CHECK FOR OPTIONS ASSIGNED if(isset($product['configurations'])){ foreach ($product['configurations'] as $configuration) { //CHECK FOR GROUPS if (isset($configuration['type']) && $configuration['type'] == 'product'){ $view .= ''; } //CHECK FOR GROUPS if (isset($configuration['type']) && $configuration['type'] == 'group'){ $view .= ''; //BASED ON GROUP TYPE CREATE INPUT FORM switch($configuration['group_type']) { case 0: //Radiobutton $output =''; foreach ($configuration['attributes'] as $attribute){ // Check if this option should be pre-selected $isChecked = (isset($_GET['option_id']) && $_GET['option_id'] == $attribute['attribute_id']) ? ' checked' : ''; if(isset($attribute['full_path']) && $attribute['full_path'] !=''){ $onclick =''; //ADD updateOption to change pictures when GROUP is IN configuration if(isset($product['config_setting']) && $product['config_setting'] == $configuration['assignment']){ $IMG_large_id = img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE $onclick = 'onclick="updateOption(\''.$product['rowID'].'\',\''.$IMG_large_id.'\')"'; } $IMG_small_id = img_url.$attribute['full_path']; //URL TO SMALL IMAGE $output .= ' '; } else { $output .= ' '; } } $view .= '
'.$output.'
'; break; case 1: //Checkbox $output =''; foreach ($configuration['attributes'] as $attribute){ // Check if this option should be pre-selected $isChecked = (isset($_GET['option_id']) && $_GET['option_id'] == $attribute['attribute_id']) ? ' checked' : ''; if(isset($attribute['full_path']) && $attribute['full_path'] !=''){ $onclick =''; //ADD updateOption to change pictures when GROUP is IN configuration if(isset($product['config_setting']) && $product['config_setting'] == $configuration['assignment']){ $IMG_large_id = img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE $onclick = 'onclick="updateOption(\''.$product['rowID'].'\',\''.$IMG_large_id.'\')"'; } $IMG_small_id = img_url.$attribute['full_path']; //URL TO SMALL IMAGE $output .= ' '; } else { $output .= ' '; } } $view .= '
'.$output.'
'; break; case 2: //Dropdown // Check if any option is pre-selected via URL $hasPreselection = isset($_GET['option_id']) && !empty($_GET['option_id']); $output ='
'; break; } } } } $view .='
'.(${$product['productdescription']} ?? $product['productdescription']).'
'; $view .= ''; } $view .= ' '; $view .= template_footer(); //OUTPUT echo $view; ?>