Exemplo n.º 1
0
 /**
  * export old attributes from 4.9 to 4.10
  * @param Amasty_Pgrid_Model_Group $group
  * @param string                   $attributesKey
  *
  * @throws Exception
  */
 protected function _exportOldAttributes(Amasty_Pgrid_Model_Group $group, $attributesKey = '')
 {
     $extraKey = $attributesKey;
     $userId = Mage::getSingleton('admin/session')->getUser()->getId();
     $extraKey .= $userId;
     //first run module after update
     $defAttributes = Mage::getStoreConfig('ampgrid/attributes/ongrid' . $attributesKey);
     $defCategory = Mage::getStoreConfig('ampgrid/attributes/category' . $attributesKey);
     $attributes = Mage::getStoreConfig('ampgrid/attributes/ongrid' . $extraKey);
     $category = Mage::getStoreConfig('ampgrid/attributes/category' . $extraKey);
     if ($category == null) {
         //OLD OPTION BY DEFAULT
         $category = Mage::getStoreConfig('ampgrid/additional/category');
     }
     $defGroup = Mage::getModel('ampgrid/group');
     $defGroup->setData('title', $attributesKey ? 'Default(' . $attributesKey . ')' : 'Default');
     if ($defAttributes) {
         $realAttributes = array();
         $defAttributesRow = explode(',', $defAttributes);
         foreach ($defAttributesRow as $attribute) {
             $attr = Mage::getModel('eav/entity_attribute')->load($attribute);
             if ($attr->getId()) {
                 $realAttributes[] = $attribute;
             }
         }
         $defGroup->setData('attributes', implode(',', $realAttributes));
     }
     $defGroup->setData('additional_columns', $defCategory ? Mage::getModel('ampgrid/group')->getCategoriesKey() : '');
     $defGroup->setData('user_id', $userId);
     $defGroup->setData('is_default', 1);
     $defGroup->save();
     Mage::app()->getConfig()->saveConfig('ampgrid/attributes/ongrid' . $attributesKey, $defGroup->getId());
     Mage::getConfig()->saveConfig('ampgrid/attributes/ongrid' . $extraKey, $defGroup->getId());
     Mage::app()->getStore()->setConfig('ampgrid/attributes/ongrid' . $extraKey, $defGroup->getId());
     if ($attributes || $category == 1) {
         $group->setData('title', sprintf('Default(%s)', Mage::getSingleton('admin/session')->getUser()->getUsername()));
         if ($attributes) {
             $realAttributes = array();
             $attributesRow = explode(',', $attributes);
             foreach ($attributesRow as $attribute) {
                 $attr = Mage::getModel('eav/entity_attribute')->load($attribute);
                 if ($attr->getId()) {
                     $realAttributes[] = $attribute;
                 }
             }
             $group->setData('attributes', implode(',', $realAttributes));
         }
         $group->setData('additional_columns', $defCategory ? Mage::getModel('ampgrid/group')->getCategoriesKey() : '');
         $group->setData('user_id', $userId);
         $group->save();
     }
     //Group successfully saved, drop and rewrite config
     if ($group->getId()) {
         Mage::getConfig()->deleteConfig('ampgrid/attributes/category' . $extraKey);
         Mage::getConfig()->saveConfig('ampgrid/attributes/ongrid' . $extraKey, $group->getId());
         Mage::app()->getStore()->setConfig('ampgrid/attributes/ongrid' . $extraKey, $group->getId());
     }
 }
Exemplo n.º 2
0
 /**
  * @param array $attributesData
  * @param Amasty_Pgrid_Model_Group $currentGroup
  *
  * @throws Exception
  */
 protected function _saveAttributes($attributesData, $currentGroup)
 {
     $attrModel = Mage::getModel('ampgrid/groupattribute');
     $attrModel->getCollection()->addFieldToFilter('group_id', $currentGroup->getId())->walk('delete');
     if (!empty($attributesData)) {
         $copyAttribute = array();
         foreach ($attributesData as $key => &$value) {
             $value['group_id'] = $currentGroup->getId();
             if (in_array($value['attribute_id'], $copyAttribute)) {
                 unset($attributesData[$key]);
             } else {
                 $copyAttribute[] = $value['attribute_id'];
             }
         }
         $attrModel->insert($attributesData);
     }
 }