/** * Test render method */ public function testRender() { $arrayToRender = array('key' => 'value'); /** Assert jsonEncode method in mocked helper will run once */ $this->_helperMock->expects($this->once())->method('jsonEncode'); $this->_restJsonRenderer->render($arrayToRender); }
/** * Generate a [salted] hash. * * $salt can be: * false - a random will be generated * integer - a random with specified length will be generated * string * * @param string $password * @param mixed $salt * @return string */ public function getHash($password, $salt = false) { if (is_integer($salt)) { $salt = $this->_helper->getRandomString($salt); } return $salt === false ? $this->hash($password) : $this->hash($salt . $password) . ':' . $salt; }
/** * Get the total amount to be redeemed from gift cards, formatted as currency. * @return string */ protected function _getAppliedGiftCardTotal() { $appliedTotal = 0.0; foreach ($this->_giftCardContainer->getUnredeemedGiftCards() as $card) { $appliedTotal += $card->getAmountToRedeem(); } return $this->_coreHelper->currency($appliedTotal, true, false); }
/** * Set up the paypal helper. */ public function _construct() { parent::_construct(); $app = Mage::app(); $locale = $app->getLocale(); $this->_coreHelper = $this->helper('core'); $this->_paymentHelper = Mage::helper('payment'); $this->_helper = Mage::helper('ebayenterprise_paypal'); $this->_config = $this->_helper->getConfigModel(); $this->_localeCode = $locale->getLocaleCode(); $url = $this->_config->shortcutExpressCheckoutButton ?: self::DEFAULT_IMAGE_URL; $this->_payPalImageUrl = str_replace(array('{locale_code}'), array($this->_localeCode), $url); $this->_htmlId = $this->_coreHelper->uniqHash(self::HTML_ID_PREFIX); }
public function isModuleEnabled($moduleName = null) { if (Mage::getStoreConfig(self::CONFIG_ACTIVE) == '0') { return false; } return parent::isModuleEnabled($moduleName = null); }
/** * Generate secret key for controller and action based on form key * * @param string $routeName * @param string $controller Controller name * @param string $action Action name * @return string */ public function getSecretKey($routeName = null, $controller = null, $action = null) { $salt = $this->_coreSession->getFormKey(); $request = $this->getRequest(); if (!$routeName) { if ($request->getBeforeForwardInfo('route_name') !== null) { $routeName = $request->getBeforeForwardInfo('route_name'); } else { $routeName = $request->getRouteName(); } } if (!$controller) { if ($request->getBeforeForwardInfo('controller_name') !== null) { $controller = $request->getBeforeForwardInfo('controller_name'); } else { $controller = $request->getControllerName(); } } if (!$action) { if ($request->getBeforeForwardInfo('action_name') !== null) { $action = $request->getBeforeForwardInfo('action_name'); } else { $action = $request->getActionName(); } } $secret = $routeName . $controller . $action . $salt; return $this->_coreHelper->getHash($secret); }
/** * Merge specified files into one * * By default will not merge, if there is already merged file exists and it * was modified after its components * If target file is specified, will attempt to write merged contents into it, * otherwise will return merged content * May apply callback to each file contents. Callback gets parameters: * (<existing system filename>, <file contents>) * May filter files by specified extension(s) * Returns false on error * * @param array $srcFiles * @param string|false $targetFile - file path to be written * @param bool $mustMerge * @param callback $beforeMergeCallback * @param array|string $extensionsFilter * @return bool|string */ public function mergeFiles(array $srcFiles, $targetFile = false, $mustMerge = false, $beforeMergeCallback = null, $extensionsFilter = array()) { $content_type = pathinfo($targetFile, PATHINFO_EXTENSION); if (!Mage::getStoreConfig('minify/general/enabled') || $content_type != 'css' && $content_type != 'js') { return parent::mergeFiles($srcFiles, $targetFile, $mustMerge, $beforeMergeCallback, $extensionsFilter); } if (!Mage::getStoreConfig('minify/general/' . $content_type)) { return parent::mergeFiles($srcFiles, $targetFile, $mustMerge, $beforeMergeCallback, $extensionsFilter); } try { $shouldMinify = $this->shouldMinify($mustMerge, $targetFile, $srcFiles); if ($shouldMinify) { $result = parent::mergeFiles($srcFiles, false, $mustMerge, $beforeMergeCallback, $extensionsFilter); Varien_Profiler::start('minify_file_' . $targetFile); switch ($content_type) { case 'css': $minifier = new MatthiasMullie\Minify\CSS($result); break; case 'js': $minifier = new MatthiasMullie\Minify\JS($result); break; } $minifier->minify($targetFile); Varien_Profiler::stop('minify_file_' . $targetFile); } return true; } catch (Exception $e) { Mage::logException($e); } return false; }
public function jsonEncode($valueToEncode, $cycleCheck = false, $options = array()) { if ('saveBilling' == Mage::app()->getRequest()->getActionName()) { if ('shipping_method' == $valueToEncode['goto_section']) { // will check if we have required attributes on shipping info step $collection = Mage::getModel('eav/entity_attribute')->getCollection(); $collection->addFieldToFilter('is_visible_on_front', 1); $collection->addFieldToFilter('entity_type_id', Mage::getModel('eav/entity')->setType('order')->getTypeId()); $collection->addFieldToFilter('checkout_step', 3); $collection->addFieldToFilter('is_required', 1); $collection->load(); $forceShipping = false; if ($collection->getSize() > 0) { foreach ($collection as $attribute) { $currentStore = Mage::app()->getStore()->getId(); $storeIds = explode(',', $attribute->getData('store_ids')); if (!in_array($currentStore, $storeIds) && !in_array(0, $storeIds)) { continue; } $forceShipping = true; } } if ($forceShipping) { $valueToEncode['goto_section'] = 'shipping'; unset($valueToEncode['update_section']); } } } return parent::jsonEncode($valueToEncode, $cycleCheck, $options); }
public function isModuleEnabled($moduleName = null) { if ((int) Mage::getStoreConfig(self::XML_PATH_STATUS, Mage::app()->getStore()) != 1) { return false; } return parent::isModuleEnabled($moduleName); }
public function testDuplicateProductTypeFile() { $currentProduct = $this->getMock('Mage_Catalog_Model_Product', array('getTypeId', 'getTypeInstance'), array(), '', false); $currentProduct->expects($this->once())->method('getTypeId')->will($this->returnValue(Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)); $newProduct = $this->getMock('Mage_Catalog_Model_Product', array('getTypeId', 'getTypeInstance'), array(), '', false); $links = $this->_getLinks(); $samples = $this->_getSamples(); $getLinks = new Varien_Object($links); $getSamples = new Varien_Object($samples); $typeInstance = $this->getMock('Mage_Downloadable_Model_Product_Type', array('getLinks', 'getSamples'), array(), '', false); $typeInstance->expects($this->atLeastOnce())->method('getLinks')->will($this->returnValue(array($getLinks))); $typeInstance->expects($this->atLeastOnce())->method('getSamples')->will($this->returnValue(array($getSamples))); $currentProduct->expects($this->atLeastOnce())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $this->_setObserverExpectedMethods($currentProduct, $newProduct); $callbackJsonEncode = function ($arg) { return json_encode($arg); }; $this->_helperJsonEncode->expects($this->atLeastOnce())->method('jsonEncode')->will($this->returnCallback($callbackJsonEncode)); $this->assertNull($newProduct->getDownloadableData($newProduct)); $this->_model->duplicateProduct($this->_observer); $newDownloadableData = $newProduct->getDownloadableData(); $fileData = json_decode($newDownloadableData['link'][0]['file'], true); $this->assertEquals($links['price'], $newDownloadableData['link'][0]['price']); $this->assertEquals($links['link_file'][0], $fileData[0]['file'][0]); $this->assertEquals($samples['title'], $newDownloadableData['sample'][0]['title']); $this->assertEquals(false, $newDownloadableData['link'][0]['is_delete']); $this->assertEquals($links['number_of_downloads'], $newDownloadableData['link'][0]['number_of_downloads']); }
public function isModuleOutputEnabled($moduleName = null) { $siteId = $this->getSiteId(); if (empty($siteId)) { return false; } return parent::isModuleOutputEnabled($moduleName); }
/** * Test to get valid html code for 'image' with placeholder */ public function testImagePlaceholder() { $urlPath = 'http://example.com/pub/images/image-placeholder.png'; $this->_block->setValue(null); $this->_coreHelper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $html = $this->_createHtmlCode('', $urlPath); $this->assertXmlStringEqualsXmlString(str_replace('×', '&times;', "<test>{$html}</test>"), str_replace('×', '&times;', "<test>{$this->_block->getElementHtml()}</test>"), 'Another BaseImage html code is expected'); }
/** * Encode data * * @param Mage_Core_Model_Abstract $object * @param string $filedName * @return mixed */ public function encode(Mage_Core_Model_Abstract $object, $filedName) { $value = $object->getData($filedName); if ($this->_shouldBeEncrypted($object, $filedName)) { $value = $this->_encryptor->encrypt($value); } return $value; }
/** * Test to get valid html code for 'image' with placeholder */ public function testImagePlaceholder() { $urlPath = 'http://example.com/pub/images/image-placeholder.png'; $this->_model->setValue(null); $this->_design->expects($this->once())->method('getViewFileUrl')->will($this->returnValue($urlPath)); $this->_helperData->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $html = $this->_createHtmlCode('', $urlPath); $this->assertXmlStringEqualsXmlString("<test>{$html}</test>", "<test>{$this->_model->getElementHtml()}</test>", 'Another BaseImage html code is expected'); }
public function setUp() { $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false); $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false); $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt')); $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false); $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0)); $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false); $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false)); $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role')); $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem)); $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false); $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName)); $this->_routes = array('admin' => 'adminhtml', 'adminhtml' => ''); $this->_model = new Mage_Backend_Model_Url(array('startupMenuItemId' => 'Mage_Adminhtml::system_acl_roles', 'menu' => $this->_menuMock, 'backendHelper' => $helperMock, 'coreSession' => $this->_coreSessionMock, 'coreHelper' => $this->_coreHelperMock, 'routes' => $this->_routes)); $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false); $this->_model->setRequest($this->_requestMock); }
/** * Return config values that may vary by website/store for the given * website. * @param Mage_Core_Model_Website $website * @return array Config values for store id, AMQP username and AMQP password */ public function getWebsiteLevelAmqpConfigurations(Mage_Core_Model_Website $website) { $storeIdPath = $this->_coreConfigMap->getPathForKey(self::STORE_ID_CONFIG_KEY); $usernamePath = $this->_amqpConfigMap->getPathForKey(self::USERNAME_CONFIG_KEY); $passwordPath = $this->_amqpConfigMap->getPathForKey(self::PASSWORD_CONFIG_KEY); $defaultCoreConfig = $this->_coreHelper->getConfigModel(Mage::app()->getStore(0)); $defaultAmqpConfig = $this->_helper->getConfigModel(Mage::app()->getStore(0)); // get website level config values, falling back to any not available to the // website with default store config values return array('store_id' => $website->getConfig($storeIdPath) ?: $defaultCoreConfig->storeId, 'username' => $website->getConfig($usernamePath) ?: $defaultAmqpConfig->username, 'password' => $this->_mageHelper->decrypt($website->getConfig($passwordPath)) ?: $defaultAmqpConfig->password); }
/** * Convenience method for formatting currency values * * @param float $price * @param string $currencyCode (Optional) * * @return string */ public function formatPrice($price, $currencyCode = null) { $options = array('precision' => 2, 'display' => Zend_Currency::NO_SYMBOL); if (Mage::helper('bronto_common')->useCurrencySymbol($this->getStore()->getId())) { unset($options['display']); } $currencyCode = $currencyCode ? $currencyCode : $this->getStore()->getDefaultCurrencyCode(); if (is_null($this->_currency) || $this->_currency->getCode() != $currencyCode) { $this->_currency = Mage::getModel('directory/currency')->load($currencyCode); } return $this->_currency->formatTxt($price, $options); }
public function mergeFiles(array $srcFiles, $targetFile = false, $mustMerge = false, $beforeMergeCallback = null, $extensionsFilter = array(), $mimeType = null) { if (!Mage::helper('magefm_cdn')->isEnabled()) { return parent::mergeFiles($srcFiles, $targetFile, $mustMerge, $beforeMergeCallback, $extensionsFilter); } $targetPath = '/' . $targetFile; try { $cacheKey = 'magefm_cdn|' . $targetFile; if (Mage::app()->getCache()->load($cacheKey)) { return true; } // filter by extensions if ($extensionsFilter) { if (!is_array($extensionsFilter)) { $extensionsFilter = array($extensionsFilter); } if (!empty($srcFiles)) { foreach ($srcFiles as $key => $file) { $fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (!in_array($fileExt, $extensionsFilter)) { unset($srcFiles[$key]); } } } } if (empty($srcFiles)) { // no translation intentionally throw new Exception('No files to compile.'); } $data = ''; foreach ($srcFiles as $file) { if (!file_exists($file)) { continue; } $contents = file_get_contents($file) . "\n"; if ($beforeMergeCallback && is_callable($beforeMergeCallback)) { $contents = call_user_func($beforeMergeCallback, $file, $contents); } $data .= $contents; } if (!$data) { // no translation intentionally throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles))); } $storage = Mage::helper('magefm_cdn/storage'); $storage->saveFileFromContent($targetPath, $data, $mimeType, true); Mage::app()->getCache()->save('1', $cacheKey, array('magefm_cdn')); return true; } catch (Exception $e) { die($e->getMessage()); } return false; }
public function __() { $args = func_get_args(); if (isset($args[0]) && is_array($args[0]) && count($args) == 1) { $args = $args[0]; } $message = array_shift($args); if ($message instanceof OS_Message) { $args = $message->args; $message = $message->message; } $output = parent::__($message); /*if (true) { $translations = @file_get_contents('translations.os2'); $translations = eval('return '.$translations.';'); if (!is_array($translations)) $translations = array(); $file = 'NC'; $line = 'NC'; $backtrace = debug_backtrace(); foreach ($backtrace as $trace) { if (!isset($trace['function'])) continue; if (substr($trace['function'], strlen($trace['function'])-2, strlen($trace['function']))=='__') { $file = ltrim(str_replace(Mage::getBaseDir(), '', $trace['file']), '/'); $line = $trace['line']; continue; } //$file = ltrim(str_replace(Mage::getBaseDir(), '', $trace['file']), '/'); //echo $file.', '.$trace['function'].'(), '.$line.', '.$message.'<br/>'; break; } $translations[Mage::app()->getLocale()->getLocaleCode()][$file][$message] = $output; ksort($translations[Mage::app()->getLocale()->getLocaleCode()]); file_put_contents('translations.os2', var_export($translations, true)); }*/ if (count($args) == 0) { $result = $output; } else { if (!isset($this->_translate_inline)) { $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline(); } if ($this->_translate_inline) { $parts = explode('}}{{', $output); $parts[0] = vsprintf($parts[0], $args); $result = implode('}}{{', $parts); } else { $result = vsprintf($output, $args); } } return $result; }
/** * Create theme customization * * @param Mage_Core_Model_Theme $theme * @return Mage_Core_Model_Theme */ public function createThemeCustomization($theme) { $themeCopyCount = $this->_getThemeCustomizations()->addFilter('parent_id', $theme->getId())->count(); $themeData = $theme->getData(); $themeData['parent_id'] = $theme->getId(); $themeData['theme_id'] = null; $themeData['theme_path'] = null; $themeData['theme_title'] = $theme->getThemeTitle() . ' - ' . $this->_helper->__('Copy') . ' #' . ($themeCopyCount + 1); /** @var $themeCustomization Mage_Core_Model_Theme */ $themeCustomization = $this->_themeFactory->create()->setData($themeData); $themeCustomization->createPreviewImageCopy()->save(); return $themeCustomization; }
public function isModuleOutputEnabled($moduleName = null) { if (is_callable(array(Mage::helper('core'), 'isModuleOutputEnabled'))) { return parent::isModuleOutputEnabled(); } if ($moduleName === null) { $moduleName = $this->_getModuleName(); } if (Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) { return false; } return true; }
public function setUp() { $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false); $this->_menuConfigMock = $this->getMock('Mage_Backend_Model_Menu_Config', array(), array(), '', false); $this->_menuConfigMock->expects($this->any())->method('getMenu')->will($this->returnValue($this->_menuMock)); $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false); $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt')); $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false); $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0)); $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false); $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false)); $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role')); $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem)); $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false); $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName)); $this->_storeConfigMock = $this->getMock('Mage_Core_Model_Store_Config', array(), array(), '', false); $this->_storeConfigMock->expects($this->any())->method('getConfig')->with(Mage_Backend_Model_Url::XML_PATH_STARTUP_MENU_ITEM)->will($this->returnValue('Mage_Adminhtml::system_acl_roles')); $this->_model = new Mage_Backend_Model_Url($helperMock, $this->_coreHelperMock, $this->_coreSessionMock, $this->_storeConfigMock, $this->_menuConfigMock); $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false); $this->_model->setRequest($this->_requestMock); }
/** * @param array $source * @param array $result * @param bool $isXml * * @dataProvider getLayoutUpdateActionDataProvider */ public function testGetLayoutUpdateAction(array $source, array $result, $isXml = false) { $this->getRequest()->setPost($source); $this->dispatch('backend/admin/system_design_editor/getLayoutUpdate'); $response = $this->_dataHelper->jsonDecode($this->getResponse()->getBody()); // convert to XML string to the same format as in $result if ($isXml) { foreach ($response as $code => $data) { foreach ($data as $key => $value) { $xml = new Varien_Simplexml_Element($value); $response[$code][$key] = $xml->asNiceXml(); } } } $this->assertEquals($result, $response); }
/** * Save file to storage * * @param string $filePath * @param string $content * @param bool $overwrite * @return bool */ public function saveFile($filePath, $content, $overwrite = false) { if (strpos($filePath, $this->getMediaBaseDirectory()) !== 0) { $filePath = $this->getMediaBaseDirectory() . DS . $filePath; } try { if (!$this->_filesystem->isFile($filePath) || $overwrite && $this->_filesystem->delete($filePath)) { $this->_filesystem->write($filePath, $content); return true; } } catch (Magento_Filesystem_Exception $e) { $this->_logger->log($e->getMessage()); Mage::throwException($this->_helper->__('Unable to save file: %s', $filePath)); } return false; }
/** * Format error data according to required format. * * @param string $errorMessage * @param string $trace * @param string $format * @param int $httpCode * @return array */ protected function _formatError($errorMessage, $trace, $httpCode, $format) { $errorData = array(); $message = array('code' => $httpCode, 'message' => $errorMessage); if ($this->_app->isDeveloperMode()) { $message['trace'] = $trace; } $errorData['messages']['error'][] = $message; switch ($format) { case self::DATA_FORMAT_JSON: $errorData = $this->_coreHelper->jsonEncode($errorData); break; case self::DATA_FORMAT_XML: $errorData = '<?xml version="1.0"?>' . '<error>' . '<messages>' . '<error>' . '<data_item>' . '<code>' . $httpCode . '</code>' . '<message>' . $errorMessage . '</message>' . ($this->_app->isDeveloperMode() ? '<trace><![CDATA[' . $trace . ']]></trace>' : '') . '</data_item>' . '</error>' . '</messages>' . '</error>'; break; } return $errorData; }
/** * Duplicating downloadable product data * * @param Varien_Event_Observer $observer * @return Mage_Downloadable_Model_Observer */ public function duplicateProduct($observer) { $currentProduct = $observer->getCurrentProduct(); $newProduct = $observer->getNewProduct(); if ($currentProduct->getTypeId() !== Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { //do nothing if not downloadable return $this; } $downloadableData = array(); $type = $currentProduct->getTypeInstance(); foreach ($type->getLinks($currentProduct) as $link) { $linkData = $link->getData(); $downloadableData['link'][] = array('is_delete' => false, 'link_id' => null, 'title' => $linkData['title'], 'is_shareable' => $linkData['is_shareable'], 'sample' => array('type' => $linkData['sample_type'], 'url' => $linkData['sample_url'], 'file' => $this->_helper->jsonEncode(array(array('file' => $linkData['sample_file'], 'name' => $linkData['sample_file'], 'size' => 0, 'status' => null)))), 'file' => $this->_helper->jsonEncode(array(array('file' => $linkData['link_file'], 'name' => $linkData['link_file'], 'size' => 0, 'status' => null))), 'type' => $linkData['link_type'], 'link_url' => $linkData['link_url'], 'sort_order' => $linkData['sort_order'], 'number_of_downloads' => $linkData['number_of_downloads'], 'price' => $linkData['price']); } foreach ($type->getSamples($currentProduct) as $sample) { $sampleData = $sample->getData(); $downloadableData['sample'][] = array('is_delete' => false, 'sample_id' => null, 'title' => $sampleData['title'], 'type' => $sampleData['sample_type'], 'file' => $this->_helper->jsonEncode(array(array('file' => $sampleData['sample_file'], 'name' => $sampleData['sample_file'], 'size' => 0, 'status' => null))), 'sample_url' => $sampleData['sample_url'], 'sort_order' => $sampleData['sort_order']); } $newProduct->setDownloadableData($downloadableData); return $this; }
$t = $this->getTable('cms_block'); $conn->addColumn($t, 'udropship_vendor', 'int(11) unsigned'); $conn->addConstraint('FK_CMS_BLOCK_VENDOR', $t, 'udropship_vendor', $vt, 'vendor_id'); */ $t = $this->getTable('admin_user'); $conn->modifyColumn($t, 'username', 'varchar(128) NOT NULL DEFAULT \'\''); $conn->addColumn($t, 'udropship_vendor', 'int(11) unsigned'); $conn->addConstraint('FK_ADMIN_USER_VENDOR', $t, 'udropship_vendor', $vt, 'vendor_id'); $t = $this->getTable('admin_role'); $roleId = $conn->fetchOne("select role_id from {$t} where role_name='Dropship Vendor'"); if (!$roleId) { $conn->insert($t, array('tree_level' => 1, 'role_type' => 'G', 'role_name' => 'Dropship Vendor')); $roleId = $conn->lastInsertId($t); $rules = new Mage_Admin_Model_Rules(); $rules->setResources(array('admin/catalog', 'admin/catalog/products')); $rules->setRoleId($roleId)->saveRel(); } $ut = $this->getTable('admin_user'); $vendors = $conn->fetchAll("select * from {$this->getTable('udropship_vendor')}"); $coreHlp = new Mage_Core_Helper_Data(); foreach ($vendors as $v) { if ($conn->fetchOne("select user_id from {$ut} where username=?", $v['email'])) { continue; } $conn->insert($ut, array('firstname' => $v['vendor_name'], 'lastname' => $v['vendor_attn'], 'email' => $v['email'], 'username' => $v['email'], 'password' => $coreHlp->getHash($v['password'], 2), 'created' => now(), 'is_active' => 1, 'udropship_vendor' => $v['vendor_id'])); $userId = $conn->lastInsertId($ut); $conn->insert($t, array('parent_id' => $roleId, 'tree_level' => 2, 'role_type' => 'U', 'user_id' => $userId, 'role_name' => $v['vendor_name'])); } $this->run("\nCREATE TABLE IF NOT EXISTS `{$this->getTable('udropship_vendor_registration')}` (\n`reg_id` int(10) unsigned NOT NULL auto_increment,\n`store_id` smallint(5) unsigned NOT NULL,\n`vendor_name` varchar(255) default NULL,\n`telephone` varchar(255) default NULL,\n`email` varchar(255) default NULL,\n`password_enc` varchar(255) default NULL,\n`password_hash` varchar(255) default NULL,\n`carrier_code` varchar(64) default NULL,\n`vendor_attn` varchar(255) default NULL,\n`street` text,\n`city` varchar(255) default NULL,\n`zip` varchar(255) default NULL,\n`region_id` int(10) unsigned default NULL,\n`region` varchar(255) default NULL,\n`country_id` char(2) default NULL,\n`remote_ip` varchar(15) default NULL,\n`registered_at` datetime default NULL,\n`url_key` varchar(64) default NULL,\n`comments` text,\n`notes` text,\nPRIMARY KEY (`reg_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n"); $this->endSetup();
/** * Save import rows bunch. * * @param string $entity * @param string $behavior * @param array $data * @return int */ public function saveBunch($entity, $behavior, array $data) { return $this->_getWriteAdapter()->insert($this->getMainTable(), array('behavior' => $behavior, 'entity' => $entity, 'data' => $this->_jsonHelper->jsonEncode($data))); }
/** * Retrieve aliases to classes map if exit * * @return array */ protected function _getAliasesMap() { if (is_null($this->_aliasesMap)) { $this->_aliasesMap = array(); $map = $this->_loadMap($this->_pathToMapFile); if (!empty($map)) { $this->_aliasesMap = $this->_coreHelper->jsonDecode($map); } } return $this->_aliasesMap; }
/** * Return json-encoded list of existing behaviors * * @return string */ public function getUniqueBehaviors() { $importModel = $this->_importModel; $uniqueBehaviors = $importModel::getUniqueEntityBehaviors(); return $this->_coreHelper->jsonEncode(array_keys($uniqueBehaviors)); }