shopp_product_variant_to_item()

convert a variant Price object to an Item object

shopp_product_variant_to_item ( $Variant, $quantity )

@param Price $Variant a product or variant Price object to create the item from.
@param int $quantity (optional default:1) quantity of the variant the Item object will represent
@return Item|bool Item object on success, false on failure

Description

convert a variant Price object to an Item object

It is sometimes necessary to use/manipulate an Item object from a product or product variant, without needing to add the item to the cart.

Examples

product variant Price object to Item object

// Get the Variant object for My Album product
// This album has track variants, selecting the '02 My Favorite Song' option.
$option = array( 'Track' => '02 My Favorite Song' );
$Track2 = 
    shopp_product_variant(
        array(
            'product' => shopp_product( 'My Album', 'name' )->id,
            'option' => $option,
        ),
        'variant'
    );

// convert the product variant Price object to an Item object
$Item = shopp_product_variant_to_item ( $Track2 );

non-variant product Price object to Item object

// Get the single Price object associated with product 15
$ProductPrice = shopp_product_variant( 
    array( 'product' => 15 ),
    'product'
);

// convert the product Price to an Item object
// specify quantity 2
$Item = shopp_product_variant_to_item ( $ProductPrice, 2 );

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar