function product_is_wishlisted($retailer, $pid) { $product = product_get_raw($retailer, $pid); $lists = lists_get_for_user(); $list_ids = array(); foreach ($lists as $list) { $list_ids[] = $list['id']; } $list_ids[] = 'def_' . current_user(); if ($product) { $lists = @$product['lists'] ?: array(); foreach ($list_ids as $list_id) { if (array_contains($lists, $list_id)) { return true; } } } return false; }
if (!$product && $product_url && $product_title && $product_image_url && $pid && $product_price) { $product_price = preg_replace('#[^0-9\\.]+#m', '', $product_price) * 1; $product = product_create($retailer, $pid, array('title' => $product_title, 'url' => $product_url, 'price' => $product_price, 'currency' => 'GBP', 'image_url' => $product_image_url)); } if (!$product) { $product = array(); $product['title'] = 'Asus C300 Chromebook, Intel Celeron, 2GB RAM, 32GB SSD, 13.3", Red'; $product['image_url'] = 'http://johnlewis.scene7.com/is/image/JohnLewis/233845648alt3?$prod_main$'; $product['price'] = 239.9; $product['url'] = 'http://www.johnlewis.com/asus-c300-chromebook-intel-celeron-2gb-ram-32gb-ssd-13-3-red/p1625271'; } $logo = 'http://www.johnlewis.com/assets/header/john-lewis-logo.gif'; $product['logo'] = image_thumbnail_url($logo, '200x20', 'resize'); $product_image = image_thumbnail_url(@$product['image_url'], '320x250', 'resizenp'); $price_formatted = '£' . sprintf('%01.2f', $product['price']); $lists = lists_get_for_user(false); if ($product) { $list_ids = product_get_list_ids($retailer, $pid); if ($list_id) { if (array_contains($list_ids, $list_id)) { if (isset($_GET['list'])) { product_remove_from_list($retailer, $pid, $list_id); } } else { product_add_to_list($retailer, $pid, $list_id); } $list_ids = product_get_list_ids($retailer, $pid); } $data = array('product' => $product, 'product_image' => $product_image, 'price_formatted' => $price_formatted, 'lists' => $lists, 'added_list_id' => $list_id, 'pid' => $pid, 'retailer' => $retailer, 'list_ids' => $list_ids, 'is_popup' => $is_popup); show_template('add_product_popup', $data); } else {
<?php require '_init.php'; $extended = @$_GET['extended'] == 'true'; $lists = lists_get_for_user($extended); $def_list_id = 'def_' . current_user(); $deflist = array('id' => $def_list_id, 'title' => 'All stashes', 'n_users' => 1, 'date' => '13th September 2014'); $deflist['n_products'] = products_count(array('lists' => $def_list_id)); if ($extended) { $deflist['products'] = products_find(array('lists' => $def_list_id), 10); } array_unshift($lists, $deflist); $ret = array('lists' => $lists); send_json($ret);