Forums / Developer / How to manage Quantity/stock/inventory?

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();
}
}
}

eZ debug

Timing: Jan 18 2025 20:57:13
Script start
Timing: Jan 18 2025 20:57:13
Module start 'content'
Timing: Jan 18 2025 20:57:13
Module end 'content'
Timing: Jan 18 2025 20:57:13
Script end

Main resources:

Total runtime0.1483 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.8125180.8281
Module start 'content' 0.00560.0058 768.6406101.8828
Module end 'content' 0.01140.1368 870.5234529.8281
Script end 0.1482  1,400.3516 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00342.2625200.0002
Check MTime0.00130.8750200.0001
Mysql Total
Database connection0.00070.449810.0007
Mysqli_queries0.106771.92891410.0008
Looping result0.00130.88131390.0000
Template Total0.136492.010.1364
Template load0.00090.619810.0009
Template processing0.135591.356310.1355
Override
Cache load0.00060.419410.0006
Sytem overhead
Fetch class attribute can translate value0.00110.722210.0011
XML
Image XML parsing0.00030.206410.0003
General
dbfile0.00392.6456200.0002
String conversion0.00000.004230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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