/** * Return Wysiwyg config as Varien_Object * * Config options description: * * enabled: Enabled Visual Editor or not * hidden: Show Visual Editor on page load or not * use_container: Wrap Editor contents into div or not * no_display: Hide Editor container or not (related to use_container) * translator: Helper to translate phrases in lib * files_browser_*: Files Browser (media, images) settings * encode_directives: Encode template directives with JS or not * * @param $data array constructor params to override default config values * @return Varien_Object */ public function getConfig($data = array()) { $config = new Varien_Object(); $config->setData(array('enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'translator' => Mage::helper('cms'), 'encode_directives' => true, 'directives_url' => Mage::getSingleton('adminhtml/url')->getUrl('*/cms_wysiwyg/directive'), 'popup_css' => Mage::getBaseUrl('js') . 'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css', 'content_css' => Mage::getBaseUrl('js') . 'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css', 'width' => '100%', 'plugins' => array())); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); if (Mage::getSingleton('admin/session')->isAllowed('cms/media_gallery')) { $config->addData(array('add_images' => true, 'files_browser_window_url' => Mage::getSingleton('adminhtml/url')->getUrl('*/cms_wysiwyg_images/index'), 'files_browser_window_width' => (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width'), 'files_browser_window_height' => (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height'))); } if (is_array($data)) { $config->addData($data); } Mage::dispatchEvent('cms_wysiwyg_config_prepare', array('config' => $config)); return $config; }
protected function _prepareForm() { $form = new Varien_Data_Form(); $dataObj = new Varien_Object(array('store_id' => '', 'store_name_in_store' => '', 'status_in_store' => '', 'description_in_store' => '', 'address_in_store' => '', 'city_in_store' => '')); if (Mage::getSingleton('adminhtml/session')->getStoreData()) { $data = Mage::getSingleton('adminhtml/session')->getStoreData(); Mage::getSingleton('adminhtml/session')->setStoreData(null); } elseif (Mage::registry('store_data')) { $data = Mage::registry('store_data')->getData(); } if (isset($data)) { $dataObj->addData($data); } if ($dataObj->getStoreId()) { $warehouse = Mage::getResourceModel('inventoryplus/warehouse_collection')->addFieldToFilter('storepickup_id', $dataObj->getStoreId())->getFirstItem(); $dataObj->setData('warehouse_id', $warehouse->getId()); $dataObj->setData('curr_warehouse_id', $warehouse->getId()); } $this->setForm($form); $fieldset = $form->addFieldset('store_form', array('legend' => Mage::helper('storepickup')->__('Warehouse Information'))); $fieldset->addField('warehouse_id', 'select', array('label' => Mage::helper('storepickup')->__('Linked Warehouse'), 'name' => 'warehouse_id', 'values' => $this->getWarehouseOptions(), 'onchange' => 'imStorePickup.changeWarehouse(this);', 'note' => $this->__('If you choose a warehouse, this Store information will be imported from the warehouse after saved.'))); $fieldset->addField('curr_warehouse_id', 'hidden', array('name' => 'curr_warehouse_id')); if (Mage::getSingleton('adminhtml/session')->getStoreData()) { $form->setValues(Mage::getSingleton('adminhtml/session')->getStoreData()); Mage::getSingleton('adminhtml/session')->setStoreData(null); } elseif (Mage::registry('store_data')) { $form->setValues($dataObj->getData()); } parent::_prepareForm(); }
private function getSearchResultCollection() { $collection = new Varien_Data_Collection(); $index = Mage::helper('searchindex/index')->getIndex('mage_catalog_product'); $storeId = $this->getStoreId(); if (($query = $this->getRequest()->getParam('q')) && $index) { $engine = Mage::helper('searchindex')->getSearchEngine(); $start = microtime(true); try { $result = $engine->query($query, $storeId, $index); } catch (Exception $e) { try { $engine = Mage::getModel('searchsphinx/engine_fulltext'); $result = $engine->query($query, $storeId, $index); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $result = array(); } } $end = microtime(true); $this->searchTime = round($end - $start, 4); foreach ($result as $productId => $relevance) { $varienObject = new Varien_Object(); $varienObject->addData(array('id' => $productId, 'relevance' => $relevance)); $collection->addItem($varienObject); } $this->resultSize = $collection->getSize(); } return $collection; }
/** * Adds GeoIP location html to order view * * @param Varien_Event_Observer $observer * @return MageWorx_CustomerLocation_Model_Observer */ public function orderLocation(Varien_Event_Observer $observer) { if (Mage::helper('mageworx_geolocation')->isEnabledForOrders()) { $_order = null; $block = $observer->getEvent()->getBlock(); $controller = Mage::app()->getRequest()->getControllerName(); if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View_Info && $controller == 'sales_order') { $_order = $block->getOrder(); } else { if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_View_Form && $controller == 'sales_order_shipment') { $_order = $block->getShipment()->getOrder(); } else { if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Invoice_View_Form && $controller == 'sales_order_invoice') { $_order = $block->getInvoice()->getOrder(); } } } if (!is_null($_order)) { $ip = $_order->getRemoteIp(); if (!$ip) { return $this; } $geoIpObj = Mage::getModel('mageworx_geoip/geoip')->getLocation($ip); if ($geoIpObj->getCode()) { $obj = new Varien_Object(); $obj->addData(array('geo_ip' => $geoIpObj, 'ip' => $ip)); $block->getOrder()->setRemoteIp(Mage::helper('mageworx_geolocation')->getGeoIpHtml($obj)); } } } return $this; }
/** * Extracts information from report's filepath * * @param string $filepath * @return Varien_Object */ public function extractDataFromFile($filepath) { // Read the unserialize content of the file $content = unserialize(file_get_contents($filepath)); // Loop through the array foreach ($content as $key => $value) { // Value with key = 0 is always the error message if (!$key) { $error = $value; } elseif ($key == "url") { $url = $value; } elseif ($key == "script_name") { $script_name = $value; } elseif ($key == "skin") { $skin = $value; } else { // The trace has the key = 1, we do it last $trace = $value; } } // Create the result object $result = new Varien_Object(); $result->addData(array('error' => $error ? $error : "", 'url' => $url ? $url : "", 'script_name' => $script_name ? $script_name : "", 'skin' => $skin ? $skin : "", 'trace' => $trace ? $trace : "", 'time' => filemtime($filepath))); return $result; }
/** * Loads the data from the Piwik instance and * ass assembles a collection with the live * users. * * @param array $params * Array with additional params for requesting the Piwik API * @return Varien_Data_Collection The collection with the live users */ public function getLastVisits(array $params) { try { // load the data and decode it $phpNative = $this->decode($params); // initialize the collection foreach ($phpNative as $date => $values) { // initialize an empty object $obj = new Varien_Object(); // pass the data if (is_array($values)) { $obj->addData($values); } // add the object to the collection $this->_collection->addItem($obj); } } catch (Exception $e) { // log the exception Mage::logException($e); // add an error to the session Mage::getSingleton('adminhtml/session')->addError(Mage::helper('piwik')->__('900.error.invalid.piwik-configuration')); } // return the collection return $this->_collection; }
public function popupajaxAction() { $response = new Varien_Object(); $response->setError(0); try { $pageName = $this->getRequest()->getParam('page'); if (!$pageName) { throw new Exception($this->__('PageType not found')); } $pageName = Mage::helper('core')->escapeHtml($pageName); $popup = Mage::helper('promotional')->getPopup($pageName); if (isset($popup['promotional_id'])) { Mage::helper('promotional')->setViewedPopup($popup['promotional_id']); $response->addData($popup->toArray()); $autoHideTime = Mage::helper('promotional')->getAutoHide(); if ($autoHideTime > 0) { $response->setAutoHideTime($autoHideTime); } } else { throw new Exception('Promotional Popup not found'); } } catch (Exception $e) { $response->setError(1); $response->setErrorMessage($e->getMessage()); } $this->getResponse()->setBody($response->toJson()); return; }
/** * Loads the data from the Piwik instance and * ass assembles a collection with the summary * of the visits for a given time. * * @param array $params * Array with additional params for requesting the Piwik API * @return Varien_Data_Collection The collection with the live users */ public function get(array $params) { try { // load the data and decode it $phpNative = $this->decode($params); // initialize the collection foreach ($phpNative as $date => $values) { // pass the data if (is_array($values)) { // check if a value for the unique visitors exists if (array_key_exists('nb_uniq_visitors', $values)) { // if yes, initialize an empty object $obj = new Varien_Object(); $obj->addData($values); $obj->setUsers($values['nb_uniq_visitors']); $obj->setRange($date); // add the object to the collection $this->_collection->addItem($obj); } } } } catch (Exception $e) { // log the exception Mage::logException($e); // add an error to the session Mage::getSingleton('adminhtml/session')->addError(Mage::helper('piwik')->__('900.error.invalid.piwik-configuration')); } // return the collection return $this->_collection; }
protected function _loadXmlElementCustomParams($element) { $params = array(); $sortOrder = 0; foreach ($element->asCanonicalArray() as $key => $data) { if (is_array($data)) { $data['sort_order'] = isset($data['sort_order']) ? (int) $data['sort_order'] : 'top'; // Prepare values (for dropdowns) specified directly in configuration $values = array(); if (isset($data['values']) && is_array($data['values'])) { foreach ($data['values'] as $value) { if (isset($value['label']) && isset($value['value'])) { $values[] = $value; } } } $data['values'] = $values; // Prepare helper block object if (isset($data['helper_block'])) { $helper = new Varien_Object(); if (isset($data['helper_block']['data']) && is_array($data['helper_block']['data'])) { $helper->addData($data['helper_block']['data']); } if (isset($data['helper_block']['type'])) { $helper->setType($data['helper_block']['type']); } $data['helper_block'] = $helper; } $params[$key] = $data; $sortOrder++; } } return $params; }
protected function _prepareForm() { $form = new Varien_Data_Form(); $dataObj = new Varien_Object(array('package_name', 'description', 'package_status')); $this->setForm($form); if (Mage::getSingleton('adminhtml/session')->getStoreData()) { $data = Mage::getSingleton('adminhtml/session')->getStoreData(); Mage::getSingleton('adminhtml/session')->setStoreData(null); } elseif (Mage::registry('package_data')) { $data = Mage::registry('package_data')->getData(); } if (isset($data)) { $dataObj->addData($data); } $data = $dataObj->getData(); $this->setForm($form); $inStore = $this->getRequest()->getParam('store'); $defaultLabel = Mage::helper('membership')->__('Use Default'); $defaultTitle = Mage::helper('membership')->__('-- Please Select --'); $scopeLabel = Mage::helper('membership')->__('STORE VIEW'); $websiteLabel = Mage::helper('membership')->__('WEBSITE'); $fieldset = $form->addFieldset('membership_form', array('legend' => Mage::helper('membership')->__('Item information'))); $fieldset->addField('package_name', 'text', array('label' => Mage::helper('membership')->__('Name'), 'class' => 'required-entry', 'required' => true, 'name' => 'package_name', 'disabled' => $inStore && !$data['package_name_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="package_name_default" name="package_name_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['package_name_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="package_name_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('package_price', 'text', array('label' => Mage::helper('membership')->__('Price'), 'required' => true, 'name' => 'package_price')); $fieldset->addField('package_product_price', 'text', array('label' => Mage::helper('membership')->__('Product Price'), 'name' => 'package_product_price', 'class' => 'required-entry', 'required' => true)); $fieldset->addField('custom_option_discount', 'select', array('label' => Mage::helper('membership')->__('Custom Option Discount'), 'name' => 'custom_option_discount', 'required' => true, 'values' => array(array('value' => 'yes', 'label' => Mage::helper('membership')->__('Yes')), array('value' => 'no', 'label' => Mage::helper('membership')->__('No'))))); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('duration', 'text', array('label' => Mage::helper('membership')->__('Duration'), 'required' => true, 'name' => 'duration', 'note' => 'months')); $fieldset->addField('description', 'editor', array('name' => 'description', 'label' => Mage::helper('membership')->__('Description'), 'wysiwyg' => false, 'required' => false, 'disabled' => $inStore && !$data['description_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="description_default" name="description_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['description_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="description_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('sort_order', 'text', array('name' => 'sort_order', 'label' => Mage::helper('membership')->__('Sort Order'), 'required' => true)); $fieldset->addField('package_status', 'select', array('label' => Mage::helper('membership')->__('Status'), 'name' => 'package_status', 'required' => true, 'values' => array(array('value' => 1, 'label' => Mage::helper('membership')->__('Enabled')), array('value' => 2, 'label' => Mage::helper('membership')->__('Disabled'))), 'disabled' => $inStore && !$data['package_status_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="package_status_default" name="package_status_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['package_status_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="package_status_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $websiteLabel . '] ' : '</td><td class="scope-label"> [' . $websiteLabel . ']')); if (Mage::getSingleton('adminhtml/session')->getPackageData()) { $form->setValues(Mage::getSingleton('adminhtml/session')->getPackageData()); Mage::getSingleton('adminhtml/session')->setPackageData(null); } elseif (Mage::registry('package_data')) { $form->setValues(Mage::registry('package_data')->getData()); } return parent::_prepareForm(); }
/** * Tests Varien_Object->addData() */ public function testAddData() { $this->_object->addData(array('test' => 'value')); $this->assertEquals('value', $this->_object->getData('test')); $this->_object->addData(array('test' => 'value1')); $this->assertEquals('value1', $this->_object->getData('test')); $this->_object->addData(array('test2' => 'value2')); $this->assertEquals(array('test' => 'value1', 'test2' => 'value2'), $this->_object->getData()); }
/** * Assign data to info model instance * * @param Varien_Object|Array $data * @return TemplateTag_Stripe_Model_Payment */ public function assignData($data) { if (is_array($data)) { $data = new Varien_Object($data); } try { $token = $this->getToken($data->getStripeToken()); $data->addData(array('cc_last4' => $token->card->last4, 'cc_type' => $token->card->type, 'cc_owner' => $token->card->name)); } catch (Exception $e) { } $data->setData('stripe_test', $this->_getHelper()->getTest()); return parent::assignData($data); }
public function _prepareCollection() { $collection = new Varien_Data_Collection(); $page_list = $this->getImportPage(); foreach ($page_list->page as $key => $v) { $data = new Varien_Object(); $data->setData('page_id', $key); $data->addData(Mage::helper('themeframework/managetheme')->_xmlToArray($v)); $collection->addItem($data); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Retrieve form data * * @return Varien_Object */ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { $formData = Mage::getSingleton('customer/session')->getRegistrationFormData(true); $data = new Varien_Object(); if ($formData) { $data->addData($formData); } $this->setData('form_data', $data); } return $data; }
/** * Load data into object * * @param bool $printQuery * @param bool $logQuery * @return Ebizmarts_MageMonkey_Model_Custom_Collection */ public function load($printQuery = false, $logQuery = false) { if ($this->isLoaded() || is_null($this->_toload)) { return $this; } foreach ($this->_toload as $row) { $item = new Varien_Object(); $item->addData($row); $this->addItem($item); } $this->_setIsLoaded(); return $this; }
public function _prepareCollection() { $collection = new Varien_Data_Collection(); //Mage::getResourceSingleton('themeframework/theme_list'); $block_list = $this->getImportSlideshow(); foreach ($block_list->slideshow as $key => $v) { $data = new Varien_Object(); $data->setData('block_id', $key); $data->addData(Mage::helper('themeframework/managetheme')->_xmlToArray($v)); $collection->addItem($data); } $this->setCollection($collection); return parent::_prepareCollection(); }
public function jsonProductInfoAction() { $response = new Varien_Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = Mage::getModel('catalog/product')->load($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(Mage::helper('catalog')->__('Unable to get the product ID.')); } $this->getResponse()->setBody($response->toJSON()); }
protected function _getSearchableEntities($storeId, $entityIds, $lastEntityId, $limit = 100) { if ($lastEntityId) { return new Varien_Data_Collection(); } $attributeCode = $this->getIndexModel()->getProperty('attribute'); $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); $options = $attribute->getSource()->getAllOptions(false); $collection = new Varien_Data_Collection(); foreach ($options as $option) { $obj = new Varien_Object(); $obj->addData($option); $collection->addItem($obj); } return $collection; }
public function load($printQuery = false, $logQuery = false) { if ($this->isLoaded() || is_null($this->_emailCollection)) { return $this; } $ext = array(); foreach ($this->_emailCollection as $row) { $item = new Varien_Object(); $ext['type'] = 'email'; $ext['emailadress'] = $row; $item->addData($ext); $this->addItem($item); } $this->_setIsLoaded(); return $this; }
public function getCollection() { $matchedIds = $this->getMatchedIds(); $attributeCode = $this->getProperty('attribute'); $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); $options = $attribute->getSource()->getAllOptions(false); $collection = new Varien_Data_Collection(); foreach ($options as $option) { if (isset($matchedIds[$option['value']])) { $obj = new Varien_Object(); $obj->addData($option); $collection->addItem($obj); } } return $collection; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (is_array($data)) { $data = new Varien_Object($data); } try { $paymentRequest = Mage::app()->getRequest()->getPost('payment'); $data->addData(array('cc_last4' => substr($data->cc_number, -4), 'cc_exp_year' => '', 'cc_exp_month' => '')); $info = $this->getInfoInstance(); $this->_openpay_token = $paymentRequest['openpay_token']; $this->_device_session_id = $paymentRequest['device_session_id']; $info->setOpenpayToken($paymentRequest['openpay_token'])->setDeviceSessionId($paymentRequest['device_session_id']); } catch (Exception $e) { } return parent::assignData($data); }
/** * Retrieve form data * * @return Varien_Object */ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { $formData = Mage::getSingleton('customer/session')->getCustomerFormData(true); $data = new Varien_Object(); if ($formData) { $data->addData($formData); $data->setCustomerData(1); } if (isset($data['region_id'])) { $data['region_id'] = (int) $data['region_id']; } $this->setData('form_data', $data); } return $data; }
protected function createMagentoGridFromArray(array $data) { $collection = new Varien_Data_Collection(); foreach ($data as $key => $value) { $tempObj = new Varien_Object(); $tempObj->addData($value); $collection->addItem($tempObj); } /** @var $grid Mage_Adminhtml_Block_Widget_Grid */ $grid = Mage::getBlockSingleton('adminhtml/Widget_Grid'); $grid->setCollection($collection); $grid->addColumn('title', array('header' => Mage::helper('M2ePro')->__('Title'), 'type' => 'title', 'width' => '350px', 'index' => 'title', 'filter' => false, 'sortable' => false)); $grid->addColumn('marketplace_title', array('header' => Mage::helper('M2ePro')->__('Marketplaces'), 'type' => 'text', 'width' => '200px', 'index' => 'marketplace_title', 'filter' => false, 'sortable' => false)); $grid->addColumn('category_path', array('header' => Mage::helper('M2ePro')->__('Category'), 'type' => 'text', 'index' => 'category_path', 'filter' => false, 'sortable' => false)); $grid->setFilterVisibility(false); $grid->setPagerVisibility(false); return $grid; }
/** * Loads the data from the Piwik instance and * ass assembles a collection with the live * users. * * @param array $params * Array with additional params for requesting the Piwik API * @return Varien_Data_Collection The collection with the live users */ public function getLastVisits(array $params) { // load the data and decode it $phpNative = $this->decode($params); // initialize the collection foreach ($phpNative as $date => $values) { // initialize an empty object $obj = new Varien_Object(); // pass the data if (is_array($values)) { $obj->addData($values); } // add the object to the collection $this->_collection->addItem($obj); } // return the collection return $this->_collection; }
public function render(Varien_Data_Form_Element_Abstract $element) { if ($element->hasData('emt_temp_editor') && $element->hasData('emt_temp_text')) { $editorElement = $element->getData('emt_temp_editor'); $textElement = $element->getData('emt_temp_text'); $virtualElement = new Varien_Object(); $attributes = array('note', 'fieldset_html_class', 'no_display', 'type', 'value_class', 'html_id', 'required'); foreach ($attributes as $attribute) { if ($element->hasData($attribute)) { $virtualElement->setData($attribute, $element->getData($attribute)); } } $textElement->setValue($element->getValue())->getHtml(); $editorElement->setTextInputHtml($textElement->getElementHtml()); $virtualElement->addData(array('id' => $element->getId(), 'label_html' => $element->getLabelHtml(), 'html_container_id' => $element->getHtmlContainerId(), 'element_html' => $editorElement->getHtml())); $this->_element = $virtualElement; return $this->toHtml(); } return parent::render($element); }
public function _construct() { $order = Mage::registry('current_order'); $this->setOrder($order); $items = Mage::helper('enterprise_rma')->getOrderItems($order); $this->setItems($items); $session = Mage::getSingleton('core/session'); $formData = $session->getRmaFormData(true); if (!empty($formData)) { $data = new Varien_Object(); $data->addData($formData); $this->setFormData($data); } $errorKeys = $session->getRmaErrorKeys(true); if (!empty($errorKeys)) { $data = new Varien_Object(); $data->addData($errorKeys); $this->setErrorKeys($data); } }
/** * Prepare collection of errors * * @return Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Grid */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $removeButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button', '', array('class' => 'delete', 'label' => '', 'onclick' => 'addBySku.removeFailedItem(this)', 'type' => 'button'))->toHtml(); /* @var $parentBlock Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Abstract */ $parentBlock = $this->getParentBlock(); foreach ($parentBlock->getFailedItems() as $affectedItem) { // Escape user-submitted input if (isset($affectedItem['item']['qty'])) { $affectedItem['item']['qty'] = empty($affectedItem['item']['qty']) ? '' : (double) $affectedItem['item']['qty']; } $item = new Varien_Object(); $item->setCode($affectedItem['code']); if (isset($affectedItem['error'])) { $item->setError($affectedItem['error']); } $item->addData($affectedItem['item']); $item->setId($item->getSku()); /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); if (isset($affectedItem['item']['id'])) { $productId = $affectedItem['item']['id']; $item->setProductId($productId); $product->load($productId); /* @var $stockStatus Mage_CatalogInventory_Model_Stock_Status */ $stockStatus = Mage::getModel('cataloginventory/stock_status'); $status = $stockStatus->getProductStatus($productId, $this->getWebsiteId()); if (!empty($status[$productId])) { $product->setIsSalable($status[$productId]); } $item->setPrice(Mage::helper('core')->formatPrice($product->getPrice())); } $descriptionBlock = $this->getLayout()->createBlock('enterprise_checkout/adminhtml_sku_errors_grid_description', '', array('product' => $product, 'item' => $item)); $item->setDescription($descriptionBlock->toHtml()); $item->setRemoveButton($removeButtonHtml); $collection->addItem($item); } $this->setCollection($collection); return $this; }
public function createTransaction($amount = 0, $action = '', $title = '', $customer = null, $rewardCustomer = null, $extraContent = array()) { $expiration_date = null; if ($amount > 0) { $expiration_date = isset($extraContent['expiration_date']) ? $extraContent['expiration_date'] : $this->getExpirationDate(); } if (isset($extraContent['notice'])) { $extraContent['notice'] = htmlspecialchars($extraContent['notice']); } if (is_array($extraContent['extra_content'])) { $extra_content = new Varien_Object($extraContent['extra_content']); $extraContent['extra_content'] = $extra_content->serialize(null, '=', '&', ''); } $this->addData($extraContent)->setTitle($title)->setCustomerId($customer->getId())->setAction($action)->setCreateAt(Mage::getModel('core/date')->gmtDate())->setExpirationDate($expiration_date)->setPointsChange($amount)->setPointsSpent(0)->setIsExpired(0)->save(); if (is_array($extraContent['customer_extra_content'])) { parse_str($rewardCustomer->getExtraContent(), $current_customer_extra_content); $customerExtraContent = new Varien_Object($current_customer_extra_content); $customerExtraContent->addData($extraContent['customer_extra_content']); $rewardCustomer->setExtraContent($customerExtraContent->serialize(null, '=', '&', '')); } $rewardCustomer->setTotalPoints($rewardCustomer->getTotalPoints() + $amount)->save(); return $this; }
/** * Loads the data from the Piwik instance and * ass assembles a collection with the summary * of the visits for a given time. * * @param array $params * Array with additional params for requesting the Piwik API * @return Varien_Data_Collection The collection with the live users */ public function get(array $params) { // load the data and decode it $phpNative = $this->decode($params); // initialize the collection foreach ($phpNative as $date => $values) { // pass the data if (is_array($values)) { // check if a value for the unique visitors exists if (array_key_exists('nb_uniq_visitors', $values)) { // if yes, initialize an empty object $obj = new Varien_Object(); $obj->addData($values); $obj->setUsers($values['nb_uniq_visitors']); $obj->setRange($date); // add the object to the collection $this->_collection->addItem($obj); } } } // return the collection return $this->_collection; }
protected function _prepareForm() { $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('affiliateplusprogram_'); $dataObj = new Varien_Object(array('program_id' => '', 'discount_in_store' => '', 'commission_in_store' => '', 'discount_type_in_store' => '', 'commission_type_in_store' => '')); if (Mage::getSingleton('adminhtml/session')->getAffiliateplusprogramData()) { $data = Mage::getSingleton('adminhtml/session')->getAffiliateplusprogramData(); $programId = isset($data['program_id']) ? $data['program_id'] : 0; $model = Mage::getModel('affiliateplusprogram/program')->load($programId)->setData($data); Mage::getSingleton('adminhtml/session')->setAffiliateplusprogramData(null); } elseif (Mage::registry('affiliateplusprogram_data')) { $model = Mage::registry('affiliateplusprogram_data'); $data = $model->getData(); } if (isset($data)) { $dataObj->addData($data); } $data = $dataObj->getData(); $this->setForm($form); $fieldset = $form->addFieldset('affiliateplusprogram_actions_commission', array('legend' => Mage::helper('affiliateplusprogram')->__('Commission'))); $inStore = $this->getRequest()->getParam('store'); $defaultLabel = Mage::helper('affiliateplusprogram')->__('Use Default'); $defaultTitle = Mage::helper('affiliateplusprogram')->__('-- Please Select --'); $scopeLabel = Mage::helper('affiliateplusprogram')->__('STORE VIEW'); $fieldset->addField('affiliate_type', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Pay commission'), 'name' => 'affiliate_type', 'values' => Mage::getSingleton('affiliateplusprogram/system_config_source_type')->toOptionArray(), 'disabled' => $inStore && !$data['affiliate_type_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="affiliate_type_default" name="affiliate_type_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['affiliate_type_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliate_type_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('commission_type', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Commission Type'), 'name' => 'commission_type', 'values' => Mage::getSingleton('affiliateplus/system_config_source_fixedpercentage')->toOptionArray(), 'disabled' => $inStore && !$data['commission_type_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="commission_type_default" name="commission_type_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['commission_type_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="commission_type_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('commission', 'text', array('label' => Mage::helper('affiliateplusprogram')->__('Commission Value'), 'required' => true, 'name' => 'commission', 'disabled' => $inStore && !$data['commission_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="commission_default" name="commission_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['commission_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="commission_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('sec_commission', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Use different commission from 2nd order of a Customer'), 'name' => 'sec_commission', 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(), 'disabled' => $inStore && !$data['sec_commission_in_store'], 'after_element_html' => '<p class="note">' . Mage::helper('affiliateplusprogram')->__('Select "No" to apply the above commission to all orders') . '</p>' . ($inStore ? '</td><td class="use-default"> <input id="sec_commission_default" name="sec_commission_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['sec_commission_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="sec_commission_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']'))); $fieldset->addField('sec_commission_type', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Commission Type (from 2nd order)'), 'name' => 'sec_commission_type', 'values' => Mage::getSingleton('affiliateplus/system_config_source_fixedpercentage')->toOptionArray(), 'disabled' => $inStore && !$data['sec_commission_type_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="affiliateplusprogram_sec_commission_type_inherit" name="sec_commission_type_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['sec_commission_type_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliateplusprogram_sec_commission_type_inherit" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('secondary_commission', 'text', array('label' => Mage::helper('affiliateplusprogram')->__('Commission Value (from 2nd order)'), 'name' => 'secondary_commission', 'disabled' => $inStore && !$data['secondary_commission_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="affiliateplusprogram_secondary_commission_inherit" name="secondary_commission_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['secondary_commission_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliateplusprogram_secondary_commission_inherit" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); Mage::dispatchEvent('affiliateplusprogram_adminhtml_edit_actions', array('form' => $form, 'form_data' => $data, 'fieldset' => $fieldset, 'in_store' => $inStore)); $fieldset = $form->addFieldset('affiliateplusprogram_actions_discount', array('legend' => Mage::helper('affiliateplusprogram')->__('Discount'))); $fieldset->addField('discount_type', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Discount Type'), 'name' => 'discount_type', 'values' => Mage::getSingleton('affiliateplus/system_config_source_discounttype')->toOptionArray(), 'disabled' => $inStore && !$data['discount_type_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="discount_type_default" name="discount_type_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['discount_type_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="discount_type_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('discount', 'text', array('label' => Mage::helper('affiliateplusprogram')->__('Discount Value'), 'required' => true, 'name' => 'discount', 'disabled' => $inStore && !$data['discount_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="discount_default" name="discount_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['discount_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="discount_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('sec_discount', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Use different discount from 2nd order of a Customer'), 'name' => 'sec_discount', 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(), 'disabled' => $inStore && !$data['sec_discount_in_store'], 'after_element_html' => '<p class="note">' . Mage::helper('affiliateplusprogram')->__('Select "No" to apply above discount for all orders') . '</p>' . ($inStore ? '</td><td class="use-default"> <input id="affiliateplusprogram_sec_discount_inherit" name="sec_discount_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['sec_discount_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliateplusprogram_sec_discount_inherit" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']'))); $fieldset->addField('sec_discount_type', 'select', array('label' => Mage::helper('affiliateplusprogram')->__('Discount Type (from 2nd order)'), 'name' => 'sec_discount_type', 'values' => Mage::getSingleton('affiliateplus/system_config_source_discounttype')->toOptionArray(), 'disabled' => $inStore && !$data['sec_discount_type_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="affiliateplusprogram_sec_discount_type_inherit" name="sec_discount_type_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['sec_discount_type_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliateplusprogram_sec_discount_type_inherit" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('secondary_discount', 'text', array('label' => Mage::helper('affiliateplusprogram')->__('Discount Value (from 2nd order)'), 'name' => 'secondary_discount', 'disabled' => $inStore && !$data['secondary_discount_in_store'], 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="affiliateplusprogram_secondary_discount_inherit" name="secondary_discount_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['secondary_discount_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="affiliateplusprogram_secondary_discount_inherit" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $fieldset->addField('customer_group_ids', 'multiselect', array('label' => Mage::helper('affiliateplusprogram')->__('Customer Groups Applied'), 'required' => false, 'values' => Mage::getResourceModel('customer/group_collection')->load()->toOptionArray(), 'name' => 'customer_group_ids', 'disabled' => $inStore && !$data['customer_group_ids_in_store'], 'after_element_html' => '<p class="note">' . Mage::helper('affiliateplusprogram')->__('Discount is applied to customers who buy products directly. Select none for all customers.') . '</p>' . ($inStore ? '</td><td class="use-default"> <input id="customer_group_ids_default" name="customer_group_ids_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($data['customer_group_ids_in_store'] ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="customer_group_ids_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']'))); $model->setData('actions', $model->getData('actions_serialized')); $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')->setTemplate('promo/fieldset.phtml')->setNewChildUrl($this->getUrl('adminhtml/promo_quote/newActionHtml/form/affiliateplusprogram_actions_fieldset')); Mage::dispatchEvent('affiliateplusprogram_adminhtml_edit_actions_discount', array('fieldset' => $fieldset, 'form' => $form, 'form_data' => $data)); $fieldset = $form->addFieldset('actions_fieldset', array('legend' => Mage::helper('affiliateplusprogram')->__('Apply the program only to cart items matching the following conditions (leave blank for all items)')))->setRenderer($renderer); $fieldset->addField('actions', 'text', array('name' => 'actions', 'label' => Mage::helper('affiliateplusprogram')->__('Apply To'), 'title' => Mage::helper('affiliateplusprogram')->__('Apply To'), 'required' => true))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/actions')); $form->setValues($data); $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')->addFieldMap('affiliateplusprogram_sec_commission', 'use_commission')->addFieldMap('affiliateplusprogram_sec_commission_type', 'commission_type')->addFieldMap('affiliateplusprogram_secondary_commission', 'commission')->addFieldDependence('commission_type', 'use_commission', '1')->addFieldDependence('commission', 'use_commission', '1')->addFieldMap('affiliateplusprogram_sec_discount', 'use_discount')->addFieldMap('affiliateplusprogram_sec_discount_type', 'discount_type')->addFieldMap('affiliateplusprogram_secondary_discount', 'discount')->addFieldDependence('discount_type', 'use_discount', '1')->addFieldDependence('discount', 'use_discount', '1')); return parent::_prepareForm(); }