function __construct($productId) { //make the api call using product details api //https://confluence.overstock.com/display/WIIP/Bridge2Solutions+-+Product+Details+API $url = "http://www.overstock.com/api/product.json?prod_id=" . $productId; $json = file_get_contents($url); $productData = json_decode($json, True); if (isset($productData['id'])) { $this->validProductID = True; } else { $this->validProductID = False; } $taxonomyStore = $productData[taxonomy][store][id]; $this->name = $productData[name]; $this->productId = $productData[id]; $this->developerId = $GLOBALS['developerId']; if ($taxonomyStore == 2 || $taxonomyStore == 3) { return ostk_formatError("Our apologies we do not offer <b>'{$this->name}'</b> for affiliate sale. Product ID is '{$productId}'"); } else { //we have dynamic pricing types, including COMPARISON_PRICE, DISCOUNTED_AMOUNT, CURRENT_PRICE //return only the CURRENT_PRICE (formatted) $numPriceSets = count($productData[priceSet]); for ($i = 0; $i < $numPriceSets; $i++) { if ($productData[priceSet][$i][priceType] == "CURRENT_PRICE") { $this->price = $productData[priceSet][$i][formattedPrice]; if ($this->price >= 1500) { return ostk_formatError("Maximum price for affiliate items is \$1500."); } } } $this->baseImageUrl = $productData[meta][imageBaseUrl]; $this->numImages = count($productData[oViewerImages]); //we must populate the $arrayOfAllProductImages dynamically based on $numImages $this->arrayOfAllProductImages = array(); for ($j = 1; $j <= $this->numImages; $j++) { $imageSizeCount = count($productData[oViewerImages][$j - 1][imageSizes]); //each oViewerImage has a dynamic number of sizes, fetch the biggest one $imagePath = $productData[oViewerImages][$j - 1][imageSizes][$imageSizeCount - 1][imagePath]; //last img in array is the biggest one. $imageUrl = $this->baseImageUrl . $imagePath; array_push($this->arrayOfAllProductImages, $imageUrl); } $this->description = $productData[shortDescription]; if (empty($this->arrayOfAllProductImages)) { $this->imgUrl_large = $this->baseImageUrl . $productData[imageLarge]; } else { $this->imgUrl_large = $this->arrayOfAllProductImages[0]; } $this->imgUrl_medium = $this->baseImageUrl . $productData[imageMedium1]; $this->imgUrl_thumbnail = $this->baseImageUrl . $productData[imageThumbnail]; $murl = "http%3A%2F%2Fwww.overstock.com%2F" . $this->productId . "%2Fproduct.html"; $this->affiliateUrl = ostk_generateAffiliateLink($murl); $this->averageReviewAsDecimal = $productData[reviews]; if (!empty($productData[rating])) { $this->averageReviewAsGif = "http://ak1.ostkcdn.com/" . $productData[rating]; } } }
/** * Pattern 2 - URL: lets you create links to any overstock page * Generate a link to a predefined page on Overstock.com * Specify the link_text with the link_text attribute * Usage example * 1) [overstock type="link" url="http://www.overstock.com/Worldstock-Fair-Trade/Natural-Thailand/9179503/product.html"] * 2) [overstock type="link" url="http://www.overstock.com/Worldstock-Fair-Trade/Natural-Thailand/9179503/product.html" link_text="I want to buy this for my wife"] **/ function ostk_generateLinktoAnyPage($atts) { $atts = shortcode_atts(array('url' => 'http://www.overstock.com/', 'link_text' => 'A link to Overstock.com', 'link_target' => 'new_tab'), $atts); $affiliateLink = ostk_generateAffiliateLink($atts['url']); $link_text = $atts['link_text']; return '<a href="' . $affiliateLink . '" class="ostk-element ostk-link" ' . ostk_getLinkTarget($atts) . '>' . $link_text . '</a>'; }