Exemplo n.º 1
0
 /**
  * Save attribute options
  * Override to save image to attribute option
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  * @version 1.7.0.2
  */
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (is_array($option)) {
         $adapter = $this->_getWriteAdapter();
         $optionTable = $this->getTable('eav/attribute_option');
         $optionValueTable = $this->getTable('eav/attribute_option_value');
         $stores = Mage::app()->getStores(true);
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $adapter->delete($optionTable, array('option_id = ?' => $intOptionId));
                     }
                     continue;
                 }
                 $sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
                 $image = !empty($option['image'][$optionId]) ? $option['image'][$optionId] : null;
                 $thumb = !empty($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : null;
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => $sortOrder, 'image' => $image, 'thumb' => $thumb);
                     $adapter->insert($optionTable, $data);
                     $intOptionId = $adapter->lastInsertId($optionTable);
                 } else {
                     $data = array('sort_order' => $sortOrder, 'image' => $image, 'thumb' => $thumb);
                     $where = array('option_id =?' => $intOptionId);
                     $adapter->update($optionTable, $data, $where);
                 }
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } elseif ($object->getFrontendInput() == 'select') {
                         $attributeDefaultValue = array($intOptionId);
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
                 }
                 $adapter->delete($optionValueTable, array('option_id =?' => $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $adapter->insert($optionValueTable, $data);
                     }
                 }
             }
             $bind = array('default_value' => implode(',', $attributeDefaultValue));
             $where = array('attribute_id =?' => $object->getId());
             $adapter->update($this->getMainTable(), $bind, $where);
         }
     }
     return $this;
 }
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (is_array($option)) {
         $write = $this->_getWriteAdapter();
         $optionTable = $this->getTable('attribute_option');
         $optionValueTable = $this->getTable('attribute_option_value');
         $stores = Mage::getModel('core/store')->getResourceCollection()->setLoadDefault(true)->load();
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $condition = $write->quoteInto('option_id=?', $intOptionId);
                         $write->delete($optionTable, $condition);
                     }
                     continue;
                 }
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'image' => isset($option['image'][$optionId]) ? $option['image'][$optionId] : '', 'thumb' => isset($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : '');
                     $write->insert($optionTable, $data);
                     $intOptionId = $write->lastInsertId();
                 } else {
                     $data = array('sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'image' => isset($option['image'][$optionId]) ? $option['image'][$optionId] : '', 'thumb' => isset($option['thumb'][$optionId]) ? $option['thumb'][$optionId] : '');
                     $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId));
                 }
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } else {
                         if ($object->getFrontendInput() == 'select') {
                             $attributeDefaultValue = array($intOptionId);
                         }
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.'));
                 }
                 $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $write->insert($optionValueTable, $data);
                     }
                 }
             }
             $write->update($this->getMainTable(), array('default_value' => implode(',', $attributeDefaultValue)), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId()));
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Save attribute options
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (!is_array($option)) {
         return $this;
     }
     $defaultValue = $object->getDefault() ?: array();
     if (isset($option['value'])) {
         if (!is_array($object->getDefault())) {
             $object->setDefault(array());
         }
         $defaultValue = $this->_processAttributeOptions($object, $option);
     }
     $this->_saveDefaultValue($object, $defaultValue);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Save attribute options
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (!is_array($option)) {
         return $this;
     }
     /* System attribute options are permanent, which of them is default can be changed only */
     if (!$object->getIsUserDefined() && !$object->getCanManageOptionLabels() && !$object->isObjectNew()) {
         $defaultValue = $object->getDefault() ?: array();
     } elseif (isset($option['value'])) {
         if (!is_array($object->getDefault())) {
             $object->setDefault(array());
         }
         $defaultValue = $this->_processUserDefinedAttributeOptions($object, $option);
     } else {
         $defaultValue = null;
     }
     $this->_saveDefaultValue($object, $defaultValue);
     return $this;
 }
Exemplo n.º 5
0
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (is_array($option)) {
         $write = $this->_getWriteAdapter();
         $optionTable = $this->getTable('attribute_option');
         $optionValueTable = $this->getTable('attribute_option_value');
         $stores = Mage::getModel('core/store')->getResourceCollection()->setLoadDefault(true)->load();
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $condition = $write->quoteInto('option_id=?', $intOptionId);
                         $write->delete($optionTable, $condition);
                     }
                     continue;
                 }
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0);
                     $write->insert($optionTable, $data);
                     $intOptionId = $write->lastInsertId();
                 } else {
                     $data = array('sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0);
                     $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId));
                 }
                 $attributeId = $object->getId();
                 $optionData = array();
                 if (isset($option['url_key'][$optionId])) {
                     $urlKey = preg_replace('/[^\\w]/ui', '', $option['url_key'][$optionId]);
                     $urlKey = trim($urlKey);
                     if ($urlKey) {
                         $optionData['url_key'] = $urlKey;
                     } else {
                         $optionData['url_key'] = trim(preg_replace('/[^\\w]/ui', '', strtolower($option['value'][$optionId][0])));
                     }
                     $optionExist = $write->fetchOne($write->select()->from(Mage::getSingleton('core/resource')->getTableName('ecommerceteam_sln/attribute'), 'attribute_id')->where('attribute_id != ? ', $attributeId)->where('url_key = ? ', $optionData['url_key']));
                     if ($optionExist) {
                         $optionData['url_key'] = $attributeId . '_' . $optionData['url_key'];
                     }
                 }
                 if (isset($option['remove_image'][$intOptionId])) {
                     $optionData['image'] = '';
                     $ioObject = new Varien_Io_File();
                     $targetDirectory = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'attribute' . DS . $attributeId . DS . $intOptionId;
                     $ioObject->rmdir($targetDirectory, true);
                 }
                 if (isset($option['image'][$optionId])) {
                     $imageInfo = Mage::helper('core')->jsonDecode($option['image'][$optionId]);
                     if (is_array($imageInfo)) {
                         //$imageInfo = array_shift($imageInfo);
                         if (!empty($imageInfo) && isset($imageInfo['status']) && $imageInfo['status'] == 'new') {
                             $image = Mage::helper('ecommerceteam_sln')->moveImageFromTemp($imageInfo['file'], $attributeId, $intOptionId);
                             $optionData['image'] = $image;
                         }
                     }
                 }
                 if (!empty($optionData)) {
                     $optionData['attribute_id'] = $attributeId;
                     $optionData['option_id'] = $intOptionId;
                     $table = Mage::getSingleton('core/resource')->getTableName('ecommerceteam_sln/attribute');
                     $write->insertOnDuplicate($table, $optionData);
                 }
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } else {
                         if ($object->getFrontendInput() == 'select') {
                             $attributeDefaultValue = array($intOptionId);
                         }
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.'));
                 }
                 $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $write->insert($optionValueTable, $data);
                     }
                 }
             }
             $write->update($this->getMainTable(), array('default_value' => implode(',', $attributeDefaultValue)), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId()));
         }
     }
     return $this;
 }
Exemplo n.º 6
0
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     $swatchOnLayeredEnabled = Mage::helper('weltpixel_productswatch')->isColorSwatchEnabledOnLayeredNavigation();
     $swatchOnProductEnabled = Mage::helper('weltpixel_layerednavigation')->isColorSwatchEnabledOnProduct();
     if (is_array($option)) {
         $adapter = $this->_getWriteAdapter();
         $optionTable = $this->getTable('eav/attribute_option');
         $optionValueTable = $this->getTable('eav/attribute_option_value');
         $stores = Mage::app()->getStores(true);
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $adapter->delete($optionTable, array('option_id = ?' => $intOptionId));
                         if ($swatchOnProductEnabled) {
                             Mage::helper('weltpixel_productswatch/image')->clearCache($object->getId(), $intOptionId);
                         }
                         if ($swatchOnLayeredEnabled) {
                             Mage::helper('weltpixel_layerednavigation/image')->clearCache($object->getId(), $intOptionId);
                         }
                     }
                     continue;
                 }
                 $sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
                 /**
                  * Customization - adding image options
                  */
                 $navigationImage = !empty($option['navigation_image'][$optionId]) ? $option['navigation_image'][$optionId] : '';
                 $productImage = !empty($option['product_image'][$optionId]) ? $option['product_image'][$optionId] : '';
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => $sortOrder);
                     if ($swatchOnProductEnabled) {
                         $data['product_image'] = $productImage;
                     }
                     if ($swatchOnLayeredEnabled) {
                         $data['navigation_image'] = $navigationImage;
                     }
                     $adapter->insert($optionTable, $data);
                     $intOptionId = $adapter->lastInsertId($optionTable);
                     if ($swatchOnProductEnabled) {
                         Mage::helper('weltpixel_productswatch/image')->clearCache($object->getId(), $intOptionId);
                     }
                     if ($swatchOnLayeredEnabled) {
                         Mage::helper('weltpixel_layerednavigation/image')->clearCache($object->getId(), $intOptionId);
                     }
                 } else {
                     $data = array('sort_order' => $sortOrder);
                     if ($swatchOnProductEnabled) {
                         $data['product_image'] = $productImage;
                     }
                     if ($swatchOnLayeredEnabled) {
                         $data['navigation_image'] = $navigationImage;
                     }
                     $where = array('option_id =?' => $intOptionId);
                     $wasThereUpdate = $adapter->update($optionTable, $data, $where);
                     if ($wasThereUpdate) {
                         ///delete swatch images
                         if ($swatchOnProductEnabled) {
                             Mage::helper('weltpixel_productswatch/image')->clearCache($object->getId(), $intOptionId);
                         }
                         if ($swatchOnLayeredEnabled) {
                             Mage::helper('weltpixel_layerednavigation/image')->clearCache($object->getId(), $intOptionId);
                         }
                     }
                 }
                 /**
                  * End Of Customization - adding image options
                  */
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } elseif ($object->getFrontendInput() == 'select') {
                         $attributeDefaultValue = array($intOptionId);
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
                 }
                 $adapter->delete($optionValueTable, array('option_id =?' => $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $adapter->insert($optionValueTable, $data);
                     }
                 }
             }
             $bind = array('default_value' => implode(',', $attributeDefaultValue));
             $where = array('attribute_id =?' => $object->getId());
             $adapter->update($this->getMainTable(), $bind, $where);
         }
     }
     return $this;
 }
Exemplo n.º 7
0
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (is_array($option)) {
         $write = $this->_getWriteAdapter();
         $optionTable = $this->getTable('attribute_option');
         $optionValueTable = $this->getTable('attribute_option_value');
         $stores = Mage::getModel('core/store')->getResourceCollection()->setLoadDefault(true)->load();
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $condition = $write->quoteInto('option_id=?', $intOptionId);
                         $write->delete($optionTable, $condition);
                     }
                     continue;
                 }
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0);
                     $write->insert($optionTable, $data);
                     $intOptionId = $write->lastInsertId();
                 } else {
                     $data = array('sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0);
                     $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId));
                 }
                 $attribute_id = $object->getId();
                 $table = Mage::getSingleton('core/resource')->getTableName('gomage_navigation_attribute_option');
                 $connection = $this->_getReadAdapter();
                 if (isset($option['remove_image'][$intOptionId]) && $option['remove_image'][$intOptionId] > 0) {
                     $connection->query("DELETE FROM {$table} WHERE `attribute_id` = {$attribute_id} AND `option_id` = {$intOptionId}; ");
                 }
                 if (isset($option['image'][$optionId])) {
                     $imageInfo = Zend_Json::decode($option['image'][$optionId]);
                     if (isset($imageInfo[0])) {
                         $imageInfo = $imageInfo[0];
                     } else {
                         $imageInfo = null;
                     }
                     if (!empty($imageInfo) && isset($imageInfo['status']) && $imageInfo['status'] == 'new') {
                         $image = Mage::getSingleton('gomage_navigation/observer')->moveImageFromTmp($imageInfo['file']);
                         $name = $imageInfo['name'];
                         $size = (double) $imageInfo['size'];
                         if ($connection->fetchOne("SELECT COUNT(*) FROM {$table} WHERE `attribute_id` = {$attribute_id} AND `option_id` = {$intOptionId};") > 0) {
                             $connection->query("UPDATE {$table} SET `filename` = '{$image}', `name` = '{$name}', `size` = {$size} WHERE `attribute_id` = {$attribute_id} AND `option_id` = {$intOptionId}; ");
                         } else {
                             $connection->query("INSERT INTO {$table} VALUES ({$attribute_id},{$intOptionId},'{$image}','{$name}',{$size});");
                         }
                     }
                 }
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } else {
                         if ($object->getFrontendInput() == 'select') {
                             $attributeDefaultValue = array($intOptionId);
                         }
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.'));
                 }
                 $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $write->insert($optionValueTable, $data);
                     }
                 }
             }
             $write->update($this->getMainTable(), array('default_value' => implode(',', $attributeDefaultValue)), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId()));
         }
     }
     return $this;
 }