Share » Forums » General » ezPublish WebShop Inventory Tracking?

ezPublish WebShop Inventory Tracking?

ezPublish WebShop Inventory Tracking?

Tuesday 19 February 2008 3:31:48 pm - 3 replies

Author Message

Pascal Specht

Wednesday 20 February 2008 1:05:35 am

Hi Trent,

this isn't a built-in feature. But it isn't too much work to do:

add an attribute called quantity (integer) to your product class, and use some code like this one whenever an order has been acknowledged:

function updateQuantities($order)
{
	$productCollection = $order->productCollection();
	$orderedItems = $productCollection->itemList();
	foreach ($orderedItems as $item)
	{
		$contentObject = $item->contentObject();
		$contentObjectVersion =& $contentObject->version($contentObject->attribute('current_version'));
		$contentObjectAttributes =& $contentObjectVersion->contentObjectAttributes();

		// iterate over the attributes
		foreach (array_keys($contentObjectAttributes) as $key)
		{
			$contentObjectAttribute =& $contentObjectAttributes[$key];
			$contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
			$attributeIdentifier = $contentClassAttribute->attribute("identifier");

			if ($attributeIdentifier == "quantity")
			{
				$newQuantity = $contentObjectAttribute->attribute("value") - $item->ItemCount;

				$contentObjectAttribute->fromString($newQuantity);
				$contentObjectAttribute->store();
			}
		}
	}
}

 

Hope this helps,
</Pascal>

Trent Jurewicz

Wednesday 20 February 2008 9:46:50 am

Thank you for the reply Pascal! Please forgive my noob question, but is the sample code you provided ez template or PHP code?

Thanks!

Pascal Specht

Thursday 21 February 2008 12:26:51 am

Hi Trent,

the code snipped is PHP, and would have to be placed somewhere in a workflow that gets triggered when the purchase is done, typically in the payment gateway, for instance.

</Pascal>

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu