/** * Before save method * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $attributeValue = $object->getData($attributeCode); $delimiter = Glace_Menumobile_Block_Category_Attribute_Helper_Dropdown_Blocks::DELIMITER; $maxBlocks = Glace_Menumobile_Block_Category_Attribute_Helper_Dropdown_Blocks::MAX_BLOCKS; if ($attributeValue) { //To make parsing simpler, replace value with empty string if all blocks are empty $exploded = explode($delimiter, $attributeValue); $allBlocksAreEmpty = TRUE; for ($i = 0; $i < $maxBlocks; $i++) { if (isset($exploded[$i])) { if (trim($exploded[$i])) { //Block is not empty after trimming $allBlocksAreEmpty = FALSE; break; } } } if ($allBlocksAreEmpty) { $object->setData($attributeCode, ''); //Set empty value } } return parent::beforeSave($object); }
/** * Method is invoked before save * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { if ($object->getCreditmemo()) { $object->setParentId($object->getCreditmemo()->getId()); } return parent::beforeSave($object); }
public function afterSave($object) { if ($object->getOrderItem()) { $object->getOrderItem()->save(); } return parent::beforeSave($object); }
/** * Performed before data is saved * * @param Varieb_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { if ($object->getShipment()) { $object->setParentId($object->getShipment()->getId()); } return parent::beforeSave($object); }
/** * Process the attribute value before saving * * @param Mage_Core_Model_Abstract $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); $customerGroupIds = array(Netzarbeiter_GroupsCatalog2_Helper_Data::USE_DEFAULT, Netzarbeiter_GroupsCatalog2_Helper_Data::USE_NONE); $customerGroups = Mage::helper('netzarbeiter_groupscatalog2')->getGroups(); $customerGroupIds = array_merge($customerGroupIds, array_keys($customerGroups->getItems())); if (!$data) { $data = array(Netzarbeiter_GroupsCatalog2_Helper_Data::USE_DEFAULT); } if (!is_array($data)) { $data = explode(',', $data); } if (1 < count($data)) { // remove USE_DEFAULT if any other groups are selected, too $key = array_search(Netzarbeiter_GroupsCatalog2_Helper_Data::USE_DEFAULT, $data); if (false !== $key) { unset($data[$key]); } // if USE_NONE is selected remove all other groups if (in_array(Netzarbeiter_GroupsCatalog2_Helper_Data::USE_NONE, $data)) { $data = array(Netzarbeiter_GroupsCatalog2_Helper_Data::USE_NONE); } } // validate all customer groups ids are valid foreach ($data as $key => $groupId) { if (!in_array($groupId, $customerGroupIds)) { unset($data[$key]); } } // I like it nice and tidy, this gives us sequential index numbers again as a side effect :) sort($data); $object->setData($attributeCode, implode(',', $data)); return parent::beforeSave($object); }
/** * Before save method * * @param Varien_Object $object Object Model * @return FireGento_DynamicCategory_Model_Entity_Attribute_Backend_Rule Self. */ public function beforeSave($object) { parent::beforeSave($object); $attrCode = $this->getAttribute()->getAttributeCode(); $object->setData($attrCode, serialize($object->getData($attrCode))); return $this; }
public function beforeSave($object) { if ($object->getOrder()) { $object->setParentId($object->getOrder()->getId()); } parent::beforeSave($object); return $this; }
public function beforeSave($object) { if ($object->getAddress()) { $object->setParentId($object->getAddress()->getId())->setStoreId($object->getAddress()->getStoreId()); } parent::beforeSave($object); return $this; }
public function beforeSave($object) { if ($object->getOrder()) { $object->setOrderId($object->getOrder()->getId()); $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId()); } return parent::beforeSave($object); }
public function beforeSave($object) { $data = $object->getData($this->getAttribute()->getAttributeCode()); if (is_array($data)) { $object->setData($this->getAttribute()->getAttributeCode(), implode(',', $data)); } return parent::beforeSave($object); }
/** * Prepare data for save * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); if (is_array($data)) { $data = array_filter($data); $object->setData($attributeCode, implode(',', $data)); } return parent::beforeSave($object); }
/** * Prepare data for save * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); if ($data instanceof Varien_Object) { $data = get_class($data) . '|' . json_encode($data->getData()); } $object->setData($attributeCode, $data); return parent::beforeSave($object); }
/** * Encrypts the value before saving * * @param Mage_Core_Model_Abstract $object Object * @return Itabs_Debit_Model_Entity_Customer_Attribute_Backend_Encrypted */ public function beforeSave($object) { $helper = Mage::helper('core'); $attributeName = $this->getAttribute()->getName(); if ($object->getData($attributeName) != '') { $value = $helper->encrypt($object->getData($attributeName)); $object->setData($attributeName, $value); } return parent::beforeSave($object); }
/** * Prepare inventory data from custom atribute * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract|void */ public function beforeSave($object) { /** @var $object Mage_Catalog_Model_Product */ $stockData = $object->getData($this->getAttribute()->getAttributeCode()); if ($object->getStockData() !== null || $stockData !== null) { $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData)); } $object->unsetData($this->getAttribute()->getAttributeCode()); parent::beforeSave($object); }
/** * Prepare inventory data from custom attribute * * @param Mage_Catalog_Model_Product $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract|void */ public function beforeSave($object) { $stockData = $object->getData($this->getAttribute()->getAttributeCode()); if (isset($stockData['qty']) && $stockData['qty'] === '') { $stockData['qty'] = null; } if ($object->getStockData() !== null || $stockData !== null) { $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData)); } $object->unsetData($this->getAttribute()->getAttributeCode()); parent::beforeSave($object); }
public function beforeSave($object) { $attrCode = $this->getAttribute()->getAttributeCode(); if ($object->hasData($attrCode)) { $value = trim($object->getData($attrCode)); if ('' !== $value) { if (!preg_match('#^(?:http|https|ftp)://[a-z][a-z.]*\\.[a-z]+#', $value)) { throw new RuntimeException($this->getHelper()->__('Please specify a full URL including http://, https:// or ftp:// for for the attribute "%s"', $this->getAttribute()->getFrontendLabel())); //Mage::throwException($this->getHelper()->__('Please specify a full URL.')); } } } return parent::beforeSave($object); }
public function beforeSave($object) { $attributeCode = $this->getAttribute()->getName(); if ($attributeCode == self::ATTRIBUTE_CODE) { $data = $object->getData($attributeCode); $postData = Mage::app()->getRequest()->getPost('product'); if (!empty($postData) && empty($postData[$attributeCode])) { $data = array(); } if (is_array($data)) { $object->setData($attributeCode, implode(',', $data)); } } parent::beforeSave($object); }
public function beforeSave($product) { parent::beforeSave($product); /* @var $product Mage_Catalog_Model_Product */ // if ($product->getDcProductId()) // { // /* @var $childProducts Mage_Catalog_Model_Resource_Product_Collection */ // $childProducts = Mage::getModel('catalog/product')->getResourceCollection(); // $childProductsIds = array_values(current($product->getTypeInstance(true)->getChildrenIds($product->getId(), false))); // $childProducts->addIdFilter($childProductsIds); // $childProducts->load(); // foreach ($childProducts as $child) // { // $child->load($child->getId()); // $child->setDcProductId($product->getDcProductId()); // $child->save(); // } // } }
public function beforeSave($object) { if (!Mage::app()->getRequest()->getParam('canonical_url_custom')) { return parent::beforeSave($object); } $stores = array(); echo "<pre>"; print_r($object->getCanonicalUrl()); //exit; if (Mage::app()->getRequest()->getParam('store')) { $stores[] = Mage::app()->getRequest()->getParam('store'); $product = Mage::getSingleton('catalog/product')->setStoreId(Mage::app()->getRequest()->getParam('store'))->load($object->getId()); } else { foreach (Mage::app()->getStores() as $store) { $product = Mage::getSingleton('catalog/product')->setStoreId($store->getId())->load($object->getId()); if ($product) { $stores[] = $store->getId(); } } $product = Mage::getSingleton('catalog/product')->load($object->getId()); } foreach ($stores as $storeId) { $hashID = str_replace('0.', '', str_replace(' ', '_', microtime())); if (!$this->_hashId) { $this->_hashId = $hashID; } try { Mage::getModel('core/url_rewrite')->setStoreId($storeId)->setCategoryId(null)->setProductId($object->getId())->setIdPath($hashID)->setRequestPath(Mage::app()->getRequest()->getParam('canonical_url_custom'))->setTargetPath($product->getUrlPath())->setIsSystem(1)->setOptions('RP')->save(); } catch (Exception $e) { $obj = Mage::getModel('core/url_rewrite')->load(Mage::app()->getRequest()->getParam('canonical_url_custom'), 'request_path'); $this->_hashId = $obj->getIdPath(); } } $product = Mage::app()->getRequest()->getParam('product'); $product['canonical_url'] = $this->_hashId; Mage::app()->getRequest()->setParam('product', $product); $object->setCanonicalUrl($this->_hashId); return parent::beforeSave($object); }
/** * Before save method * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { $delimiter = ';'; $maxColumns = 3; $gridUnitMax = 12; $attributeCode = $this->getAttribute()->getAttributeCode(); $attributeValue = $object->getData($attributeCode); if ($attributeValue) { //To make parsing simpler, replace value with empty string if all units are 0 $exploded = explode($delimiter, $attributeValue); $sum = 0; for ($i = 0; $i < $maxColumns; $i++) { if (isset($exploded[$i])) { $sum += intval($exploded[$i]); } } if ($sum === 0) { $object->setData($attributeCode, ''); //Set empty value } } return parent::beforeSave($object); }
/** * * especially developed for copying when we get incoming data as an image collection * instead of plain post... * */ public function beforeSave($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 (!is_array($values) && is_object($values)) { foreach ((array) $values->getItems() as $image) { // TOFIX $io = new Varien_Io_File(); $value = $image->getData(); $data = array(); $data[$entityIdField] = $entityId; $data['attribute_id'] = $attributeId; $data['position'] = $value['position']; $data['entity_type_id'] = $entityTypeId; $data['store_id'] = $storeId; if ($entityId) { $connection->insert($this->getTable(), $data); $lastInsertId = $connection->lastInsertId(); } else { continue; } unset($newFileName); $types = $this->getImageTypes(); foreach ($types as $type) { try { $io->open(); $path = Mage::getStoreConfig('system/filesystem/upload', 0); $io->cp($path . '/' . $type . '/' . 'image_' . $entityId . '_' . $value['value_id'] . '.' . 'jpg', $path . '/' . $type . '/' . 'image_' . $entityId . '_' . $lastInsertId . '.' . 'jpg'); $io->close(); } catch (Exception $e) { continue; } $newFileName = 'image_' . $entityId . '_' . $lastInsertId . '.' . 'jpg'; } $condition = array($connection->quoteInto('value_id = ?', $lastInsertId)); if (isset($newFileName)) { $data = array(); $data['value'] = $newFileName; $connection->update($this->getTable(), $data, $condition); } else { $connection->delete($this->getTable(), $condition); } } $object->setData($this->getAttribute()->getName(), array()); } return parent::beforeSave($object); }
/** * Make SKU unique before save * * @param Varien_Object $object * @return Mage_Catalog_Model_Product_Attribute_Backend_Sku */ public function beforeSave($object) { $this->_generateUniqueSku($object); return parent::beforeSave($object); }