shopp_product_variant_set_type()

sets the product type of a product/variant/addon.

shopp_product_variant_set_type ( $variant, $type, $context )

@param int/Price $variant (required) The priceline id to set the type on, or the Price object to change.  If Price object is specified, the object will be returned, but not saved to the database.
@param string $type (optional default:N/A) The product price type, ex Shipped, Download, Virtual, Subscription.  N/A is a disabled priceline.
@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.

Description

This function sets the product type of a product/variant/addon.

Default Product Types
* Shipped – the product, product variant, or addon is shipped.
* Download – the product, product variant, or addon is a digital download.
* Virtual – the product, product variant, or addon is non-tangible.
* Subscription – the product, product variant, or addon is a type of subscription, with recurring payment.
* N/A – the product, product variant, or addon is disabled.

Example

// Adding a stub product
$data = array(
    'name' => "Music Album",
    'single' => array(),
    'publish' => array( 'flag' => true ),
    'description' =>
        "My Music Track"
);
$Product = shopp_add_product($data);

// get the Price object for the product (the product has no variants)
$Pricetag = shopp_product_variant( array( 'product'=>$Product->id ), 'product' );

// set the product type to Download
shopp_product_variant_set_type($Pricetag->id, 'Download', 'product');

// Setup some addon options for this product
$options = array(
    'Bonus' => array('Call from Artist', 'Magazine Subscription')
);
shopp_product_set_addon_options ( $Product->id, $options, 'save' );

// Say we have a premium intangible addon
// such as a personal telephone call from the music artist.
// We set the product type to Virtual
$Call = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option' => 
        array(
            'Bonus'=>'Call from Artist'
        )
    ), 'addon'
);
shopp_product_variant_set_type($Call->id, 'Virtual', 'addon');

// Another addon to the music download could
// a magazine subscription.
$Mag = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option' => 
        array(
            'Bonus'=>'Magazine Subscription'
        )
    ), 'addon'
);
shopp_product_variant_set_type($Mag->id, 'Subscription', 'addon');

See Also

You must be logged in to post a comment.

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

Skip to toolbar