/** * get store id for static block and join them into array * * @param integer $blockId * @return array */ protected function _joinBlockStoreIds($blockId) { /** @var \Mage_Core_Model_Resource $resource */ $resource = \Mage::getSingleton('core/resource'); $list = []; $readConnection = $resource->getConnection('core_read'); $query = $readConnection->select()->from('cms_block_store')->where("block_id='{$blockId}'"); $results = $readConnection->fetchAll($query); foreach ($results as $store) { $code = \Mage::getModel('core/store')->load($store['store_id'])->getCode(); $extendedId = $this->_parser->createExtendedId('store', 'code', 'id', $code); $list[] = $extendedId; } return $list; }
/** * @see Nexway_SetupManager_Model_Processor_AbstractAction::execute() */ protected function _update() { $this->getParameters()->setModel('cms/page'); /** @var Parser $configParser */ $configParser = Parser::getInstance(); $data = $this->getParameters()->getData(self::F_DATA); $data['content'] = $configParser->convert($data['content'], Parser::CONVERT_FROM_EXTID); if (isset($data['parent_id']) && $data['parent_id'] === '0') { $loadId = $data['store_id']; $loadName = 'store_id'; if (isset($data['url_key']) && empty($data['url_key'])) { $data['identifier'] = $data['url_key']; } } else { /** @var \Mage_Cms_Model_Page $collection */ $collection = \Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier', ['eq' => $data['url_key']])->addFieldToFilter('store_id', ['eq' => $data['store_id']]); $loadedData = $collection->getData()[0]; $loadId = $loadedData['page_id']; $loadName = 'page_id'; } /** @var \Mage_Cms_Model_Page $cmsModel */ $cmsModel = \Mage::getModel('cms/page')->load($loadId, $loadName); $data = array_merge($cmsModel->getData(), $data); $cmsModel->setData($data); $cmsModel->save(); return true; }
protected function _save() { /** @var Parser $parser */ $parser = Parser::getInstance(); $agreementList = \Mage::getModel('checkout/agreement')->getCollection(); $configuration = array(); $action = 'agreement/create'; foreach ($agreementList as $agreement) { $agreement->load($agreement->getId()); $data = $agreement->getData(); $storeIds = $data['store_id']; $messageAction = 'agreement/save/' . $this->_truncate($data['name'], 40, '...'); $this->_showActionMessage([$messageAction], $this->_configurationCounter); foreach ($storeIds as &$storeId) { $code = \Mage::getModel('core/store')->load($storeId)->getCode(); $storeId = $parser->createExtendedId('store', 'code', 'id', $code); } $data['stores'] = $storeIds; unset($data['agreement_id']); unset($data['store_id']); $configuration[] = ['action' => $action, 'parameters' => ['data' => $data]]; echo $this->_colorizeString("[OK]\n", 'green'); $this->_configurationCounter++; } $this->_completeConfiguration = array_merge($configuration, $this->_completeConfiguration); }
/** * @return array */ public function getTaxRateConfiguration() { $taxRates = []; $parser = Parser::getInstance(); $taxRateCollection = \Mage::getModel('tax/calculation_rate')->getCollection(); foreach ($taxRateCollection as $taxRate) { try { $this->_showActionMessage(['save tax rate - ' . $taxRate->getCode()], $this->_configurationCounter); $data = $taxRate->getData(); $data['title'] = []; $titles = $taxRate->getTitles()->getData(); foreach ($titles as $title) { $store = \Mage::getModel('core/store')->load($title['store_id']); $extendedStoreId = $parser->createExtendedId('store', 'code', 'id', $store->getCode()); $data['title'][$extendedStoreId] = $title['value']; } unset($data['tax_calculation_rate_id']); $taxRates[] = ['taxrate/create', 'parameters' => ['data' => $data]]; $this->_configurationCounter++; echo $this->_colorizeString("[OK]\n", 'green'); } catch (\Exception $error) { echo $this->_colorizeString("[ERROR]\n", 'red'); $this->_prepareErrorMessage($error, $this->_configurationCounter); } } return $taxRates; }
/** * Convert store ids to exteneded id array * @param $storeIds * @return array */ protected function _convertStoreIds($storeIds) { $parser = Parser::getInstance(); $result = []; foreach ($storeIds as $storeId) { $store = \Mage::getModel('core/store')->load($storeId); $result[] = $parser->createExtendedId('store', 'code', 'id', $store->getCode()); } return $result; }
/** * @see Nexway_SetupManager_Model_Processor_AbstractAction::execute() */ protected function _update() { $this->getParameters()->setModel('cms/block'); /** @var Parser $configParser */ $configParser = Parser::getInstance(); $data = $this->getParameters()->getData(self::F_DATA); $data['content'] = $configParser->convert($data['content'], Parser::CONVERT_FROM_EXTID); /** @var \Mage_Cms_Model_Block $cmsModel */ $staticBlockModel = \Mage::getModel('cms/block')->load($data['identifier'], 'identifier'); $data = array_merge($staticBlockModel->getData(), $data); $staticBlockModel->setData($data); $staticBlockModel->save(); return true; }
protected function _update() { $this->getParameters()->setModel('checkout/agreement'); /** @var Parser $configParser */ $configParser = Parser::getInstance(); $data = $this->getParameters()->getData(self::F_DATA); $data['content'] = $configParser->convert($data['content'], Parser::CONVERT_FROM_EXTID); /** @var \Mage_Cms_Model_Block $agreementModel */ $agreementModel = \Mage::getModel('checkout/agreement')->load($data['agreement_id']); $data = array_merge($agreementModel->getData(), $data); $agreementModel->setData($data); $agreementModel->save(); return true; }
/** * override generic _create method to handle correct parent cms page * * @return bool */ protected function _create() { $this->getParameters()->setModel('cms/page'); /** @var Parser $configParser */ $configParser = Parser::getInstance(); $data = $this->getParameters()->getData(self::F_DATA); if ($data['parent_id'] !== '0' || !isset($data['parent_id'])) { $id = $this->_findParentId($data['store_id']); $data['parent_id'] = $id; } $data['content'] = $configParser->convert($data['content'], Parser::CONVERT_FROM_EXTID); $this->getParameters()->setData(self::F_DATA, $data); return parent::_create(); }
/** * @return bool */ protected function _create() { $parser = Parser::getInstance(); $this->getParameters()->setModel('tax/calculation_rate'); $data = $this->getParameters()->getData('data'); if (isset($data['title'])) { $parsedTitles = []; foreach ($data['title'] as $key => $value) { $parsedTitles[$parser->parseExtendedId($key)] = $value; } $data['title'] = $parsedTitles; $this->getParameters()->setData('data', $data); } return parent::_create(); }
/** * save all stores * * @return array */ protected function _saveStores() { $config = []; foreach (\Mage::app()->getWebsites() as $website) { foreach ($website->getGroups() as $group) { foreach ($group->getStores() as $store) { try { $this->_showActionMessage(['save store: ' . $store->getName()], $this->_configurationCounter); $code = \Mage::getModel('core/website')->load($group['website_id'])->getCode(); $config[] = ['store/createstore', 'parameters' => ['name' => $store->getName(), 'code' => $store->getCode(), 'group' => $this->_parser->createExtendedId('group', 'id', 'default_group_id', $code), 'website' => $this->_parser->createExtendedId('website', 'code', 'id', $code)]]; echo $this->_colorizeString("[OK]\n", 'green'); } catch (\Exception $error) { echo $this->_colorizeString("[ERROR]\n", 'red'); $this->_prepareErrorMessage($error, $this->_configurationCounter); } $this->_configurationCounter++; } } } return $config; }
/** * allow to save configuration array for all existing in database cms pages * with their configuration */ protected function _save() { /** @var Parser $configParser */ $configParser = Parser::getInstance(); $cmsPageCollection = \Mage::getModel('cms/page')->getCollection(); $parent = []; $children = []; foreach ($cmsPageCollection as $collection) { try { $data = $collection->getData(); $configurationAction = 'cms/create'; $messageAction = 'cms/save/' . $this->_truncate($data['title'], 40, '...'); $this->_showActionMessage([$messageAction], $this->_configurationCounter); $code = \Mage::getModel('core/store')->load($data['store_id'])->getCode(); $data['store_id'] = $configParser->createExtendedId('store', 'code', 'id', $code); $data['url_key'] = $data['identifier']; unset($data['page_id']); unset($data['identifier']); unset($data['path']); $data['content'] = $configParser->convert($data['content']); $configuration = ['action' => $configurationAction, 'parameters' => ['data' => $data]]; if ($data['parent_id'] === '0') { $configuration['action'] = 'cms/update'; $parent[] = $configuration; } else { unset($configuration['parameters']['data']['parent_id']); $children[] = $configuration; } echo $this->_colorizeString("[OK]\n", 'green'); } catch (\Exception $error) { echo $this->_colorizeString("[ERROR]\n", 'red'); $this->_prepareErrorMessage($error, $this->_configurationCounter); } $this->_configurationCounter++; } $cmsPages = array_merge($parent, $children); $this->_completeConfiguration = array_merge($cmsPages, $this->_completeConfiguration); return true; }
protected function _loadFile($path) { $configuration = $this->_readFile($path); $blackList = $this->_readFile(getcwd() . '/configuration/blacklist.php'); $error = false; foreach ($configuration as $key => $entry) { $skipConfig = isset($entry['parameters']['key']) && in_array($entry['parameters']['key'], $blackList); if ($skipConfig && !$this->_input->getOption('with-ignored-path')) { $this->_showActionMessage($entry, $key); $this->_output->writeln('<comment>[WARNING]</comment>'); $message = $entry['parameters']['key'] . ' - on blacklist'; $this->_prepareWarningMessage($message, $key); $this->_configurationCounter++; continue; } try { $result = $this->_processor->process($entry); /** @var Parser $parser */ $parser = Parser::getInstance(); if ($parser->warning) { $this->_showActionMessage($entry, $key); $this->_output->writeln('<comment>[WARNING]</comment>'); $this->_prepareWarningMessage($parser->warning, $key); $this->_configurationCounter++; } else { if (!$result) { $this->_showActionMessage($entry, $key); $this->_output->writeln('<error>[ERROR]</error>'); $this->_errors .= "[{$key}] Something wrong when try to apply configuration\n"; } else { if (!$this->_input->getOption('hide-success-msg')) { $this->_showActionMessage($entry, $key); $this->_output->writeln('<info>[OK]</info>'); } $this->_configurationCounter++; } } } catch (\Exception $error) { $this->_showActionMessage($entry, $key); $this->_output->writeln('<error>[ERROR]</error>'); $this->_prepareErrorMessage($error, $key); } finally { $key++; } } }
/** * @return Nexway_SetupManager_Helper_Parser */ public function getParserHelper() { return Parser::getInstance(); }
/** * @param string $value * @return string */ private function _cmsExtendedId($id) { $cms = Data::getInstance()->getCmsModel(); $cms->load($id); if ($cms->getId()) { $store = \Mage::getModel('core/store')->load($cms->getStoreId()); if (NULL === ($storeId = $store->getId())) { throw new \Exception('Unable to create extended id for cms page.' . " Page with id '{$id}' has invalid store id: '{$storeId}'"); } $parser = Parser::getInstance(); $storeExtId = $parser->createExtendedId('store', 'code', 'id', $store->getCode()); return sprintf('cms:identifier/%s,store_id/(%s)#page_id', rawurlencode($cms->getIdentifier()), $storeExtId); } throw new \Exception('Unable to create extended id for cms page.' . " Page with id '{$id}' not found"); }
/** * @return Parser */ protected function _getParser() { return Parser::getInstance(); }