Forums / Developer / Acces option fields

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