/** * Save uploaded file and set its name to entity * * @param Goodahead_Etm_Model_Entity $object * @return void */ public function afterSave($object) { parent::afterSave($object); $value = $object->getData($this->getAttribute()->getName()); if (is_array($value) && !empty($value['delete'])) { $object->setData($this->getAttribute()->getName(), ''); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); return $this; } $path = Mage::getBaseDir('media') . DS . 'goodahead' . DS . 'etm' . DS . 'images' . DS . $object->getEntityTypeInstance()->getEntityTypeCode() . DS . $this->getAttribute()->getAttributeCode() . DS; try { $uploader = new Varien_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setAllowCreateFolders(true); $uploader->setFilesDispersion(true); $uploader->save($path); $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } catch (Exception $e) { if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) { Mage::logException($e); } /** @TODO ??? */ return $this; } return $this; }
public function afterSave($object) { parent::afterSave($object); $object->getItemsCollection()->save(); $object->getShippingRatesCollection()->save(); return $this; }
public function afterSave($object) { parent::afterSave($object); $object->getAddressesCollection()->save(); $object->getItemsCollection()->save(); $object->getPaymentsCollection()->save(); return $this; }
/** * Explode the saved array again, because otherwise the indexer will think the value changed, * even if it is the same (array(1,2,3) !== "1,2,3"). * * @param Mage_Core_Model_Abstract $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function afterSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); if (is_string($data)) { $object->setData($attributeCode, explode(',', $data)); } return parent::afterSave($object); }
public function afterSave($object) { parent::afterSave($object); /** * Save creditmemo items */ foreach ($object->getAllItems() as $item) { $item->save(); } foreach ($object->getCommentsCollection() as $comment) { $comment->save(); } return $this; }
/** * Method is invoked after save * * @param Varien_Object $object * @return Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Parent */ public function afterSave($object) { parent::afterSave($object); /** * Save invoice items */ foreach ($object->getAllItems() as $item) { $item->setOrderItem($item->getOrderItem()); $item->save(); } foreach ($object->getCommentsCollection() as $comment) { $comment->save(); } return $this; }
/** * Performed after data is saved * * @param Varien_Object $object * @return Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Parent */ public function afterSave($object) { parent::afterSave($object); /** * Save Shipment items */ foreach ($object->getAllItems() as $item) { $item->save(); } /** * Save Shipment tracks */ foreach ($object->getAllTracks() as $track) { $track->save(); } foreach ($object->getCommentsCollection() as $comment) { $comment->save(); } return $this; }
/** * Perform operation after save * * @param Varien_Object $object * @return Mage_Sales_Model_Resource_Order_Attribute_Backend_Parent */ public function afterSave($object) { parent::afterSave($object); foreach ($object->getAddressesCollection() as $item) { $item->save(); } foreach ($object->getItemsCollection() as $item) { $item->save(); } foreach ($object->getPaymentsCollection() as $item) { $item->save(); } foreach ($object->getStatusHistoryCollection() as $item) { $item->save(); } foreach ($object->getRelatedObjects() as $object) { $object->save(); } return $this; }
/** * Unserialize after saving * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized */ public function afterSave($object) { parent::afterSave($object); $this->_unserialize($object); return $this; }
public function afterSave($object) { $storeId = $object->getStoreId(); $attributeId = $this->getAttribute()->getId(); $entityId = $object->getId(); $entityIdField = $this->getEntityIdField(); $entityTypeId = $this->getAttribute()->getEntity()->getTypeId(); $connection = $this->getConnection('write'); $values = $object->getData($this->getAttribute()->getName()); if (isset($values['position'])) { foreach ((array) $values['position'] as $valueId => $position) { if ($valueId >= 0) { $condition = array($connection->quoteInto('value_id = ?', $valueId)); $data = array(); $data['position'] = $position; $connection->update($this->getTable(), $data, $condition); $valueIds[$valueId] = $valueId; } else { $data = array(); $data[$entityIdField] = $entityId; $data['attribute_id'] = $attributeId; $data['store_id'] = $storeId; $data['position'] = $position; $data['entity_type_id'] = $entityTypeId; $connection->insert($this->getTable(), $data); $valueIds[$valueId] = $connection->lastInsertId(); } unset($uploadedFileName); $types = $this->getImageTypes(); foreach ($types as $type) { try { $uploader = new Varien_File_Uploader($this->getAttribute()->getName() . '_' . $type . '[' . $valueId . ']'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); } catch (Exception $e) { continue; } if ($this->getAttribute()->getEntity()->getStoreId() == 0) { $path = Mage::app()->getStore()->getConfig('system/filesystem/upload'); } else { $path = $this->getAttribute()->getEntity()->getStore()->getConfig('system/filesystem/upload'); } $uploader->save($path . '/' . $type . '/', 'image_' . $entityId . '_' . $valueIds[$valueId] . '.' . 'jpg'); if (!isset($uploadedFileName)) { $uploadedFileName = $uploader->getUploadedFileName(); } } if (isset($uploadedFileName)) { $condition = array($connection->quoteInto('value_id = ?', $valueIds[$valueId])); $data = array(); $data['value'] = $uploadedFileName; $connection->update($this->getTable(), $data, $condition); } else { if ($valueId < 0) { $values['delete'][] = $valueIds[$valueId]; } } } } if (isset($values['delete'])) { foreach ((array) $values['delete'] as $valueId) { if ($valueId != '') { $condition = array($connection->quoteInto('value_id = ?', $valueId)); $connection->delete($this->getTable(), $condition); } } } return parent::afterSave($object); }
/** * Always update the related products after save. * * @param Varien_Object $object Object Model * @return FireGento_DynamicCategory_Model_Entity_Attribute_Backend_Rule Self. */ public function afterSave($object) { $object->setIsChangedProductList(true); return parent::afterSave($object); }