function isAllValidProductIDs() { if (count($this->invalidProductIDs) > 0) { $multiMarker = ''; if (count($this->invalidProductIDs) > 1) { $multiMarker = 's'; } echo ostk_formatError('Invalid product ID' . $multiMarker . ': ' . implode(', ', $this->invalidProductIDs)); return False; } else { return True; } }
/** * Pattern 8 - Product Details Link * Allow users to create easy links to products they are showcasing. * Example Usage: * 1) [overstock type="product_link" id="8859234"] **/ function ostk_generateProductLinks($atts) { $atts = shortcode_atts(array('id' => null, 'display' => null, 'link_target' => 'new_tab'), $atts); $item = new SingleProductData($atts['id']); if ($item->isValidProductID()) { $display = trim($atts['display']); $output; switch ($display) { case 'name': $output = $item->getName(); break; case "price": $output = $item->getPrice(); break; case 'description': $output = $item->getDescription(); break; default: return ostk_formatError('We do not recognize your display input, please check it.'); } //switch return '<a href="' . $item->getAffiliateUrl() . '" class="ostk-element ostk-product-link" ' . ostk_getLinkTarget($atts) . '>' . $output . '</a>'; } }
function ostk_areAttributesValid($atts) { global $patterns; $validShortCode = true; $errorStr = ''; $type = $atts['type']; $keys = ostk_getKeyList($atts); $item = ostk_findObjWhereKeyEqualsValue($patterns, 'slug', $type); $required_attributes = ostk_getListByKey($item['required_attributes'], 'name'); $optional_attributes = ostk_getListByKey($item['optional_attributes'], 'name'); //Fail if missing any required attributes $missingRequiredAtts = ostk_lookForMissingRequiredAttributes($keys, $required_attributes); if (count($missingRequiredAtts) > 0) { $validShortCode = false; $errorStr = ostk_formatError('Missing required attributes: ' . implode(', ', $missingRequiredAtts)); } //Fail if using undefined attributes if ($validShortCode) { $invalidExtraAtts = ostk_lookForInvalidExtraAtts($keys, $required_attributes, $optional_attributes); if (count($invalidExtraAtts) > 0) { $validShortCode = false; $errorStr = ostk_formatError('The following are not valid attributes: ' . implode(', ', $invalidExtraAtts)); } } //Fail if any null attributes if ($validShortCode) { $nullAtts = ostk_lookForNullAtts($atts); if (count($nullAtts) > 0) { $validShortCode = false; $errorStr = ostk_formatError('The following atts cannot be null: ' . implode(', ', $nullAtts)); } } if ($validShortCode) { return true; } else { echo $errorStr; return false; } }