Note: This article applies to the PHP Toolkit before version 2012.2.
This Article outlines a sample for performing an add using the PHPToolkit using the item record and specifying a pricing matrix with multiple currencies.
Note: This article requires existing knowledge of Web Services and PHP.
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
/* Set up your pricing matrix into an array containing the following items in order:
* -Currency Internal ID(From Lists > Accounting > Currencies)
* -Price Level Internal ID (From Setup > Accounting > Accounting Lists)
* -Price
* -Quantity
*/
$myPricingMatrix = array(
array(1, 1, "20.00", "0"), // USA Currency (Internal ID '1') Start
array(1, 2, "18.00", "0"),
array(1, 3, "16.00", "0"),
array(1, 4, "14.00", "0"),
array(1, 5, "12.00", "0"),
array(1, 1, "18.00", "10"), // Quantity 10 pricing start
array(1, 2, "16.00", "10"),
array(1, 3, "14.00", "10"),
array(1, 4, "12.00", "10"),
array(1, 5, "10.00", "10"), // USA Currency End, Quantity 10 pricing end
array(2, 1, "10.00", "0"), // British Pound Currency (Internal ID '2') Start
array(2, 2, "8.00", "0"),
array(2, 3, "6.00", "0"),
array(2, 4, "4.00", "0"),
array(2, 5, "2.00", "0"),
array(2, 1, "9.00", "10"), // Quantity 10 pricing start
array(2, 2, "7.00", "10"),
array(2, 3, "5.00", "10"),
array(2, 4, "3.00", "10"),
array(2, 5, "1.00", "10") // British Pound Currency End
);
//Loop through the pricing matrix to create pricing array
foreach ( $myPricingMatrix as $myLoop)
{
$pricing[] = array (
"currency" => new nsRecordRef(array('internalId' => $myLoop[0])),
"priceLevel" => new nsRecordRef(array('internalId' => $myLoop[1])),
"priceList" => array (
"price" => array (
array (
"value" => $myLoop[2],
"quantity" => $myLoop[3]
)
)
)
);
};
// Create array of fields
$newItem = array (
"itemId" => "My Item Name",
"pricingMatrix" => array ("pricing" => $pricing)
);
// create Item record
$myItem = new nsComplexObject('InventoryItem');
// Set fields
$myItem->setFields($newItem);
// Perform add operation
$addResponse = $myNSclient->add($myItem);
// Handle add response
if (!$addResponse->isSuccess) {
echo $addResponse->statusDetail[0]->message;
}
else {
echo "Record internal Id is" . $addResponse->recordRef->nsComplexObject_fields['internalId'];
}
require_once 'login_info.php';
global $myNSclient;
/* Set up your pricing matrix into an array containing the following items in order:
* -Currency Internal ID(From Lists > Accounting > Currencies)
* -Price Level Internal ID (From Setup > Accounting > Accounting Lists)
* -Price
* -Quantity
*/
$myPricingMatrix = array(
array(1, 1, "20.00", "0"), // USA Currency (Internal ID '1') Start
array(1, 2, "18.00", "0"),
array(1, 3, "16.00", "0"),
array(1, 4, "14.00", "0"),
array(1, 5, "12.00", "0"),
array(1, 1, "18.00", "10"), // Quantity 10 pricing start
array(1, 2, "16.00", "10"),
array(1, 3, "14.00", "10"),
array(1, 4, "12.00", "10"),
array(1, 5, "10.00", "10"), // USA Currency End, Quantity 10 pricing end
array(2, 1, "10.00", "0"), // British Pound Currency (Internal ID '2') Start
array(2, 2, "8.00", "0"),
array(2, 3, "6.00", "0"),
array(2, 4, "4.00", "0"),
array(2, 5, "2.00", "0"),
array(2, 1, "9.00", "10"), // Quantity 10 pricing start
array(2, 2, "7.00", "10"),
array(2, 3, "5.00", "10"),
array(2, 4, "3.00", "10"),
array(2, 5, "1.00", "10") // British Pound Currency End
);
//Loop through the pricing matrix to create pricing array
foreach ( $myPricingMatrix as $myLoop)
{
$pricing[] = array (
"currency" => new nsRecordRef(array('internalId' => $myLoop[0])),
"priceLevel" => new nsRecordRef(array('internalId' => $myLoop[1])),
"priceList" => array (
"price" => array (
array (
"value" => $myLoop[2],
"quantity" => $myLoop[3]
)
)
)
);
};
// Create array of fields
$newItem = array (
"itemId" => "My Item Name",
"pricingMatrix" => array ("pricing" => $pricing)
);
// create Item record
$myItem = new nsComplexObject('InventoryItem');
// Set fields
$myItem->setFields($newItem);
// Perform add operation
$addResponse = $myNSclient->add($myItem);
// Handle add response
if (!$addResponse->isSuccess) {
echo $addResponse->statusDetail[0]->message;
}
else {
echo "Record internal Id is" . $addResponse->recordRef->nsComplexObject_fields['internalId'];
}
The above would create a pricing matrix as follows in the newly created item record:
USA
Price Level Qty 0 Qty 10
Base Price 20.00 18.00
Corporate Discount Price 18.00 16.00
Employee Price 16.00 14.00
Alternate Price 14.00 12.00
Online Price 12.00 10.00
British pound
Price Level Qty 0 Qty 10
Base Price 10.00 9.00
Corporate Discount Price 8.00 7.00
Employee Price 6.00 5.00
Alternate Price 4.00 3.00
Online Price 2.00 1.00
Price Level Qty 0 Qty 10
Base Price 20.00 18.00
Corporate Discount Price 18.00 16.00
Employee Price 16.00 14.00
Alternate Price 14.00 12.00
Online Price 12.00 10.00
British pound
Price Level Qty 0 Qty 10
Base Price 10.00 9.00
Corporate Discount Price 8.00 7.00
Employee Price 6.00 5.00
Alternate Price 4.00 3.00
Online Price 2.00 1.00
No comments:
Post a Comment