本文整理汇总了PHP中Price::load_settings方法的典型用法代码示例。如果您正苦于以下问题:PHP Price::load_settings方法的具体用法?PHP Price::load_settings怎么用?PHP Price::load_settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Price
的用法示例。
在下文中一共展示了Price::load_settings方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shopp_product_variant
/**
* Get a specific Price object
*
* @api
* @since 1.2
*
* @param mixed $variant the id of the variant, or array('product'=>int, 'option' => array('menu1name'=>'option', 'menu2name'=>'option') ) to specify variant by product id and option
* @param string $pricetype (optional default:variant) product, variant, or addon
* @return ShoppPrice Price object or false on error
**/
function shopp_product_variant($variant = false, $pricetype = 'variant')
{
if (false === $variant) {
shopp_debug(__FUNCTION__ . " failed: Variant id required.");
return false;
}
if (is_numeric($variant)) {
$Price = new ShoppPrice($variant);
if (empty($Price->id)) {
shopp_debug(__FUNCTION__ . " failed: Unable to load variant {$variant}.");
return false;
}
} else {
if (is_array($variant)) {
// specifying variant by product id and option
$Product = new stdClass();
if (isset($variant['product']) && is_numeric($variant['product'])) {
$Product = new ShoppProduct($variant['product']);
$Product->load_data(array('prices', 'meta', 'summary'));
}
if (empty($Product->id) || empty($Product->prices)) {
shopp_debug(__FUNCTION__ . " failed: Unable to load variant. Invalid Product.");
return false;
}
$pricetype = $pricetype == 'variant' ? 'variation' : $pricetype;
$pricetypes = array('product', 'variation', 'addon');
if (!in_array($pricetype, $pricetypes)) {
shopp_debug(__FUNCTION__ . " failed: Invalid pricetype. Can be product, variant, or addon.");
return false;
}
if ('product' == $pricetype) {
// No product context for product with variants
if ('on' == $Product->variants) {
shopp_debug(__FUNCTION__ . " failed: Invalid pricetype for this product.");
return false;
}
foreach ($Product->prices as $price) {
if ('product' == $price->context) {
$Price = new ShoppPrice();
$Price->populate($price);
$Price->load_settings();
$Price->load_download();
break;
}
}
} else {
// addon or variant
if (!isset($variant['option']) || !is_array($variant['option']) || empty($variant['option'])) {
shopp_debug(__FUNCTION__ . " failed: Missing option array.");
return false;
}
$menukey = substr($pricetype, 0, 1);
$flag = $pricetype == 'variation' ? 'variants' : 'addons';
if (!isset($Product->options[$menukey]) || $Product->{$flag} == 'off') {
shopp_debug(__FUNCTION__ . " failed: No product variant options of type {$pricetype} for product {$Product->id}");
return false;
}
// build simple option menu array
$menu = array();
foreach ($Product->options[$menukey] as $optionmenu) {
$key = $optionmenu['name'];
$menu[$key] = array();
foreach ($optionmenu['options'] as $option) {
$menu[$key][] = $option['name'];
}
}
list($optionkey, $options, $label, $mapping) = $Product->optionmap($variant['option'], $menu, $pricetype);
if ('variation' == $pricetype && !isset($Product->pricekey[$optionkey]) || !$options) {
shopp_debug(__FUNCTION__ . " failed: Invalid option.");
return false;
}
if ('variation' == $pricetype) {
$price = $Product->pricekey[$optionkey];
} else {
// Find the option
foreach ($Product->prices as $price) {
if ($price->context == $pricetype && $price->options == $options) {
break;
}
}
}
$Price = new Price();
$Price->populate($price);
$Price->load_settings();
$Price->load_download();
}
// end if product type / addon/variants type
}
}
if (!isset($Price)) {
//.........这里部分代码省略.........