shopp_product_set_addon()

configure a product addon.

shopp_product_set_addon ( $addon, $data )

@param int|Price $addon (required) addon id or Price object of addon
@param array $data (required) configuration data array for addon priceline
@return bool|Price false on failure, resulting Price object on success.

Description

configure a product addon.

This function uses shopp_product_set_variant().

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 addon by product id and option
// Product 130 is a Leather Case
$option = array('Accessories'=>'Leather Case');
$Addon = shopp_product_variant(array('product'=>130, 'option'=>$option), 'addon');

// Configure the Addon
shopp_product_set_addon ( $Addon->id, $data );

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 photography package, with a digital proof download addon
$Addon = shopp_product_variant(array('product'=>101
    'option'=>
    array(
        'Proofs' => 'Download Proofs'
    )
    ), 'addon');

// Configure the Addon
shopp_product_set_addon ( $Addon->id, $data );

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 a product you are selling to help fund a non-profit organization
// There is a donation addon for the product
$Addon = 
shopp_product_variant(
    array(
        'product'=> 1,
        'option' => array(
            'Other Ways to Help' => 'Donate'
        )
    ), 

    'addon'
);

// Configure the Addon
shopp_product_set_addon ( $Addon->id, $data );

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 video game with an addon magazine subscription with billing period variations
$Addon = 
shopp_product_variant(
    array(
        'product'=>99, 
        'option' => array(
            'Magazine Subscription'=>'Game Tips Weekly'
            )
    ),

    'addon'
);

// Configure the Addon
shopp_product_set_addon ( $Addon->id, $data );

See Also

You must be logged in to post a comment.

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

Skip to toolbar