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.

eZ debug

Timing: Jan 19 2025 00:26:35
Script start
Timing: Jan 19 2025 00:26:35
Module start 'layout'
Timing: Jan 19 2025 00:26:35
Module start 'content'
Timing: Jan 19 2025 00:26:35
Module end 'content'
Timing: Jan 19 2025 00:26:35
Script end

Main resources:

Total runtime0.0223 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.0313152.6406
Module start 'layout' 0.00620.0030 740.671939.4609
Module start 'content' 0.00910.0113 780.132897.3203
Module end 'content' 0.02040.0019 877.453138.3047
Script end 0.0223  915.7578 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002410.8089140.0002
Check MTime0.00114.9133140.0001
Mysql Total
Database connection0.00104.518910.0010
Mysqli_queries0.003013.493730.0010
Looping result0.00000.057710.0000
Template Total0.00146.310.0014
Template load0.00083.407410.0008
Template processing0.00062.847310.0006
Override
Cache load0.00052.343910.0005
General
dbfile0.00031.382080.0000
String conversion0.00000.035340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs