public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current System Config Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); // @todo $_FILE? return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Website Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $params = $this->_decodeParams($encodedParameters); switch ($params['store_action']) { // // Handle saving of existing Website // case 'edit': // Convert Default Group UUID $defaultGroupUuid = $params['website']['default_group_id']; $defaultGroup = Mage::getModel('core/store_group')->load($defaultGroupUuid, 'name'); if ($defaultGroup->getId()) { $params['website']['default_group_id'] = $defaultGroup->getId(); } else { throw new Exception('Group \'' . $defaultGroupUuid . '\' not found!'); } // Convert Website UUID $websiteUuid = $params['website']['website_id']; $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); if ($website->getId()) { $params['website']['website_id'] = $website->getId(); } else { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // break intentionally omitted // // Handle adding new Website // // break intentionally omitted // // Handle adding new Website // case 'add': // Nothing to convert break; // // Handle deleting existing Website // store_action parameter is undefined in case of delete // // // Handle deleting existing Website // store_action parameter is undefined in case of delete // default: //Convert Item UUID $itemUuid = $params['item_id']; $website = Mage::getModel('core/website')->load($itemUuid, 'code'); if ($website->getId()) { $params['item_id'] = $website->getId(); } else { throw new Exception('Website \'' . $itemUuid . '\' not found!'); } break; } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($params); $_SERVER['REQUEST_METHOD'] = 'POST'; // needed by StoreController $request->setQuery($params); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Attribute Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); #$attributeCode = $parameters['mageploy_uuid']; if (isset($parameters['attribute_code'])) { $attributeCode = $parameters['attribute_code']; } else { $attributeCode = $parameters['attribute_id']; } // Prepare the Attribute Option Structure that will be used to // decode parameters and try to guess if an existing option has been // changed or added. // Note: we are assuming we never change admin's value $attribute = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attributeCode)->getFirstItem(); if ($attribute->getSourceModel()) { $attributeOptions = $attribute->getSource()->getAllOptions(false); $attributeOptionsByValue = array(); foreach ($attributeOptions as $order => $valuelabel) { $optionId = $valuelabel['value']; $adminVal = $valuelabel['label']; $attributeOptionsByValue[$adminVal] = array('order' => $order, 'id' => $optionId); } } $entityTypeId = Mage::helper('pugmore_mageploy')->getEntityTypeIdFromCode(Mage_Catalog_Model_Product::ENTITY); if ($attributeId = Mage::helper('pugmore_mageploy')->getAttributeIdFromCode($attributeCode, $entityTypeId)) { $parameters['attribute_id'] = $attributeId; } // Decode Attribute Options if (isset($parameters['option'])) { $option = $parameters['option']; // Used to store new options $newOptions = array(); // Value $newValues = array(); foreach ($option['value'] as $optionUuid => $optionValues) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newValues[$optionId] = array(); foreach ($optionValues as $storeCode => $value) { $storeId = Mage::getModel('core/store')->load($storeCode)->getId(); $newValues[$optionId][$storeId] = $value; } } $parameters['option']['value'] = $newValues; // Order $newOrders = array(); foreach ($option['order'] as $optionUuid => $optionOrder) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newOrders[$optionId] = $optionOrder; } $parameters['option']['order'] = $newOrders; // Delete $newDeletes = array(); foreach ($option['delete'] as $optionUuid => $optionDelete) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newDeletes[$optionId] = $optionDelete; } $parameters['option']['delete'] = $newDeletes; } // Decode Default Option if (isset($attributeOptionsByValue)) { $optionUuid = $parameters['default'][0]; $parameters['default'][0] = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); } // Decode Frontend Label $newFrontendLabel = array(); foreach ($parameters['frontend_label'] as $storeCode => $label) { $storeId = Mage::getModel('core/store')->load($storeCode)->getId(); $newFrontendLabel[$storeId] = $label; } $parameters['frontend_label'] = $newFrontendLabel; $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Attribute Set Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $helper = Mage::helper('pugmore_mageploy'); $parameters = $this->_decodeParams($encodedParameters); $attributeSetName = $parameters['mageploy_uuid']; $entityTypeId = $this->_getEntityTypeId(); $entityTypeCode = $this->_getEntityTypeCode(); if ($attributeSetId = $helper->getAttributeSetIdFromName($attributeSetName)) { $parameters['id'] = $attributeSetId; } $skeletonSetName = $parameters['skeleton_set']; if ($skeletonSetId = $helper->getAttributeSetIdFromName($skeletonSetName)) { $parameters['skeleton_set'] = $skeletonSetId; } $data = $parameters['data']; foreach ($data['attributes'] as $i => $attribute) { $attributeUuid = $attribute[0]; $attributeId = $helper->getAttributeIdFromCode($attributeUuid, $entityTypeId); if ($attributeId == 208) { $break = $here; } $attributeGroupUuid = $attribute[1]; // Is new Group? if (!strncmp($attributeGroupUuid, 'ynode', strlen('ynode'))) { $attributeGroupId = $attributeGroupUuid; $eavAttributeId = null; } else { // $attributeSetUuid is not used; we still have to explode the // string in order to mantain compatibility with encoding list($attributeGroupName, $attributeSetUuid) = explode(self::UUID_SEPARATOR, $attributeGroupUuid); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $eavAttributeId = $helper->getEavEntityAttributeId($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId); } $data['attributes'][$i][0] = $attributeId; $data['attributes'][$i][1] = $attributeGroupId; if ($eavAttributeId) { $data['attributes'][$i][3] = $eavAttributeId; } else { $data['attributes'][$i][3] = ''; } } foreach ($data['groups'] as $i => $group) { $attributeGroupUuid = $group[0]; if (!strncmp($attributeGroupUuid, 'ynode', strlen('ynode'))) { continue; } list($attributeGroupName, $attributeSetUuid) = explode(self::UUID_SEPARATOR, $attributeGroupUuid, 2); $attributeSetName = $attributeSetUuid; $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $data['groups'][$i][0] = $attributeGroupId; } foreach ($data['not_attributes'] as $i => $eavAttributeUuid) { if (empty($eavAttributeUuid)) { continue; } list($attributeGroupName, $attributeSetName, $attributeCode) = explode(self::UUID_SEPARATOR, $eavAttributeUuid); $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $attributeId = $helper->getAttributeIdFromCode($attributeCode, $entityTypeId); $entityAttributeId = $helper->getEavEntityAttributeId($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId); $data['not_attributes'][$i] = $entityAttributeId; } foreach ($data['removeGroups'] as $i => $attributeGroupUuid) { if (empty($attributeGroupUuid)) { continue; } list($attributeGroupName, $attributeSetName) = explode(self::UUID_SEPARATOR, $attributeGroupUuid); $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $data['removeGroups'][$i] = $attributeGroupId; } // json encode data array $parameters['data'] = Zend_Json::encode($data); $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Website Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $helper = Mage::helper('pugmore_mageploy'); $params = $this->_decodeParams($encodedParameters); switch ($params['store_action']) { // // Handle saving of existing Website // case 'edit': $websiteUuid = $params['group']['website_id']; $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); if (!$website->getId()) { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // Convert Default Store UUID $defaultStoreUuid = $params['group']['default_store_id']; $defaultStore = Mage::getModel('core/store')->load($defaultStoreUuid, 'code'); if (!$defaultStore->getId()) { throw new Exception('Store \'' . $defaultStoreUuid . '\' not found!'); } $params['group']['default_store_id'] = $defaultStore->getId(); // Convert Group UUID $groupUuid = $params['group']['group_id']; $group = Mage::getModel('core/store_group')->getCollection()->addWebsiteFilter($website->getId())->addFieldToFilter('name', $groupUuid)->getFirstItem(); if (!$group->getId()) { throw new Exception('Group \'' . $groupUuid . '\' not found!'); } $params['group']['group_id'] = $group->getId(); // break intentionally omitted // // Handle adding new Website // // break intentionally omitted // // Handle adding new Website // case 'add': $websiteUuid = $params['group']['website_id']; if (!isset($website)) { $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); } if (!$website->getId()) { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // Convert Website UUID $params['group']['website_id'] = $website->getId(); // Convert Root Category UUID $rootCategoryUuid = $params['group']['root_category_id']; $rootCategoryPath = $helper->getCategoryPathFromUuid($rootCategoryUuid, self::UUID_SEPARATOR); $rootCategoryId = $helper->getCategoryIdFromPath($rootCategoryPath); $params['group']['root_category_id'] = $rootCategoryId; break; // // Handle deleting existing Website // store_action parameter is undefined in case of delete // // // Handle deleting existing Website // store_action parameter is undefined in case of delete // default: //Convert Item UUID $itemUuid = $params['item_id']; list($websiteCode, $groupName) = explode(self::UUID_SEPARATOR, $itemUuid, 2); $website = Mage::getModel('core/website')->load($websiteCode, 'code'); if (!$website->getId()) { throw new Exception('Website \'' . $websiteCode . '\' not found!'); } $group = Mage::getModel('core/store_group')->getCollection()->addWebsiteFilter($website->getId())->addFieldToFilter('name', $groupName)->getFirstItem(); break; } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($params); $_SERVER['REQUEST_METHOD'] = 'POST'; // needed by StoreController $request->setQuery($params); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current CMS Page Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); // convert store IDs foreach ($parameters['stores'] as $i => $storeUuid) { $storeId = Mage::app()->getStore($storeUuid)->getId(); $parameters['stores'][$i] = $storeId; } // convert UUID, if page already exists if (isset($parameters['page_id'])) { list($identifier, $joinedStoreCodes) = explode(self::UUID_SEPARATOR, $parameters['page_id'], 2); $storeCodes = explode(self::UUID_SEPARATOR, $joinedStoreCodes); $storeId = Mage::app()->getStore($storeCodes[0])->getId(); $page = Mage::getModel('cms/page')->getCollection()->addStoreFilter($storeId, false)->addFieldToFilter('identifier', $identifier)->getFirstItem(); /** * On pages created out of the box by Magento, the addStoreFilter * doesn't seem to return the requested object. */ if (!$page->getId()) { $page = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier', $identifier)->getFirstItem(); } $parameters['page_id'] = $page->getId(); } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }