shopp_product_set_addon_options()

creates a complete set of addon product options on a specified product.

shopp_product_set_addon_options ( $product, $options, $summary )

@param int $product (required) The product id of the product that you wish to add the addon options to.
@param array $options (required) A two dimensional array describing the addon options.
@param string $summary (optional default:save) when 'save', will cause the product summary to be updated, otherwise the prices will be added to the database, but the product summary data will not be updated.
@return array addon Price objects that have been created on the product.

Description

Creates a complete set of addon product options on a specified product, by letting you specify the set of options types, and corresponding options. This function will create new addon options in the database and will attach them to the specified product.

Example

// Create a stub product
$data = array(
    'name' => "Motorcycle",
    'publish' => array( 'flag' => true ),
    'description' =>
        "Testing shopp_product_set_addon_options"
);
$Product = shopp_add_product($data);

// Structure 2 menus for 5 different addons
$options = array(
    'Accessories' => array('Helmet', 'Decals', 'Plate Mount'),
    'Apparel' => array('T-Shirt', 'Chaps')
);

// Create the addon options within the product
shopp_product_set_addon_options ( $Product->id, $options, 'save' );

// How to get the individual Price objects for these addons
$Helmet = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option'=>array('Accessories'=>'Helmet')
        ), 'addon'
    );

$Decals = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option'=>array('Accessories'=>'Decals')
        ), 'addon'
    );

$PlateMount = shopp_product_variant(
    array(
        'product'=>$Product->id, 
        'option'=>array('Accessories'=>'Plate Mount')
    ), 'addon'
);

$TShirt = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option'=>array('Apparel'=>'T-Shirt')
    ), 'addon'
);

$Chaps = shopp_product_variant(
    array(
        'product'=>$Product->id,
        'option'=>array('Apparel'=>'Chaps')
    ), '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