shopp_product_set_variant()

used to configure a variant, addon, or single product priceline object.

shopp_product_set_variant ( $variant, $data, $context )

@param int|Price $variant (required) Either the id of the variant/addon/product price line, or the Price object. If passed a Price object, the modified object is returned, but not saved.
@param array $data (required) the data array used to configure the variant. See example below.
@param string $context (optional default:variant) set product, addon, or variant context
@return bool|Price false on failure, resulting Price object on success.

Description

Used to configure a variant, addon, or single product priceline object.

Examples

Shipped Variation

$data = array();

// Setup the price type, can be:
// Shipped
// Virtual
// Download
// Donation
// Subscription
// N/A (N/A for Disabled)
$data['type'] = 'Shipped';

// Price should be taxed?
// on to allow tax on price
// off to disallow tax
$data['taxed'] = 'on';

// Setup the regular price
// The price is a php float number, not a string.
// Include taxes if 'Inclusive Taxes' is enabled.
$data['price'] = 10.00;

// Setup the sale price
// sale is an associative array.
$data['sale'] = array();
// Set the flag to true to enable sale, otherwise false
// sale price not needed if flag is false
$data['sale']['flag'] = true;
// Set the sale price, tax exclusive float figure as with price
$data['sale']['price'] = 8.00;

// Configure shipping settings (only if Shipped type)
// shipping is an associative array
$data['shipping'] = array();
// Set flag to true to enable shipping fee calculation on product
$data['shipping']['flag'] = true;
// Set an extra shipping and handling fee (optional)
// fee is tax exclusive float figure
$data['shipping']['fee'] = 1.00;
// Set the weight, height, width, and length
// All are float number figures
$data['shipping']['weight'] = 1.0;
$data['shipping']['height'] = 10.0;
$data['shipping']['width'] = 10.0;
$data['shipping']['length'] = 10.0;

// Configure inventory/stock settings
// inventory is an associative array
$data['inventory'] = array();
// Set inventory tracking on or off
// flag true for on, false for off
$data['inventory']['flag'] = true;
// Set the integer stock level
$data['inventory']['stock'] = 10;
// Set the SKU (Stock Keeping Unit)
$data['inventory']['sku'] = 'PR-1';

// Lookup variant by product id and option set
// Product 130 is a Jacket with sizes and color variants
$option = array('Size'=>'medium', 'Color'=>'Navy Baby Solid');
$Variant = shopp_product_variant(array('product'=>130, 'option'=>$option), 'variant');

// Configure the Variant
shopp_product_set_variant ( $Variant->id, $data, 'variant' );

Download Product

$data = array();

// Set type
$data['type'] = 'Download';

// Set taxed
$data['taxed'] = 'off';

// Set price
$data['price'] = 10.00;

// Set sale
$data['sale'] = array();
$data['sale']['flag'] = true;
$data['sale']['price'] = 8.00;

// Product 101 is a music download product with no variations
$Variant = shopp_product_variant(array('product'=>101), 'product');

// Configure the Variant
// Pass the id to have shopp_product_set_variant save for you,
// the object if you need to save yourself.
shopp_product_set_variant ( $Variant, $data, 'product' );
$Variant->save();

Donation Product

$data = array();

// Set type
$data['type'] = 'Donation';

// Set taxed
$data['taxed'] = 'off';

// Set default donation price
$data['price'] = 10.00;

// Set donation settings
// donation is an associative array
$data['donation'] = array();
// set variable to true if donation amount can be set by the donor
// false if the above price is a set donation amount
$data['donation']['variable'] = true;
// set minimum to true for variable donation to force the 
// above price to be the minimum allowed donation.
$data['donation']['minimum'] = true;

// Product 1 is your donation product
$Variant = shopp_product_variant(array('product'=>1), 'product');

// Configure the Variant
shopp_product_set_variant ( $Variant->id, $data, 'product' );

Subscription Product

Some payment methods do not support subscriptions. Ensure that your Shopp payment gateway addon supports the feature you are trying to implement.

Check the payment addons documentation, and assume that subscription support is not available if it isn’t mentioned specifically. Contact support if you have any questions.

$data = 
array(
    'type' => "Subscription",
    'taxed' => 'on',
    'price' => 15.99,
    'sale' => array('flag'=>true, 'price'=>9.99)    
);

// Subscription settings
// subscription is an associative array
$data['subscription'] = array();

// Trial period settings
// If the subscription has a trial period.
// Not all payment methods will allow a trial period.
// Check the payment addon documentation to be sure.

// Here's how to set a 30 day trial for $4.99
// Remember there will be one price for introductory period, not recurring.

// trial is an associative array
$data['subscription']['trial'] = array();
// Set a special price for the trial, useful for an introductory price
// price is a float value
$data['subscription']['trial']['price'] = 4.99;
// Set the trial period cycle, as an associative array
$data['subscription']['trial']['cycle'] = array();

// Set the trial interval unit. How many time units will it last?
$data['subscription']['trial']['cycle']['interval'] = 30;
// Set the trial time period
// d for days, w for weeks, m for months, y for years
$data['subscription']['trial']['cycle']['period'] = 'd';

// Recurring payment (billcycle) settings
// Here is an example of monthly billing for one year:
// Each cycle is 1 month and there are 12 cycles

// billcycle is an associative array
$data['subscription']['billcycle'] = array();
// Set how many billing cycles the recurrence will last
// cycles is an integer (0 for ongoing without limit)
$data['subscription']['billcycle']['cycles'] = 12;

// Set the billing cycle interval and period
// cycle is an associative array
$data['subscription']['billcycle']['cycle'] = array();
// Set the cycle interval unit. How many time units will it last?
$data['subscription']['billcycle']['cycle']['interval'] = 1;
// Set the cycle time period
// d for days, w for weeks, m for months, y for years
$data['subscription']['billcycle']['cycle']['period'] = 'm';

// Product 99 is a magazine product with billing period variations
$Variant = shopp_product_variant(array('product'=>99, 'option' => array('Billing'=>'Monthly')), 'product');

// Configure the Variant
shopp_product_set_variant ( $Variant->id, $data, 'variant' );

// Now for the cheaper annual up-front price
$data = 
array(
    'type' => "Subscription",
    'taxed' => 'on',
    'price' => 149.99,
    'sale' => array('flag'=>true, 'price'=>99.99),
    'subcription' =>
    array(
        'billcycle' =>
        array(
            'cycles'=>0, // forever
            'cycle'=>
            array(
                'interval'=>1,
                'period'=>'y'
            )
        )
    )   
);

$Variant = shopp_product_variant(array('product'=>99, 'option' => array('Billing'=>'Annual')), 'product');

// Configure the Variant
shopp_product_set_variant ( $Variant->id, $data, 'variant' );

See Also

You must be logged in to post a comment.

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

Skip to toolbar