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 _saveDescription(Mage_Core_Model_Abstract $object) { $table = $this->getTable('customoptions/option_description'); $storeId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; if ($object->getStoreId() != $storeId) { $storeId = $object->getStoreId(); } if (!$object->getData('scope', 'description')) { $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')) { $this->_getWriteAdapter()->delete($table, 'option_id = ' . $object->getId() . ' AND store_id = ' . $storeId); } }
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); }
public function getDescription() { //return str_replace("\"","%22",parent::getDescription()); return parent::getDescription(); }
protected function _afterSave(Mage_Core_Model_Abstract $object) { $priceTable = $this->getTable('catalog/product_option_price'); $titleTable = $this->getTable('catalog/product_option_title'); $opt = new Achang_Scene7_Model_Catalog_Product_Option(); $issvene7text = false; if ($opt->getGroupByType($object->getType()) == 'scene7text') { $issvene7text = true; } //better to check param 'price' and 'price_type' for saving. If there is not price scip saving price if ($object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME || $issvene7text) { //save for store_id = 0 if (!$object->getData('scope', 'price')) { $statement = $this->_getReadAdapter()->select()->from($priceTable)->where('option_id = ' . $object->getId() . ' AND store_id = ?', 0); if ($this->_getReadAdapter()->fetchOne($statement)) { if ($object->getStoreId() == '0') { $this->_getWriteAdapter()->update($priceTable, array('price' => $object->getPrice(), 'price_type' => $object->getPriceType()), $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', 0)); } } else { $this->_getWriteAdapter()->insert($priceTable, array('option_id' => $object->getId(), 'store_id' => 0, 'price' => $object->getPrice(), 'price_type' => $object->getPriceType())); } } $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(); } $statement = $this->_getReadAdapter()->select()->from($priceTable)->where('option_id = ' . $object->getId() . ' AND store_id = ?', $storeId); if ($this->_getReadAdapter()->fetchOne($statement)) { $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())); } } //title if (!$object->getData('scope', 'title')) { $statement = $this->_getReadAdapter()->select()->from($titleTable)->where('option_id = ' . $object->getId() . ' and store_id = ?', 0); if ($this->_getReadAdapter()->fetchOne($statement)) { if ($object->getStoreId() == '0') { $this->_getWriteAdapter()->update($titleTable, array('title' => $object->getTitle()), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', 0)); } } else { $this->_getWriteAdapter()->insert($titleTable, array('option_id' => $object->getId(), 'store_id' => 0, 'title' => $object->getTitle())); } } if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) { $statement = $this->_getReadAdapter()->select()->from($titleTable)->where('option_id = ' . $object->getId() . ' and store_id = ?', $object->getStoreId()); if ($this->_getReadAdapter()->fetchOne($statement)) { $this->_getWriteAdapter()->update($titleTable, array('title' => $object->getTitle()), $this->_getWriteAdapter()->quoteInto('option_id=' . $object->getId() . ' AND store_id=?', $object->getStoreId())); } else { $this->_getWriteAdapter()->insert($titleTable, array('option_id' => $object->getId(), 'store_id' => $object->getStoreId(), 'title' => $object->getTitle())); } } elseif ($object->getData('scope', 'title')) { $this->_getWriteAdapter()->delete($titleTable, $this->_getWriteAdapter()->quoteInto('option_id = ' . $object->getId() . ' AND store_id = ?', $object->getStoreId())); } ////////////////////////// $descriptionTable = $this->getTable('scenescene7/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 Mage_Core_Model_Mysql4_Abstract::_afterSave($object); }