コード例 #1
0
ファイル: Core.php プロジェクト: BlessySoftwares/anvelocom
/**
 * @deprecated Use Shopp::taxrate()
 **/
function shopp_taxrate($override = null, $taxprice = true, $Item = false)
{
    return Shopp::taxrate($Item);
}
コード例 #2
0
ファイル: product.php プロジェクト: BlessySoftwares/anvelocom
    /**
     * Iterate over the product variants or provide markup for a product variants chooser widget
     *
     * @api `shopp('product.variants')`
     * @since 1.1
     *
     * @param string       $result  The output
     * @param array        $options The options
     * - **mode**: `loop` (loop, single, multiple) Iterate over the variants with `loop` or provide an variant chooser widget using a `single` drop-down menu for all variants or `multiple` menus
     * - **defaults**: Specify a default option that is displayed as the initial selection for the `menu`
     * - **before_menu**: Markup to add before the widget
     * - **after_menu**: Markup to add after the widget
     * - **label**: `on` (on,off) Show or hide the menu name labels from the `menu` widget
     * - **format**: `%l (+%p)` The variant option label format
     *   - **%p**: shows the current variant price including available discounts.
     *   - **%l**: show the option label.
     *   - **%s**: show the stock amount of a product in inventory
     *   - **%d**: show the discount amount of an on sale variant.
     *   - **%r**: show the original price (the non-sale price) of the product variant.
     *   - **%u**: show the SKU for the product variant.
     * - **required**: `You must select the options for this item before you can add it to your shopping cart.` The error message to show when adding to the cart without selecting an variant when the **required** option is `on`
     * - **taxes**: Include or exclude taxes from prices
     * - **class**: The class attribute specifies one or more class-names for the menu elements
     * @param ShoppProduct $O       The working object
     * @return bool|string True if the next variant exists, or false otherwise, or the variant chooser markup
     **/
    public static function variants($result, $options, $O)
    {
        $string = '';
        if (!isset($options['mode'])) {
            if (!isset($O->_prices_loop)) {
                reset($O->prices);
                $O->_prices_loop = true;
            } else {
                next($O->prices);
            }
            $price = current($O->prices);
            while (false !== $price && ('N/A' == $price->type || 'variation' != $price->context)) {
                $price = next($O->prices);
            }
            if (false !== current($O->prices)) {
                return true;
            } else {
                $O->_prices_loop = false;
                return false;
            }
        }
        if (shopp_setting_enabled('inventory') && $O->outofstock) {
            return false;
        }
        // Completely out of stock, hide menus
        if (!isset($options['taxes'])) {
            $options['taxes'] = null;
        }
        $defaults = array('defaults' => '', 'disabled' => 'show', 'pricetags' => 'show', 'before_menu' => '', 'after_menu' => '', 'format' => '%l (%p)', 'label' => 'on', 'mode' => 'multiple', 'taxes' => null, 'required' => __('You must select the options for this item before you can add it to your shopping cart.', 'Shopp'));
        $options = array_merge($defaults, $options);
        extract($options);
        $taxes = isset($taxes) ? Shopp::str_true($taxes) : null;
        $taxrates = self::_taxes($O, 'price');
        $collection_class = ShoppCollection() && isset(ShoppCollection()->slug) ? 'category-' . ShoppCollection()->slug : '';
        if ('single' == $mode) {
            if (!empty($before_menu)) {
                $string .= $before_menu . "\n";
            }
            if (Shopp::str_true($label)) {
                $string .= '<label for="product-options' . (int) $O->id . '">' . Shopp::esc_html__('Options') . ': </label> ' . "\n";
            }
            $string .= '<select name="products[' . (int) $O->id . '][price]" id="product-options' . (int) $O->id . '" class="' . esc_attr($collection_class) . ' product' . (int) $O->id . ' options">';
            if (!empty($defaults)) {
                $string .= '<option value="">' . esc_html($options['defaults']) . '</option>' . "\n";
            }
            foreach ($O->prices as $pricing) {
                if ('variation' != $pricing->context) {
                    continue;
                }
                $currently = Shopp::str_true($pricing->sale) ? $pricing->promoprice : $pricing->price;
                $disable = $pricing->type == 'N/A' || Shopp::str_true($pricing->inventory) && $pricing->stock == 0;
                $currently = self::_taxed((double) $currently, $O, $pricing->tax, $taxes);
                $discount = 0 == $pricing->price ? 0 : 100 - round($pricing->promoprice * 100 / $pricing->price);
                $_ = new StdClass();
                $_->p = 'Donation' != $pricing->type && !$disable ? money($currently) : false;
                $_->l = $pricing->label;
                $_->i = Shopp::str_true($pricing->inventory);
                $_->s = $_->i ? (int) $pricing->stock : false;
                $_->u = $pricing->sku;
                $_->tax = Shopp::str_true($pricing->tax);
                $_->t = $pricing->type;
                $_->r = $pricing->promoprice != $pricing->price ? money($pricing->price) : false;
                $_->d = $discount > 0 ? $discount : false;
                if (!$disable || 'show' == $disabled) {
                    $string .= '<option value="' . $pricing->id . '"' . ($disable ? ' disabled="disabled"' : '') . '>' . esc_html(self::_variant_formatlabel($format, $_)) . '</option>' . "\n";
                }
            }
            $string .= '</select>';
            if (!empty($options['after_menu'])) {
                $string .= $options['after_menu'] . "\n";
            }
        } else {
            if (!isset($O->options)) {
                return;
            }
            $menuoptions = $O->options;
            if (!empty($O->options['v'])) {
                $menuoptions = $O->options['v'];
            }
            $baseop = shopp_setting('base_operations');
            $precision = $baseop['currency']['format']['precision'];
            $pricekeys = array();
            foreach ($O->pricekey as $key => $pricing) {
                $currently = Shopp::str_true($pricing->sale) ? $pricing->promoprice : $pricing->price;
                $disable = $pricing->type == 'N/A' || Shopp::str_true($pricing->inventory) && $pricing->stock == 0;
                $currently = self::_taxed((double) $currently, $O, $pricing->tax, $taxes);
                $discount = 100 - round($pricing->promoprice * 100 / $pricing->price);
                $_ = new StdClass();
                $_->p = 'Donation' != $pricing->type && !$disable ? (double) apply_filters('shopp_product_variant_price', Shopp::str_true($pricing->sale) ? $pricing->promoprice : $currently) : false;
                $_->i = Shopp::str_true($pricing->inventory);
                $_->s = $_->i ? (int) $pricing->stock : false;
                $_->u = $pricing->sku;
                $_->tax = Shopp::str_true($pricing->tax);
                $_->t = $pricing->type;
                $_->r = $pricing->promoprice != $pricing->price ? money($pricing->price) : false;
                $_->d = $discount > 0 ? $discount : false;
                $pricekeys[$key] = $_;
            }
            // Output a JSON object for JS manipulation
            if ('json' == $options['mode']) {
                return json_encode($pricekeys);
            }
            $jsoptions = array('prices' => $pricekeys, 'format' => $format);
            if ('hide' == $options['disabled']) {
                $jsoptions['disabled'] = false;
            }
            if ('hide' == $options['pricetags']) {
                $jsoptions['pricetags'] = false;
            }
            if (!empty($taxrate)) {
                $jsoptions['taxrate'] = Shopp::taxrate($O);
            }
            $select_collection = !empty($collection_class) ? '.' . $collection_class : '';
            ob_start();
            if (!empty($options['defaults'])) {
                ?>
$s.opdef = true;
<?php 
            }
            if (!empty($options['required'])) {
                ?>
$s.opreq = "<?php 
                echo $options['required'];
                ?>
";
<?php 
            }
            ?>
new ProductOptionsMenus(<?php 
            printf("'select%s.product%d.options'", $select_collection, $O->id);
            ?>
,<?php 
            echo json_encode($jsoptions);
            ?>
);
<?php 
            $script = ob_get_clean();
            add_storefrontjs($script);
            foreach ($menuoptions as $id => $menu) {
                if (!empty($before_menu)) {
                    $string .= $before_menu . "\n";
                }
                if (Shopp::str_true($label)) {
                    $string .= '<label for="options-' . esc_attr($menu['id']) . '">' . esc_html($menu['name']) . '</label> ' . "\n";
                }
                $string .= '<select name="products[' . (int) $O->id . '][options][]" class="' . esc_attr($collection_class) . ' product' . (int) $O->id . ' options" id="options-' . esc_attr($menu['id']) . '">';
                if (!empty($defaults)) {
                    $string .= '<option value="">' . esc_html($options['defaults']) . '</option>' . "\n";
                }
                foreach ($menu['options'] as $key => $option) {
                    $string .= '<option value="' . esc_attr($option['id']) . '">' . esc_html($option['name']) . '</option>' . "\n";
                }
                $string .= '</select>';
                if (!empty($after_menu)) {
                    $string .= $after_menu . "\n";
                }
            }
        }
        return $string;
    }
コード例 #3
0
ファイル: product.php プロジェクト: forthrobot/inuvik
/**
 * shopp_product_variant_set_price - set the price of a variant
 *
 * @api
 * @since 1.2
 *
 * @param int/Price $variant (required) The priceline id to set the price on, or the Price object to change.  If Price object is specified, the object will be returned, but not saved to the database.
 * @param float $price the price to be set
 * @param string $context (optional default:variant) enforces the priceline is a 'product','variant', or 'addon'
 * @return bool/Price false on failure, true if Price saved, else the modified Price object.
 **/
function shopp_product_variant_set_price($variant = false, $price = 0.0, $context = 'variant')
{
    $context = 'variant' == $context ? 'variation' : $context;
    $save = true;
    if (is_object($variant) && is_a($variant, 'ShoppPrice')) {
        $Price = $variant;
        $save = false;
    } else {
        if (false == $variant) {
            shopp_debug(__FUNCTION__ . " failed: Variant id required.");
            return false;
        }
        $Price = new ShoppPrice($variant);
        if (empty($Price->id) || $Price->context != $context) {
            shopp_debug(__FUNCTION__ . " failed: No such {$context} with id {$variant}.");
        }
    }
    if (shopp_setting_enabled('tax_inclusive') && isset($Price->tax) && Shopp::str_true($Price->tax)) {
        $Product = new ShoppProduct($Price->product);
        $taxrate = Shopp::taxrate($Product);
        $price = Shopp::floatval($price / (1 + $taxrate));
    }
    $Price->price = $price;
    if ($save) {
        return $Price->save();
    }
    return $Price;
}