سؤال

When you save your multiple Model Object object then I want to provide Transaction. How can I achieve in magento?

Any one Please Guide Me?

هل كانت مفيدة؟

المحلول

I hope I understood correctly your question.
If you want to save X objects at once and roll back all of them in case something goes wrong try this.

$transaction = Mage::getModel('core/resource_transaction');
$transaction->addObject($obj1);
$transaction->addObject($obj2);
...
$transaction->addObject($objX);

$transaction->save();

This will call ->save() for each object you added using addObject but everything will be done inside a transaction.

نصائح أخرى

Have a look e.g. into \Mage_Eav_Model_Entity_Abstract::saveAttribute

public function saveAttribute(Varien_Object $object, $attributeCode)
{
    // ...
    $adapter        = $this->_getWriteAdapter();
    // ...
    $adapter->beginTransaction();

    try {
        // ...
        $adapter->commit();
    } catch (Exception $e) {
        $adapter->rollback();
        throw $e;
    }

    return $this;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top