ezPublish WebShop Inventory Tracking?

Author Message

Trent Jurewicz

Tuesday 19 February 2008 3:31:48 pm

I am looking to see how inventory can be tracked in the ezPublish WebShop. I'm sure somebody has needed this before. Is it always a custom development? Is there a plugin or add-on? Any information you can offer is appreciated.

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>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.