Acces option fields

Author Message

Albert Hornos

Tuesday 10 May 2005 3:30:53 am

Hi, another time!
I've another problem (what new!!) I extend datatype ezoption and I include a field quantity to manage the stock for each option. Now I want decrease this stock when the costumer confirm the order.
Ok, I can do it if I put an integer like attribute of product, but I can't do it if the quantity is a field of an option because I don't know how could I access to change this field in the option.
This is my code now and I put ????????????? at the space that I don't know how to do.

Thanks!!!

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 )
{
$ini =& eZINI::instance( 'workflow.ini' );

$cost = $ini->variable( "SimpleShippingWorkflow", "ShippingCost" );
$description = $ini->variable( "SimpleShippingWorkflow", "ShippingDescription" );

$parameters = $process->attribute( 'parameter_list' );
$orderID = $parameters['order_id'];

$order =& eZOrder::fetch( $orderID );

// Here start de stock's decrease
$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();
$contentClassAttributeID = $contentClassAttribute->attribute('id' );
$contentClassAttributeVersion = $contentClassAttribute->attribute('version' );
// Each attribute has an attribute called 'name' that identifies it.
echo ($contentClassAttribute->attribute("name"));
if ($contentClassAttribute->attribute("name") == "cantidad"){
$contentObjectAttribute->setAttribute("data_int", (($contentObjectAttribute->attribute("value"))-1));
$contentObjectAttribute->store();
}
if ($contentClassAttribute->attribute("name") == "opcion"){????????????????????????????????????????}
}
}
//Here finish the decrease

$orderItems = $order->attribute( 'order_items' );
$addShipping = true;

foreach ( array_keys( $orderItems ) as $key )
{
$orderItem =& $orderItems[$key];
if ( $orderItem->attribute( 'description' ) == $description )
{
$addShipping = false;
break;
}
}
if ( $addShipping )
{
$orderItem = new eZOrderItem( array( 'order_id' => $orderID,
'description' => $description,
'price' => $cost,
'vat_is_included' => true,
'vat_type_id' => 1 )
);
$orderItem->store();
}
return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
}
}

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

?>

Joe Lancros

Thursday 08 April 2010 7:02:11 am

Hey Albert,

I have a similar problem to yours. Did you ever find a way of decreasing the stock for a specific product option?

Joe

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 31 2025 04:23:00
Script start
Timing: Jan 31 2025 04:23:00
Module start 'layout'
Timing: Jan 31 2025 04:23:00
Module start 'content'
Timing: Jan 31 2025 04:23:01
Module end 'content'
Timing: Jan 31 2025 04:23:01
Script end

Main resources:

Total runtime0.9359 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.0313151.1953
Module start 'layout' 0.00560.0023 739.226636.6172
Module start 'content' 0.00790.9272 775.8438901.7734
Module end 'content' 0.93510.0008 1,677.617211.8750
Script end 0.9359  1,689.4922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3413160.0002
Check MTime0.00130.1402160.0001
Mysql Total
Database connection0.00080.089310.0008
Mysqli_queries0.877993.8011540.0163
Looping result0.00050.0529520.0000
Template Total0.903096.520.4515
Template load0.00210.220420.0010
Template processing0.901096.262220.4505
Template load and register function0.00120.130010.0012
states
state_id_array0.00100.105310.0010
state_identifier_array0.00150.159220.0007
Override
Cache load0.00180.1946730.0000
Sytem overhead
Fetch class attribute can translate value0.00060.061020.0003
Fetch class attribute name0.00260.276620.0013
XML
Image XML parsing0.00020.025920.0001
class_abstraction
Instantiating content class attribute0.00000.000620.0000
General
dbfile0.00270.2871100.0003
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs