protected function _afterSave(Mage_Core_Model_Abstract $object) { $descriptionTable = $this->getTable('customoptiondescription/product_option_description'); if (!$object->getData('scope', 'description')) { $statement = $this->_getReadAdapter()->select()->from($descriptionTable)->where('option_id = ' . $object->getId() . ' and store_id = ?', 0); if ($this->_getReadAdapter()->fetchOne($statement)) { if ($object->getStoreId() == '0') { $this->_getWriteAdapter()->update($descriptionTable, array('description' => $object->getDescription()), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', 0)); } } else { $this->_getWriteAdapter()->insert($descriptionTable, array('option_id' => $object->getId(), 'store_id' => 0, 'description' => $object->getDescription())); } } if ($object->getStoreId() != '0' && !$object->getData('scope', 'description')) { $statement = $this->_getReadAdapter()->select()->from($descriptionTable)->where('option_id = ' . $object->getId() . ' and store_id = ?', $object->getStoreId()); if ($this->_getReadAdapter()->fetchOne($statement)) { $this->_getWriteAdapter()->update($descriptionTable, array('description' => $object->getDescription()), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', $object->getStoreId())); } else { $this->_getWriteAdapter()->insert($descriptionTable, array('option_id' => $object->getId(), 'store_id' => $object->getStoreId(), 'description' => $object->getDescription())); } } elseif ($object->getData('scope', 'description')) { $this->_getWriteAdapter()->delete($descriptionTable, $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', $object->getStoreId())); } return parent::_afterSave($object); }
protected function _afterSave(Mage_Core_Model_Abstract $object) { $storeId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; if ($object->getStoreId() != $storeId) { $storeId = $object->getStoreId(); } // save view_mode $table = $this->getTable('mageworx_customoptions/option_view_mode'); if (!$object->getData('scope', 'view_mode') && !is_null($object->getViewMode())) { $select = $this->_getReadAdapter()->select()->from($table)->where('option_id = ?', $object->getId())->where('store_id = ?', $storeId); if ($this->_getReadAdapter()->fetchOne($select)) { $this->_getWriteAdapter()->update($table, array('view_mode' => $object->getViewMode()), 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } else { $this->_getWriteAdapter()->insert($table, array('option_id' => $object->getId(), 'store_id' => $storeId, 'view_mode' => $object->getViewMode())); } } elseif ($object->getData('scope', 'view_mode') || is_null($object->getViewMode())) { $this->_getWriteAdapter()->delete($table, 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } // save description $table = $this->getTable('mageworx_customoptions/option_description'); if (!$object->getData('scope', 'description') && $object->getDescription()) { $select = $this->_getReadAdapter()->select()->from($table)->where('option_id = ?', $object->getId())->where('store_id = ?', $storeId); if ($this->_getReadAdapter()->fetchOne($select)) { $this->_getWriteAdapter()->update($table, array('description' => $object->getDescription()), 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } else { $this->_getWriteAdapter()->insert($table, array('option_id' => $object->getId(), 'store_id' => $storeId, 'description' => $object->getDescription())); } } elseif ($object->getData('scope', 'description') || !$object->getDescription()) { $this->_getWriteAdapter()->delete($table, 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } // save default text $table = $this->getTable('mageworx_customoptions/option_default'); if (!$object->getData('scope', 'default_text') && $object->getDefaultText()) { $select = $this->_getReadAdapter()->select()->from($table)->where('option_id = ?', $object->getId())->where('store_id = ?', $storeId); if ($this->_getReadAdapter()->fetchOne($select)) { $this->_getWriteAdapter()->update($table, array('default_text' => $object->getDefaultText()), 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } else { $this->_getWriteAdapter()->insert($table, array('option_id' => $object->getId(), 'store_id' => $storeId, 'default_text' => $object->getDefaultText())); } } elseif ($object->getData('scope', 'default_text') || !$object->getDefaultText()) { $this->_getWriteAdapter()->delete($table, 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } return parent::_afterSave($object); }
protected function _afterSave(Mage_Core_Model_Abstract $object) { //better to check param 'price' and 'price_type' for saving. If there is not price scip saving price if (Mage::helper('aitcg/options')->checkAitOption($object)) { $priceTable = $this->getTable('catalog/product_option_price'); $aitImageTable = $this->getTable('catalog/product_option_aitimage'); //save for store_id = 0 $this->_saveForZeroStore($object); $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && !$object->getData('scope', 'price')) { $baseCurrency = Mage::app()->getBaseCurrencyCode(); $storeIds = Mage::app()->getStore($object->getStoreId())->getWebsite()->getStoreIds(); if (is_array($storeIds)) { foreach ($storeIds as $storeId) { if ($object->getPriceType() == 'fixed') { $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); if (!$rate) { $rate = 1; } $newPrice = $object->getPrice() * $rate; } else { $newPrice = $object->getPrice(); } if ($this->_ifStoreAndOption($object->getId(), $storeId, $priceTable)) { $this->_getWriteAdapter()->update($priceTable, array('price' => $newPrice, 'price_type' => $object->getPriceType()), $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', $storeId)); } else { $this->_getWriteAdapter()->insert($priceTable, array('option_id' => $object->getId(), 'store_id' => $storeId, 'price' => $newPrice, 'price_type' => $object->getPriceType())); } } // end foreach() } } elseif ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) { $this->_getWriteAdapter()->delete($priceTable, $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', $object->getStoreId())); } /* <<< AITOC_FIX */ //aitcg image if (!$object->getData('scope', 'image_template_id')) { if ($this->_ifStoreAndOption($object->getId(), 0, $aitImageTable)) { if ($object->getStoreId() == '0') { $this->_getWriteAdapter()->update($aitImageTable, $this->_getArrayOption($object), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', 0)); } } else { $this->_getWriteAdapter()->insert($aitImageTable, array('option_id' => $object->getId(), 'store_id' => 0) + $this->_getArrayOption($object)); } } if ($object->getStoreId() != '0' && !$object->getData('scope', 'image_template_id') && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { if ($this->_ifStoreAndOption($object->getId(), $object->getStoreId(), $aitImageTable)) { $this->_getWriteAdapter()->update($aitImageTable, $this->_getArrayOption($object), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', $object->getStoreId())); } else { $insertArray = $this->_getArrayOption($object); $insertArray['option_id'] = $object->getId(); $insertArray['store_id'] = $object->getStoreId(); $this->_getWriteAdapter()->insert($aitImageTable, $insertArray); } } elseif ($object->getData('scope', 'image_template_id') && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { $this->_getWriteAdapter()->delete($aitImageTable, $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', $object->getStoreId())); } /* >>> AITOC_FIX */ } return parent::_afterSave($object); }
protected function _afterSave(Mage_Core_Model_Abstract $object) { $this->_saveDescription($object); $this->_saveBlockTitle($object); return parent::_afterSave($object); }