/** * Processing file data * * @param string $text * @return string */ public function processFileData($text) { $template = Mage::getModel('core/email_template_filter'); if (null === $this->_wsdlVariables) { $this->_wsdlVariables = new Varien_Object(); $this->_wsdlVariables->setUrl(Mage::getUrl('*/*/*')); $this->_wsdlVariables->setName('Magento'); $this->_wsdlVariables->setHandler($this->getHandler()); } $template->setVariables(array('wsdl' => $this->_wsdlVariables)); $text = $template->filter($text); return $text; }
public function getCustomerByPost($params) { $customer = $this->_getCustomer(); // Patch for custom Contact Us form with ability to change email or name of customer (HDMX-98) if ($customer->getId() > 0 && !isset($params['customer_email']) && !isset($params['customer_name'])) { return $customer; } $email = $params['customer_email']; $name = $params['customer_name']; $customers = Mage::getModel('customer/customer')->getCollection(); $customers->addAttributeToSelect('*')->addAttributeToFilter('email', $email); if ($customers->count() > 0) { return $customers->getFirstItem(); } $c = Mage::getModel('customer/customer'); $c->getEmail(); $c->setEmail('aaa'); /** @var Mage_Customer_Model_Customer $address */ $address = $customers->getFirstItem(); if ($address->getId()) { $customer = new Varien_Object(); $customer->setName($address->getName()); $customer->setEmail($address->getEmail()); $customer->setQuoteAddressId($address->getId()); return $customer; } $customer = new Varien_Object(); $customer->setName($name); $customer->setEmail($email); return $customer; }
/** * Converts map array to microdata Object * * @param array $map map array returned by the generator * @return null|Varien_Object */ protected function _createRowObject($map) { if (empty($map['price']) || empty($map['availability']) || empty($map['title'])) { return null; } $microdata = new Varien_Object(); $microdata->setName($map['title']); $microdata->setId($map['id']); if (!empty($map['sale_price'])) { $price = $map['sale_price']; } else { $price = $map['price']; } $microdata->setPrice(Zend_Locale_Format::toNumber($price, array('precision' => 2, 'number_format' => '#0.00'))); $microdata->setCurrency(Mage::app()->getStore()->getCurrentCurrencyCode()); if ($map['availability'] == 'in stock') { $microdata->setAvailability('http://schema.org/InStock'); } else { $microdata->setAvailability('http://schema.org/OutOfStock'); } if (array_key_exists('condition', $map)) { if (strcasecmp('new', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/NewCondition'); } else { if (strcasecmp('used', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/UsedCondition'); } else { if (strcasecmp('refurbished', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/RefurbishedCondition'); } } } } return $microdata; }
public function saveAction() { if ($data = $this->getRequest()->getPost()) { // $id = $this->getRequest()->getParam('id'); $model = Mage::getModel('askit/askIt'); //update exist if (!empty($data['id'])) { $model->setData($data); $id = (int) $data['id']; $model->setId($id); } else { //new question create $model->setText(strip_tags($data['text']))->setProductId((int) $data['product_id'])->setHint((int) $data['hint'])->setParentId(null)->setStoreId($data['store_id'])->setEmail($data['email'])->setStatus((int) $data['status'])->setCreatedTime($data['created_time']); $customer = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter(array(array('attribute' => 'email', 'like' => $data['email'])))->getFirstItem(); if ($customer) { $model->setCustomerName($customer->getName())->setCustomerId($customer->getId()); } $model->save(); $id = (int) $model->getId(); } try { if ($model->getCreatedTime() == NULL || $model->getUpdateTime() == NULL) { $model->setCreatedTime(now())->setUpdateTime(now()); } else { $model->setUpdateTime(now()); } $model->save(); //add new answer if (!empty($data['new_answer_text'])) { $newAnswer = Mage::getModel('askit/askIt'); $adminUser = Mage::getSingleton('admin/session')->getUser(); $newAnswer->setParentId($id)->setStatus(2)->setStoreId($data['store_id'])->setText($data['new_answer_text'])->setProductId($data['product_id'])->setHint(0)->setCustomerName($adminUser->getFirstname() . ' ' . $adminUser->getLastname())->setEmail($adminUser->getEmail())->setCreatedTime(now())->setUpdateTime(now())->save(); if (Mage::getStoreConfig('askit/email/enableCustomerNotification')) { $emailData = new Varien_Object(); $question = Mage::getModel('askit/askIt')->load($id); $product = Mage::getSingleton('catalog/product')->load($newAnswer->getProductId()); $storeId = $question->getStoreId(); $emailData->setName($question->getCustomerName())->setProduct($product->getName())->setProductLink($product->getUrlModel()->getUrl($product, array('_store' => $storeId)))->setText($model->getText())->setAnswer($newAnswer->getText())->setAdminUserEmail($adminUser->getEmail())->setCustomerEmail($question->getEmail())->setStoreId($storeId); $this->_sendCustomerNotification($emailData); } } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('askit')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setFormData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } $this->_redirect('*/*/'); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setFormData($data); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } Mage::getSingleton('adminhtml/session')->addError(Mage::helper('askit')->__('Unable to find item to save')); $this->_redirect('*/*/'); }
public function extractRefundLine($order, $amount) { $_extract = new Varien_Object(); $_extract->setName('Refund / Correction'); $_extract->setPrice($amount); $_extract->setTaxAmount(0); $_extract->setQtyOrdered(1); return $_extract; }
/** * Get array of wizard steps * * array($inndex => Varien_Object ) * * @return array */ public function getWizardSteps() { $steps = array(); foreach ((array) $this->getNode(self::XML_PATH_WIZARD_STEPS) as $stepName => $step) { $stepObject = new Varien_Object((array) $step); $stepObject->setName($stepName); $steps[] = $stepObject; } return $steps; }
/** * Get wsdl config * * @return Varien_Object */ protected function _getWsdlConfig() { $wsdlConfig = new Varien_Object(); $queryParams = $this->getController()->getRequest()->getQuery(); if (isset($queryParams['wsdl'])) { unset($queryParams['wsdl']); } $wsdlConfig->setUrl(htmlspecialchars(Mage::getUrl('*/*/*', array('_query' => $queryParams)))); $wsdlConfig->setName('Magento'); $wsdlConfig->setHandler($this->getHandler()); return $wsdlConfig; }
/** * Returns founded customer or preset entity * @return Mage_Customer_Model_Customer | Varien_Object */ public function getCustomer(AW_Helpdeskultimate_Model_Proto $proto) { if ($customer = $this->_findCustomer($this->getFromEmail($proto))) { // Found existing customer return $customer; } else { // No customer found $customer = new Varien_Object(); $customer->setName($proto->getFrom())->setEmail($this->getFromEmail($proto)); return $customer; } }
protected function _prepareProduct(array $productRow) { $product = new Varien_Object(); $product->setId($productRow[$this->getIdFieldName()]); $id = $product->getId(); $productMedia = Mage::getModel('catalog/product')->load($id)->getImage(); $product->setMedia($productMedia); $productName = Mage::getModel('catalog/product')->load($id)->getName(); $product->setName($productName); $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); $product->setUrl($productUrl); return $product; }
/** * @test * @loadFixture data * * @doNotIndex catalog_product_price */ public function last_reply_byTest() { $ticket = Mage::getModel('helpdesk/ticket')->load(2); $rule = Mage::getModel('helpdesk/rule')->load(2); $rule->setConditionsSerialized($this->getConditions('last_reply_by', '==', 'customer')); $rule->afterLoad(); $this->assertFalse($rule->validate($ticket)); $customer = new Varien_Object(); $customer->setName('John Doe'); $customer->setEmail('*****@*****.**'); $ticket->addMessage('message 1', $customer, false, true); $this->assertTrue($rule->validate($ticket)); }
/** * @test * @loadFixture data * * @doNotIndex catalog_product_price */ public function addMessageUnknownCustomerTest() { $customer = new Varien_Object(); $customer->setName('John Doe'); $customer->setEmail('*****@*****.**'); $this->_model->addMessage('message 1', $customer, false, true); $message = Mage::getModel('helpdesk/message')->getCollection()->getLastItem(); $this->assertEquals('message 1', $message->getBody()); $this->assertEquals(2, $message->getTicketId()); $this->assertEquals(Mirasvit_Helpdesk_Model_Config::MESSAGE_PUBLIC, $message->getType()); $this->assertEquals('John Doe', $message->getCustomerName()); $this->assertEquals('*****@*****.**', $message->getCustomerEmail()); $this->assertEquals('John Doe', $this->_model->getLastReplyName()); }
/** * Retrieve actions collection * * @return array * @throws Exception */ protected function _getActions() { $config = Mage::getSingleton('smile_magecache/config'); $actionsConfig = $config->getActionConfig(); $items = array(); $i = 0; foreach ($actionsConfig as $code => $actionConfig) { $action = new Varien_Object(); $action->setPosition($i++); $action->setCode($actionConfig->getCode()); $action->setName($actionConfig->getModel()->getLabel()); $action->setDescription($actionConfig->getModel()->getDescription()); $items[] = $action; } return $items; }
/** * initialize * * @access public * @author Ultimate Module Creator */ public function __construct() { $customerSession = Mage::getSingleton('customer/session'); parent::__construct(); $data = Mage::getSingleton('customer/session')->getPopupCommentFormData(true); $data = new Varien_Object($data); // add logged in customer name as nickname if (!$data->getName()) { $customer = $customerSession->getCustomer(); if ($customer && $customer->getId()) { $data->setName($customer->getFirstname()); $data->setEmail($customer->getEmail()); } } $this->setAllowWriteCommentFlag($customerSession->isLoggedIn() || Mage::getStoreConfigFlag('iou_ultimatepopup/popup/allow_guest_comment')); if (!$this->getAllowWriteCommentFlag()) { $this->setLoginLink(Mage::getUrl('customer/account/login/', array(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array('_current' => true)) . '#comment-form')))); } $this->setCommentData($data); }
protected function _prepareCollection() { /** @var $connector Smile_DigitalOceanManager_Model_Connector*/ $connector = Mage::getModel('digitaloceanmanager/connector'); $droplets = $connector->getDropletList(); $collection = new Varien_Data_Collection(); foreach ($droplets as $droplet) { $obj = new Varien_Object(); $obj->setId($droplet->id); $obj->setName($droplet->name); $obj->setVcpus($droplet->vcpus); $obj->setMemory($droplet->memory); $obj->setDisk($droplet->disk); $obj->setStatus($droplet->status); $obj->setRegion($droplet->region->name); $collection->addItem($obj); } $this->setCollection($collection); return parent::_prepareCollection(); }
public function collectionsAction() { $thing_1 = new Varien_Object(); $thing_1->setName('david'); $thing_1->setAge('27'); $thing_1->setLastName('Smith'); $thing_2 = new Varien_Object(); $thing_2->setName('Jane'); $thing_2->setAge(12); $thing_3 = new Varien_Object(); $thing_3->setName('Spot'); $thing_3->setLastName('The Dog'); $thing_3->setAge(7); //var_dump($thing_3->getData()); //var_dump($thing_3["last_name"]); /*Definiremos ahora una serie de collections*/ $collection_of_things = new Varien_Data_Collection(); $collection_of_things->addItem($thing_1)->addItem($thing_2)->addItem($thing_3); foreach ($collection_of_things as $thing) { var_dump($thing->getData()); } echo "<br><br>"; echo "obteniendo el primer y último elemento"; echo "<br><br>"; var_dump($collection_of_things->getFirstItem()); var_dump($collection_of_things->getLastItem()->getData()); echo "<br><br>"; echo "Ahora como xml"; var_dump($collection_of_things->toXml()); echo '<br><br>'; echo 'ahora obtenemos solo las columnas identificadas como name'; echo '<br><br>'; var_dump($collection_of_things->getColumnValues('name')); echo '<br><br>'; echo 'El equipo de Magento nos permite realizar filtrados, ejemplo para el nombre david'; echo '<br/><br>'; var_dump($collection_of_things->getItemsByColumnValue('name', 'Spot')); }
public function getCustomerInfoFromOrder($order) { $billingAddress = $order->getBillingAddress(); $address = new Varien_Object(); $address->setStreet($billingAddress->getStreet(1)); $address->setStreetNumber($billingAddress->getStreet(2)); $address->setComplementary($billingAddress->getStreet(3)); // optional $address->setNeighborhood($billingAddress->getStreet(4)); $address->setZipcode(Zend_Filter::filterStatic($billingAddress->getPostcode(), 'Digits')); $customer = new Varien_Object(); $customer->setName($order->getCustomerName()); $customer->setDocumentNumber($order->getCustomerTaxvat()); $customer->setEmail($order->getCustomerEmail()); $customer->setPhone($this->splitTelephone($billingAddress->getTelephone())); $customer->setSex($this->formatGender($order->getCustomerGender())); // optional $customer->setBornAt($this->formatDob($order->getCustomerDob())); // optional $customer->setAddress($address); Mage::dispatchEvent('pagarme_get_customer_info_from_order_after', array('order' => $order, 'customer_info' => $customer)); return $customer; }
/** * Returns Google Base recommended Item Types * * @param string $targetCountry Two-letters country ISO code * @return array */ public function getItemTypes($targetCountry) { $locale = Mage::getSingleton('googlebase/config')->getCountryInfo($targetCountry, 'locale'); $location = self::ITEM_TYPES_LOCATION . '/' . $locale; $itemTypes = array(); foreach ($this->getGuestService()->getFeed($location)->entries as $entry) { if (isset($entry->extensionElements[1])) { // has attributes node? $typeAttributes = $entry->extensionElements[1]->extensionElements; if (is_array($typeAttributes) && !empty($typeAttributes)) { // only items with attributes allowed $type = $entry->extensionElements[0]->text; $item = new Varien_Object(); $item->setId($type); $item->setName($entry->title->text); $item->setLocation($entry->id->text); $itemTypes[$type] = $item; $attributes = array(); foreach ($typeAttributes as $attr) { $name = $attr->extensionAttributes['name']['value']; $type = $attr->extensionAttributes['type']['value']; $attribute = new Varien_Object(); $attribute->setId($name); $attribute->setName($name); $attribute->setType($type); $attributes[$name] = $attribute; } ksort($attributes); $item->setAttributes($attributes); } } } ksort($itemTypes); $this->_itemTypes = $itemTypes; return $itemTypes; }
public function load($printQuery = false, $logQuery = false) { // Skip if already loaded if ($this->isLoaded()) { return $this; } if (empty($this->_items)) { // Get the config $config = Mage::getConfig(); // Loop through the modules foreach ($config->getNode('modules')->children() as $module) { // Create an object $item = new Varien_Object(); // Module name $item->setName($module->getName()); // Module Active $item->setFileEnable((string) $module->active); // Module Code Pool $item->setCodePool((string) $module->codePool); // Module Version $version = Mage::getConfig()->getModuleConfig($module->getName())->version ? Mage::getConfig()->getModuleConfig($module->getName())->version : "undefined"; $item->setVersion($version); // Folder Path $dir = $config->getOptions()->getCodeDir() . DS . $module->codePool . DS . uc_words($module->getName(), DS); $item->setFolderPath($dir); // Folder Exists $pathExists = file_exists($dir) ? "true" : "false"; $item->setFolderPathExists($pathExists); // Config File Exists $file = $config->getModuleDir('etc', $module->getName()) . DS . "config.xml"; $item->setConfigFilePath($file); $exists = file_exists($file); if ($exists) { // Get the config.xml file $configXml = simplexml_load_string(file_get_contents($file), 'Varien_Simplexml_Element'); // Get the resources tag if ($nodes = $configXml->global->resources) { // Reset the pointer to the beginning of the array reset($nodes); // Get the resource name (first key in the array) $resourceName = key($nodes); } else { $resourceName = ''; } $item->setDataEntry($resourceName); if (!$resourceName) { $dataVersion = ''; } else { // Get the data version based on the resource name $dataVersion = Mage::getResourceSingleton('core/resource')->getDataVersion($resourceName); } $item->setDataVersion($dataVersion); // Please note that the 0 value means Enabled and 1 means Disabled $disableOutput = Mage::getStoreConfig('advanced/modules_disable_output/' . $module->getName()) ? 'false' : 'true'; $item->setOutputEnable($disableOutput); } else { $item->setDataEntry(''); $item->setDataVersion(''); $item->setOutputEnable(''); } $exists = $exists ? 'true' : 'false'; $item->setConfigFileExists($exists); $this->addItem($item); } } $this->_setIsLoaded(); $this->_renderFilters()->_renderOrders()->_renderLimit(); return $this; }
/** * Load data * * @param bool $printQuery * @param bool $logQuery * @return Mage_XmlConnect_Model_Resource_Filter_Collection */ public function load($printQuery = false, $logQuery = false) { if (empty($this->_items)) { $layer = Mage::getSingleton('catalog/layer'); foreach ($this->_filters as $filter) { if ('category_id' == $filter['field']) { $layer->setCurrentCategory((int) $filter['value']); } } if ($layer->getCurrentCategory()->getIsAnchor()) { foreach ($layer->getFilterableAttributes() as $attributeItem) { $filterModelName = 'catalog/layer_filter_attribute'; switch ($attributeItem->getAttributeCode()) { case 'price': $filterModelName = 'catalog/layer_filter_price'; break; case 'decimal': $filterModelName = 'catalog/layer_filter_decimal'; break; default: $filterModelName = 'catalog/layer_filter_attribute'; break; } $filterModel = Mage::getModel($filterModelName); $filterModel->setLayer($layer)->setAttributeModel($attributeItem); $filterValues = new Varien_Data_Collection(); foreach ($filterModel->getItems() as $valueItem) { $valueObject = new Varien_Object(); $valueObject->setLabel($valueItem->getLabel()); $valueObject->setValueString($valueItem->getValueString()); $valueObject->setProductsCount($valueItem->getCount()); $filterValues->addItem($valueObject); } $item = new Varien_Object(); $item->setCode($attributeItem->getAttributeCode()); $item->setName($filterModel->getName()); $item->setValues($filterValues); $this->addItem($item); } } } return $this; }
/** * Prepare product * * @param array $productRow * @return Varien_Object */ protected function _prepareProduct(array $productRow) { $product = new Varien_Object(); $product->setId($productRow[$this->getIdFieldName()]); $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); $productName = $productRow['name']; $product->setName($productName); $product->setUrl($productUrl); return $product; }
public function sendAction() { // todo check validity; $template = new Varien_Object(); $template->setData($this->getRequest()->getParams()); $customersIds = $this->getRequest()->getParam('customers'); $ordersIds = $this->getRequest()->getParam('orders'); if ($customersIds) { $collection = Mage::getResourceModel('customer/customer_collection')->addNameToSelect()->addAttributeToSelect('email')->addFieldToFilter('entity_id', array('in' => explode(',', $customersIds))); $cnt = 0; foreach ($collection as $customer) { $vars = array('customer' => $customer, 'store' => Mage::app()->getStore($customer->getStoreId()), 'order' => new Varien_Object()); $res = $this->send($customer->getEmail(), $customer->getName(), $template, $vars); if (true === $res) { $cnt++; } else { Mage::getSingleton('adminhtml/session')->addError($res); } } //foreach Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('amemail')->__('%s email(s) have been sent.', $cnt)); // show customer page if we have only one order if (1 == count($customersIds)) { return $this->_redirect('customer/edit', array('id' => $customersIds[0])); } return $this->_redirect('customer/index'); } elseif ($ordersIds) { $collection = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('entity_id', array('in' => explode(',', $ordersIds))); if (version_compare(Mage::getVersion(), '1.6.2') < 0) { $collection = Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('*')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left'); } $cnt = 0; foreach ($collection as $order) { $customer = new Varien_Object(); if ($order->getCustomerFirstname() || $order->getCustomerLastname()) { $customer->setName($order->getCustomerFirstname() . ' ' . $order->getCustomerLastname()); } else { $customer->setName($order->getShippingFirstname() . ' ' . $order->getShippingLastname()); } $customer->setId($order->getCustomerId()); $vars = array('order' => $order, 'customer' => $customer, 'store' => Mage::app()->getStore($order->getStoreId())); $res = $this->send($order->getCustomerEmail(), $customer->getName(), $template, $vars); if (true === $res) { $cnt++; } else { Mage::getSingleton('adminhtml/session')->addError($res); } } //foreach Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('amemail')->__('%s email(s) have been sent.', $cnt)); // show order page if we have only one order if (1 == count($ordersIds)) { return $this->_redirect('sales_order/view', array('order_id' => $ordersIds[0])); } return $this->_redirect('sales_order/index'); } // no ids return $this->_redirect('dashboard/index'); }
public function getFilterValues() { $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $this->getFilterAttribute()); $options = $attribute->getSource()->getAllOptions(true, true); $values = array(); $category_id = Mage::getStoreConfig('grep_bracelet/settings/pendant_category'); foreach ($options as $option) { if (isset($option['value']) && $option['value']) { $value = new Varien_Object(); $value->setName($option['label']); $value->setValue($option['value']); $value->setChecked($this->getChecked($option['value'])); $category = Mage::getModel('catalog/category')->load($category_id); $c = $category->getProductCollection(); $count = $c->addAttributeToFilter($this->getFilterAttribute(), array('finset' => $option['value']))->count(); $value->setCount($count); $values[$option['value']] = $value; } } return $values; }
/** * Run webservice * * @param Mage_Api_Controller_Action $controller * @return Mage_Api_Model_Server_Adapter_Soap */ public function run() { if ($this->getController()->getRequest()->getParam('wsdl')) { // Generating wsdl content from template $io = new Varien_Io_File(); $io->open(array('path' => Mage::getModuleDir('etc', 'Mage_Api'))); $wsdlContent = $io->read('wsdl.xml'); $template = Mage::getModel('core/email_template_filter'); $wsdlConfig = new Varien_Object(); $wsdlConfig->setUrl(Mage::getUrl('*/*/*')); $wsdlConfig->setName('Magento'); $wsdlConfig->setHandler($this->getHandler()); $template->setVariables(array('wsdl' => $wsdlConfig)); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($template->filter($wsdlContent)); } elseif ($this->_extensionLoaded()) { $this->_soap = new SoapServer(Mage::getUrl('*/*/*', array('wsdl' => 1))); use_soap_error_handler(false); $this->_soap->setClass($this->getHandler()); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($this->_soap->handle()); } else { $this->fault('0', 'Unable to load Soap extension on the server'); } return $this; }
public function getConfigAsObject($code) { $xml = $this->getConfigAsXml($code); $object = new Varien_Object(); if ($xml === null) { return $object; } // Save all nodes to object data $object->setCode($code); $object->setData($xml->asCanonicalArray()); // Set module for translations etc.. $module = $object->getData('@/module'); $object->setModule($module ? $module : 'customgrid'); // Set type $type = $object->getData('@/type'); $object->setType($type); // Translate name, description and help $helper = Mage::helper($object->getModule()); if ($object->hasName()) { $object->setName($helper->__((string) $object->getName())); } if ($object->hasDescription()) { $object->setDescription($helper->__((string) $object->getDescription())); } if ($object->hasHelp()) { $object->setHelp($helper->__((string) $object->getHelp())); } if ($this->_acceptParameters) { // Correct element parameters and convert its data to objects if needed $params = $object->getData('parameters'); $newParams = array(); if (is_array($params)) { $sortOrder = 0; foreach ($params as $key => $data) { if (is_array($data)) { $data['key'] = $key; $data['sort_order'] = isset($data['sort_order']) ? (int) $data['sort_order'] : $sortOrder; // 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; } $newParams[$key] = new Varien_Object($data); $sortOrder++; } } } uasort($newParams, array($this, '_sortParameters')); $object->setData('parameters', $newParams); } return $object; }
/** * Get return contact name * * @param int|null $storeId * @return Varien_Object */ public function getReturnContactName($storeId = null) { $contactName = new Varien_Object(); if (Mage::getStoreConfigFlag(Enterprise_Rma_Model_Rma::XML_PATH_USE_STORE_ADDRESS, $storeId)) { $admin = Mage::getSingleton('admin/session')->getUser(); $contactName->setFirstName($admin->getFirstname()); $contactName->setLastName($admin->getLastname()); $contactName->setName($admin->getName()); } else { $name = Mage::getStoreConfig(Enterprise_Rma_Model_Shipping::XML_PATH_CONTACT_NAME, $storeId); $contactName->setFirstName(''); $contactName->setLastName($name); $contactName->setName($name); } return $contactName; }
private function _sendTestContactFormEmail() { $postObject = new Varien_Object(); $postObject->setName("SMTPPro Tester"); $postObject->setComment("If you get this email then everything seems to be in order."); $postObject->setEmail("*****@*****.**"); $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ include Mage::getBaseDir() . '/app/code/core/Mage/Contacts/controllers/IndexController.php'; $mailTemplate->setDesignConfig(array('area' => 'frontend'))->setReplyTo($postObject->getEmail())->sendTransactional(Mage::getStoreConfig(Mage_Contacts_IndexController::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(Mage_Contacts_IndexController::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(Mage_Contacts_IndexController::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject)); }
public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $ignoreDiscount = false) { $result = array(); $allWeee = $this->getWeeeTaxAttributeCodes(); if (!$allWeee) { return $result; } $websiteId = AO::app()->getWebsite($website)->getId(); $store = AO::app()->getWebsite($website)->getDefaultGroup()->getDefaultStore(); if ($shipping) { $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); } else { $customerTaxClass = null; } $rateRequest = AO::getModel('tax/calculation')->getRateRequest($shipping, $billing, $customerTaxClass, $store); $defaultRateRequest = AO::getModel('tax/calculation')->getRateRequest(false, false, false, $store); $discountPercent = 0; if (!$ignoreDiscount && AO::helper('weee')->isDiscounted($store)) { $discountPercent = $this->_getDiscountPercentForProduct($product); } $productAttributes = $product->getTypeInstance(true)->getSetAttributes($product); foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { $attributeId = $attribute->getId(); $attributeSelect = $this->getResource()->getReadConnection()->select(); $attributeSelect->from($this->getResource()->getTable('weee/tax'), 'value'); $on = array(); $on[] = "attribute_id = '{$attributeId}'"; $on[] = "(website_id in ('{$websiteId}', 0))"; $country = $rateRequest->getCountryId(); $on[] = "(country = '{$country}')"; $region = $rateRequest->getRegionId(); $on[] = "(state in ('{$region}', '*'))"; foreach ($on as $one) { $attributeSelect->where($one); } $attributeSelect->where('entity_id = ?', $product->getId()); $attributeSelect->limit(1); $order = array('state DESC', 'website_id DESC'); $attributeSelect->order($order); $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { if ($discountPercent) { $value = AO::app()->getStore()->roundPrice($value - $value * $discountPercent / 100); } $taxAmount = $amount = 0; $amount = $value; if ($calculateTax && AO::helper('weee')->isTaxable($store)) { $defaultPercent = AO::getModel('tax/calculation')->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); $currentPercent = $product->getTaxPercent(); $taxAmount = AO::app()->getStore()->roundPrice($value / (100 + $defaultPercent) * $currentPercent); $amount = $value - $taxAmount; } $one = new Varien_Object(); $one->setName(AO::helper('catalog')->__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode()); $result[] = $one; } } } return $result; }
/** * Run webservice * * @param Mage_Api_Controller_Action $controller * @return Mage_Api_Model_Server_Adapter_Soap */ public function run() { $apiConfigCharset = Mage::getStoreConfig("api/config/charset"); if ($this->getController()->getRequest()->getParam('wsdl') !== null) { // Generating wsdl content from template $io = new Varien_Io_File(); $io->open(array('path' => Mage::getModuleDir('etc', 'Mage_Api'))); $wsdlContent = $io->read('wsdl.xml'); $template = Mage::getModel('core/email_template_filter'); $wsdlConfig = new Varien_Object(); $queryParams = $this->getController()->getRequest()->getQuery(); if (isset($queryParams['wsdl'])) { unset($queryParams['wsdl']); } $wsdlConfig->setUrl(htmlspecialchars(Mage::getUrl('*/*/*', array('_query' => $queryParams)))); $wsdlConfig->setName('Magento'); $wsdlConfig->setHandler($this->getHandler()); $template->setVariables(array('wsdl' => $wsdlConfig)); $this->getController()->getResponse()->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $apiConfigCharset . '"?>', $template->filter($wsdlContent))); } else { try { $this->_instantiateServer(); $this->getController()->getResponse()->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $apiConfigCharset . '"?>', $this->_soap->handle())); } catch (Zend_Soap_Server_Exception $e) { $this->fault($e->getCode(), $e->getMessage()); } catch (Exception $e) { $this->fault($e->getCode(), $e->getMessage()); } } return $this; }
/** * Get Weee amounts associated with a product * * @param Mage_Catalog_Model_Product $product * @param Mage_Customer_Model_Address_Abstract $shipping * @param Mage_Customer_Model_Address_Abstract $billing * @param mixed $website * @param boolean $calculateTax * @param boolean $ignoreDiscount * @return array|\Varien_Object */ public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $ignoreDiscount = false) { $result = array(); $allWeee = $this->getWeeeTaxAttributeCodes(); if (!$allWeee) { return $result; } $websiteId = Mage::app()->getWebsite($website)->getId(); $store = Mage::app()->getWebsite($website)->getDefaultGroup()->getDefaultStore(); $customer = null; if ($shipping) { $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); $customer = $shipping->getQuote()->getCustomer(); } else { $customerTaxClass = null; } $calculator = Mage::getModel('tax/calculation'); if ($customer) { $calculator->setCustomer($customer); } $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store); $currentPercent = $product->getTaxPercent(); if (!$currentPercent) { $currentPercent = Mage::getSingleton('tax/calculation')->getRate($rateRequest->setProductClassId($product->getTaxClassId())); } $discountPercent = 0; if (!$ignoreDiscount && Mage::helper('weee')->isDiscounted($store)) { $discountPercent = $this->_getDiscountPercentForProduct($product); } $productAttributes = $product->getTypeInstance(true)->getSetAttributes($product); foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { $attributeSelect = $this->getResource()->getReadConnection()->select(); $attributeSelect->from($this->getResource()->getTable('weee/tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', array($websiteId, 0))->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', array($rateRequest->getRegionId(), '*'))->where('entity_id = ?', (int) $product->getId())->limit(1); $order = array('state ' . Varien_Db_Select::SQL_DESC, 'website_id ' . Varien_Db_Select::SQL_DESC); $attributeSelect->order($order); $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { if ($discountPercent) { $value = Mage::app()->getStore()->roundPrice($value - $value * $discountPercent / 100); } $taxAmount = 0; $amount = $value; if ($calculateTax && Mage::helper('weee')->isTaxable($store)) { if ($this->_taxHelper->isCrossBorderTradeEnabled($store)) { $defaultPercent = $currentPercent; } else { $defaultRateRequest = $calculator->getDefaultRateRequest($store); $defaultPercent = Mage::getModel('tax/calculation')->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); } if (Mage::helper('weee')->isTaxIncluded($store)) { $taxAmount = Mage::app()->getStore()->roundPrice($value / (100 + $defaultPercent) * $currentPercent); $amount = $amount - $taxAmount; } else { $appliedRates = Mage::getModel('tax/calculation')->getAppliedRates($rateRequest); if (count($appliedRates) > 1) { $taxAmount = 0; foreach ($appliedRates as $appliedRate) { $taxRate = $appliedRate['percent']; $taxAmount += Mage::app()->getStore()->roundPrice($value * $taxRate / 100); } } else { $taxAmount = Mage::app()->getStore()->roundPrice($value * $currentPercent / 100); } } } $one = new Varien_Object(); $one->setName(Mage::helper('catalog')->__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode()); $result[] = $one; } } } return $result; }
/** * Returns current customer * @return Varien_Object */ public function getCustomer() { if ($this->getCustomerId()) { return Mage::getModel('customer/customer')->load($this->getCustomerId()); } else { $data = $this->getQuote()->getBillingAddress()->getData(); $customer = new Varien_Object(); foreach ($data as $k => $v) { $customer->setData($k, $v); } $customer->setName($customer->getFirstname() . ' ' . $customer->getLastname()); return $customer; } }