Adds or updates Option Matrix record in the database.
The
$options parameter should contain data values to assign to the record, as an associative array.
Below is a full list of supported fields:
- disabled - determines whether the record is disabled. String value, accepts yes and no values.
- sku - specifies the product SKU.
- images - an array of absolute paths to image files.
- base_price - specifies the base price of the record.
- tier_price - an array of tier prices in the following format: [['group_id'=>10, 'quantity'=>4, 'price'=>10], ...]. Use NULL for group_id element to indicate "Any customer group".
- cost - specifies the product cost.
- on_sale - determines whether the product is on sale.
- sale_price_or_discount - specifies the sale price or discount in the following format: 10, -10, 10%.
- in_stock - specifies the number of items in stock.
- expected_availability_date - specifies the expected availability date in format YYYY-MM-DD.
- allow_pre_order - indicates whether pre-ordering is allowed.
- weight - specifies the product weight.
- width - specifies the product width.
- height - specifies the product height.
- depth - specifies the product depth.
- API columns - any columns added with shop:onExtendOptionMatrix event.
The method returns an object with the following fields:
- status - OK, SKIPPED or OK-WITH-WARNINGS string value.
- operation - ADD or UPDATE string value.
- warnings - an array of warnings.
- id - identifier of the added/updated record.
The method throws an exception if the operation cannot be executed.
Usage example:
$manager = new Shop_OptionMatrixManager();
$options = array(
'Color'=>'Red',
'Size'=>'Large'
);
$data = array(
'disabled'=>'no',
'sku'=>'red-large',
'images'=>array(PATH_APP.'/temp/images/red-1.jpg', PATH_APP.'/temp/images/red-2.jpg'),
'base_price'=>50,
'cost'=>10,
'on_sale'=>true,
'allow_pre_order'=>true,
'sale_price_or_discount'=>'10%',
'in_stock'=>32,
'expected_availability_date'=>'2012-05-29',
'weight'=>50,
'width'=>12,
'height'=>13,
'depth'=>14
);
$status = $manager->add_or_update($test_product, $options, $data);
Returns data field values for Option Matrix record identified with product options and product.
Creates the Option Matrix Manager class instance.