How to manage Quantity/stock/inventory?

Author Message

Albert Hornos

Friday 29 April 2005 9:54:40 am

I need to manage the quantity of my products and I add "quantity" attribute to my "product". How can I decresse the number when someone buy this product?

Thanks!!!

Eirik Alfstad Johansen

Saturday 30 April 2005 2:13:00 am

Hi Albert,

Create an event that takes the most recent order, goes through each of the order items, and decreases the quantity accordingly.

Then, put this event into a workflow run at shop|confirmorder|after.

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Albert Hornos

Monday 02 May 2005 9:11:02 am

Thanks you very much, but how can I edit the event, and what type of event I should take? Easy buy event perhaps?

Thanks another time.

Xavier Dutoit

Monday 02 May 2005 10:19:28 am

Hi Albert,

The easiest may be to start from an existing event already dealing with orders and items.

http://www.ez.no/community/contribs/workflow/extension_shopsender_pubsvn

Study it, it's going to guide you.

Good luck

X+

http://www.sydesy.com

Albert Hornos

Monday 02 May 2005 11:38:06 am

Thank you Xavier, but the main problem is that I don't know how can I update my "Product" attribute "Quantity" from the event. I don't know how I shoul move to take it and update it.

Thanks

Albert Hornos

Tuesday 03 May 2005 9:32:57 am

Hi another time!
I have modified ezsimpleshipping to decrement an integer (attribute quantity), this is the code but no found could anyone tell me why?
Thanks a lot!!

/*! \file ezsimpleshippingtype.php
*/

/*!
\class eZSimpleShippingType ezsimpleshippingtype.php
\brief The class eZSimpleshippingType handles adding shipping cost to an order

*/
include_once( 'kernel/classes/ezorder.php' );

define( 'EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID', 'ezsimpleshipping' );

class eZSimpleShippingType extends eZWorkflowEventType
{
/*!
Constructor
*/
function eZSimpleShippingType()
{
$this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID, ezi18n( 'kernel/workflow/event', "Simple shipping" ) );
$this->setTriggerTypes( array( 'shop' => array( 'confirmorder' => array ( 'before' ) ) ) );
}

function execute( &$process, &$event )
{
$parameters =& $process->attribute( 'parameter_list' );
$http =& eZHTTPTool::instance();

eZDebug::writeNotice( $parameters, "parameters" );
$orderID = $parameters['order_id'];
$order = eZOrder::fetch( $orderID );

if (empty($orderID) || get_class( $order ) != 'ezorder')
{
eZDebug::writeWarning( "Can't proceed without a Order ID.", "Simpleshipping" );
return EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT;
}
$productCollection = $order->productCollection();
$ordereditems = $productCollection->itemList();
foreach ($ordereditems as $item){
$co = $item->contentObject();
$coVersion =& $co->version( $co->attribute( 'current_version' ) );
$coAttributes =& $coVersion->contentObjectAttributes();
foreach (array_keys($coAttributes) as $key)
{
$coAttribute =& $coAttributes[$key];
$contentClassAttribute =& $coAttribute->contentClassAttribute();
// Each attribute has an attribute called 'name' that identifies it.
if ($contentClassAttribute->attribute("name") == "quantity")
{
$coAttribute->setAttribute("data_int", "50");
$coAttribute->store();
}
}
}
return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
}

eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_SIMPLESHIPPING_ID, "ezsimpleshippingtype" );

?>

Albert Hornos

Tuesday 03 May 2005 10:40:34 am

thanks for the help to everybody!!
I've solved the problem, I'll post the solution (perhaps someone has the same problem!)
This is only the piece of code that decrease de quantity attribute!

$order =& eZOrder::fetch( $orderID );
$productCollection = $order->productCollection();
$ordereditems = $productCollection->itemList();
foreach ($ordereditems as $item){
$contentObject = $item->contentObject();
$contentObjectVersion =& $contentObject->version($contentObject->attribute( 'current_version' ) );
$contentObjectAttributes =& $contentObjectVersion->contentObjectAttributes();
foreach (array_keys($contentObjectAttributes) as $key){
$contentObjectAttribute =& $contentObjectAttributes[$key];
$contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
// Each attribute has an attribute called 'name' that identifies it.
if ($contentClassAttribute->attribute("name") == "Quantity"){ $contentObjectAttribute->setAttribute("data_int", (($contentObjectAttribute->attribute("value"))-1));
$contentObjectAttribute->store();
}
}
}

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