/** * Public wrapper for __toArray * * @param array $arrAttributes * @return array */ public function toArray(array $arrAttributes = array()) { $this->setStreet1($this->getStreet(1)); $this->setStreet2($this->getStreet(2)); $this->setStreet($this->getStreet(1) . "\n" . $this->getStreet(2)); return parent::toArray($arrAttributes); }
protected function _prepareForm() { $form = new Varien_Data_Form(); $blockData = Mage::registry(AW_Autorelated_Adminhtml_ShoppingcartblockController::BLOCK_REGISTRY_KEY); if (!$blockData instanceof Varien_Object) { $blockData = new Varien_Object(); } $fieldset = $form->addFieldset('general', array('legend' => $this->__('General'))); $fieldset->addField('name', 'text', array('name' => 'name', 'label' => $this->__('Name'), 'required' => true)); if ($blockData->getData('status') === null) { $blockData->setData('status', 1); } $fieldset->addField('status', 'select', array('name' => 'status', 'label' => $this->__('Status'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_status')->toOptionArray())); if (!Mage::app()->isSingleStoreMode()) { $fieldset->addField('store', 'multiselect', array('name' => 'store[]', 'label' => $this->__('Store View'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true))); } else { $blockData->setStore(Mage::app()->getStore(true)->getId()); $fieldset->addField('store', 'hidden', array('name' => 'store[]')); } if ($blockData->getData('customer_groups') === null) { $blockData->setData('customer_groups', array(Mage_Customer_Model_Group::CUST_GROUP_ALL)); } $fieldset->addField('customer_groups', 'multiselect', array('name' => 'customer_groups[]', 'label' => $this->__('Customer groups'), 'title' => $this->__('Customer groups'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_customer_groups')->toOptionArray())); $fieldset->addField('priority', 'text', array('name' => 'priority', 'label' => $this->__('Priority'), 'title' => $this->__('Priority'), 'required' => false)); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('date_from', 'date', array('name' => 'date_from', 'label' => $this->__('Date From'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $fieldset->addField('date_to', 'date', array('name' => 'date_to', 'label' => $this->__('Date To'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $positionSourceModel = Mage::getModel('awautorelated/source_position'); $fieldset->addField('position', 'select', array('name' => 'position', 'label' => $this->__('Position'), 'title' => $this->__('Position'), 'required' => true, 'values' => $positionSourceModel->toOptionArray(AW_Autorelated_Model_Source_Type::SHOPPING_CART_BLOCK))); $form->setValues($blockData->toArray()); $this->setForm($form); }
public function render(Varien_Data_Form_Element_Abstract $element) { $html = $this->_getHeaderHtml($element); $modules = array_keys((array) Mage::getConfig()->getNode('modules')->children()); $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent('magetrashapp_system_config_magetrashapp_manage_extns_render_before', array('modules' => $dispatchResult)); $modules = $dispatchResult->toArray(); sort($modules); foreach ($modules as $moduleName) { if ($moduleName === 'Mage_Adminhtml' || $moduleName === 'Hackathon_MageTrashApp' || stripos($moduleName, 'Mage_') !== false) { continue; } $resName = Mage::helper('magetrashapp')->getResourceName($moduleName); if ($resName === null) { continue; } $number = Mage::getResourceSingleton('core/resource')->getDbVersion($resName); if (!$resName || $resName == $number) { continue; } $html .= $this->_getFieldHtml($element, $moduleName); } $html .= $this->_getFooterHtml($element); return $html; }
/** * Tests Varien_Object->toArray() */ public function testToArray() { $this->assertEquals(array(), $this->_object->toArray()); $this->assertEquals(array('key' => null), $this->_object->toArray(array('key'))); $this->_object->setData(array('key1' => 'value1', 'key2' => 'value2')); $this->assertEquals(array('key1' => 'value1'), $this->_object->toArray(array('key1'))); $this->assertEquals(array('key2' => 'value2'), $this->_object->__toArray(array('key2'))); }
public function updateWall($observer) { if (Mage::helper('fbintegrator')->extEnabled() && Mage::helper('fbintegrator')->getWallEnabled()) { $order = $observer->getEvent()->getOrder(); if (Mage::helper('fbintegrator')->isRegisteredOrder($order->getId())) { return; } else { Mage::helper('fbintegrator')->registerOrder($order->getId()); } $facebook = new AW_FBIntegrator_Model_Facebook_Api(Mage::helper('fbintegrator')->getAppConfig()); $session = $facebook->getUser(); if ($session) { try { $orderItems = $order->getAllVisibleItems(); $store = Mage::app()->getStore(); $urlConfig = array('_secure' => Mage::helper('fbintegrator')->isSecure(), '_use_rewrite' => Mage::helper('fbintegrator')->useRewrite(), '_store_to_url' => Mage::helper('fbintegrator')->addCode()); $storeLink = Mage::getUrl('', $urlConfig); $message = Mage::helper('fbintegrator')->getWallMessage(); $messageParams = array('count' => array('template' => '{items_count}', 'real' => count($order->getAllVisibleItems())), 'link' => array('template' => '{store_link}', 'real' => $storeLink)); foreach ($messageParams as $param) { $message = str_replace($param['template'], $param['real'], $message); } $description = array(); $media = array(); $countToPost = Mage::helper('fbintegrator')->getWallCount(); $count = (int) $countToPost ? min((int) $countToPost, count($orderItems)) : count($orderItems); for ($i = 0; $i < $count; $i++) { $product = $orderItems[$i]; $productLink = Mage::helper('fbintegrator')->useRewrite() ? Mage::helper('fbintegrator')->getProductRewriteUrl($product->getProductId()) : 'catalog/product/view/id/' . $product->getProductId(); $productInfo = array('count' => array('template' => '{items_count}', 'real' => $product->getQtyOrdered()), 'name' => array('template' => '{item_name}', 'real' => $product->getName()), 'price' => array('template' => '{item_price}', 'real' => $store->convertPrice($product->getBasePrice(), true, false)), 'link' => array('template' => '{item_link}', 'real' => $storeLink . $productLink), 'store' => array('template' => '{store_link}', 'real' => $storeLink)); $row = Mage::helper('fbintegrator')->getWallTemplate(); foreach ($productInfo as $param) { $row = str_replace($param['template'], $param['real'], $row); } $description[] = $row; $description[] = '<center></center>'; //facebook line break if (Mage::helper('fbintegrator')->postImagesToWall()) { $media[] = array('type' => 'image', 'src' => Mage::getModel('catalog/product')->load($product->getProductId())->getImageUrl(), 'href' => $storeLink . $productLink); } } $param = array('method' => 'stream.publish', 'message' => $message, 'attachment' => array('description' => implode(' ', $description), 'media' => $media)); $params = new Varien_Object($param); Mage::dispatchEvent('aw_fbintegrator_order_wall_post_before', array('params' => $params, 'observer' => $observer)); $param = $params->toArray(); $facebook->api($param); } catch (Exception $e) { // Mage::log($e->getMessage()); } } } }
protected function _prepareForm() { $form = new Varien_Data_Form(); $blockData = Mage::registry(AW_Autorelated_Adminhtml_ShoppingcartblockController::BLOCK_REGISTRY_KEY); if (!$blockData instanceof Varien_Object) { $blockData = new Varien_Object(); } $fieldset = $form->addFieldset('general', array('legend' => $this->__('General'))); $generalOptions = array(); if ($relatedProducts = $blockData->getData('related_products')) { if ($relatedProducts->getData('options')) { $generalOptions = $relatedProducts->getData('options'); } $blockData->setData('related_products_count', $relatedProducts->getData('count')); $blockData->setData('show_out_of_stock', $relatedProducts->getData('show_out_of_stock')); $order = $relatedProducts->getData('order'); if (!is_array($order)) { $order = array(); } $blockData->setData('order', isset($order['type']) ? $order['type'] : null); $blockData->setData('order_attribute', isset($order['attribute']) ? $order['attribute'] : null); $blockData->setData('order_direction', isset($order['direction']) ? $order['direction'] : null); } $optionsRenderer = $this->getLayout()->createBlock('awautorelated/adminhtml_blocks_shoppingcart_edit_tabs_relatedproducts_attributes')->setValues($generalOptions); $fieldset->addField('general_options', 'text', array('label' => $this->__('Attributes'), 'name' => 'related_products[options]'))->setRenderer($optionsRenderer); $conditionsRenderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')->setTemplate('promo/fieldset.phtml')->setNewChildUrl($this->getUrl('*/*/newConditionHtml', array('form' => 'related_conditions_fieldset', 'prefix' => 'related', 'rule' => base64_encode('awautorelated/blocks_shoppingcart_rulerelated')))); $fieldset = $form->addFieldset('related_conditions_fieldset', array('legend' => $this->__('Conditions (leave blank for all products)')))->setRenderer($conditionsRenderer); /** @var $model AW_Autorelated_Model_Blocks_Shoppingcart_Ruleviewed */ $model = Mage::getModel('awautorelated/blocks_shoppingcart_rulerelated'); $model->setForm($fieldset); $model->getConditions()->setJsFormObject('related_conditions'); if ($relatedProducts && is_array($conditions = $relatedProducts->getData('conditions'))) { $model->getConditions()->loadArray($conditions, 'related'); $model->getConditions()->setJsFormObject('related_conditions'); } $fieldset->addField('related_conditions', 'text', array('name' => 'related_conditions', 'label' => Mage::helper('salesrule')->__('Conditions'), 'title' => Mage::helper('salesrule')->__('Conditions')))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions')); $fieldset = $form->addFieldset('other', array('legend' => $this->__('Other'))); if ($blockData->getData('related_products_count') === null) { $blockData->setData('related_products_count', Mage::helper('awautorelated/config')->getNumberOfProducts()); } $fieldset->addField('related_products_count', 'text', array('name' => 'related_products[count]', 'title' => $this->__('Number of products'), 'label' => $this->__('Number of products'), 'required' => true)); $fieldset->addField('order', 'select', array('name' => 'related_products[order][type]', 'label' => $this->__('Order Products'), 'title' => $this->__('Order Products'), 'values' => Mage::getModel('awautorelated/source_block_common_order')->toOptionArray())); $fieldset->addField('order_attribute', 'select', array('name' => 'related_products[order][attribute]', 'values' => Mage::getModel('awautorelated/source_catalog_product_attributes')->toOptionArray(), 'note' => $this->__('Select Attribute'))); $fieldset->addField('order_direction', 'select', array('name' => 'related_products[order][direction]', 'values' => Mage::getModel('awautorelated/source_resource_collection_order')->toOptionArray(), 'note' => $this->__('Sort Direction'))); $fieldset->addField('show_out_of_stock', 'select', array('name' => 'related_products[show_out_of_stock]', 'label' => $this->__('Show "Out of stock" Products'), 'title' => $this->__('Show "Out of stock" Products'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray())); $form->setValues($blockData->toArray()); $this->setForm($form); }
public function render(Varien_Data_Form_Element_Abstract $element) { $html = $this->_getHeaderHtml($element); $modules = array_keys((array) Mage::getConfig()->getNode('modules')->children()); $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent('adminhtml_system_config_advanced_disableoutput_render_before', array('modules' => $dispatchResult)); $modules = $dispatchResult->toArray(); sort($modules); foreach ($modules as $moduleName) { if ($moduleName === 'Mage_Adminhtml') { continue; } $html .= $this->_getFieldHtml($element, $moduleName); } $html .= $this->_getFooterHtml($element); return $html; }
public function render(Varien_Data_Form_Element_Abstract $element) { $html = $this->_getHeaderHtml($element); $modules = array_keys((array) Mage::getConfig()->getNode('modules')->children()); $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent('magetrashapp_system_config_magetrashapp_manage_extns_render_before', array('modules' => $dispatchResult)); $modules = $dispatchResult->toArray(); sort($modules); foreach ($modules as $moduleName) { $moduleStatus = Mage::getConfig()->getModuleConfig($moduleName)->is('active', 'true'); if ($moduleName === 'Mage_Adminhtml' || $moduleName === 'Hackathon_MageTrashApp' || stripos($moduleName, 'Mage_') !== false) { continue; } $html .= $this->_getFieldHtml($element, $moduleName, $moduleStatus); } $html .= $this->_getFooterHtml($element); return $html; }
public function saveConfig($observer) { $modules = array_keys((array) Mage::getConfig()->getNode('modules')->children()); $dispatchResult = new Varien_Object($modules); $modules = $dispatchResult->toArray(); foreach ($modules as $moduleName) { if ($moduleName === 'Mage_Adminhtml' || $moduleName === 'Hackathon_MageTrashApp' || stripos($moduleName, 'Mage_') !== false) { continue; } $configFlag = Mage::getStoreConfig('magetrashapp/manage_extns/' . $moduleName); switch ($configFlag) { case Hackathon_MageTrashApp_Helper_Data::ENABLE: Mage::helper('magetrashapp')->activateModule($moduleName); break; case Hackathon_MageTrashApp_Helper_Data::DISABLE: $this->disableModules[] = $moduleName; Mage::helper('magetrashapp')->activateModule($moduleName, false); break; case Hackathon_MageTrashApp_Helper_Data::UNINSTALL: Mage::helper('magetrashapp')->uninstallModule($moduleName); break; default: break; } $configFlag = Mage::getStoreConfig('magetrashapp/rewind_extns/' . $moduleName); if ($configFlag != 0) { $version = substr($configFlag, 2); $configFlag = $configFlag[0]; } elseif (is_null($configFlag)) { continue; } switch ($configFlag) { case Hackathon_MageTrashApp_Helper_Data::DELETE: Mage::helper('magetrashapp')->deleteCoreResource($moduleName); break; case Hackathon_MageTrashApp_Helper_Data::REWIND: Mage::helper('magetrashapp')->rewindCoreResource($moduleName, $version); break; default: break; } } }
protected function _prepareForm() { $form = new Varien_Data_Form(); $blockData = Mage::registry(AW_Autorelated_Adminhtml_ShoppingcartblockController::BLOCK_REGISTRY_KEY); if (!$blockData instanceof Varien_Object) { $blockData = new Varien_Object(); } $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')->setTemplate('promo/fieldset.phtml')->setNewChildUrl($this->getUrl('*/*/newConditionHtml', array('form' => 'order_conditions_fieldset', 'prefix' => 'viewed', 'rule' => base64_encode('awautorelated/blocks_shoppingcart_ruleviewed')))); $fieldset = $form->addFieldset('order_conditions_fieldset', array('legend' => Mage::helper('salesrule')->__('Apply the rule only if the following conditions are met (leave blank for all products)')))->setRenderer($renderer); /** @var $model AW_Autorelated_Model_Blocks_Shoppingcart_Ruleviewed */ $model = Mage::getModel('awautorelated/blocks_shoppingcart_ruleviewed'); $model->setForm($fieldset); $model->getConditions()->setJsFormObject('order_conditions_fieldset'); if ($blockData->getData('currently_viewed') && is_array($conditions = $blockData->getData('currently_viewed')->getData('conditions'))) { $model->getConditions()->loadArray($conditions, 'viewed'); $model->getConditions()->setJsFormObject('order_conditions_fieldset'); } $fieldset->addField('order_conditions', 'text', array('name' => 'order_conditions', 'label' => Mage::helper('salesrule')->__('Conditions'), 'title' => Mage::helper('salesrule')->__('Conditions')))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions')); $form->setValues($blockData->toArray()); $this->setForm($form); }
/** * Return Merge Fields mapped to Magento attributes * * @param object $customer * @param bool $includeEmail * @param integer $websiteId * @return array */ public function getMergeVars($customer, $includeEmail = FALSE, $websiteId = NULL) { $merge_vars = array(); $maps = $this->getMergeMaps($customer->getStoreId()); if (!$maps) { return; } $request = Mage::app()->getRequest(); //Add Customer data to Subscriber if is Newsletter_Subscriber is Customer if (!$customer->getDefaultShipping() && $customer->getEntityId()) { $customer->addData(Mage::getModel('customer/customer')->load($customer->getEntityId())->setStoreId($customer->getStoreId())->toArray()); } foreach ($maps as $map) { $customAtt = $map['magento']; $chimpTag = $map['mailchimp']; if ($chimpTag && $customAtt) { $key = strtoupper($chimpTag); switch ($customAtt) { case 'gender': $val = (int) $customer->getData(strtolower($customAtt)); if ($val == 1) { $merge_vars[$key] = 'Male'; } elseif ($val == 2) { $merge_vars[$key] = 'Female'; } break; case 'dob': $dob = (string) $customer->getData(strtolower($customAtt)); if ($dob) { $merge_vars[$key] = substr($dob, 5, 2) . '/' . substr($dob, 8, 2); } break; case 'billing_address': case 'shipping_address': $addr = explode('_', $customAtt); $address = $customer->{'getPrimary' . ucfirst($addr[0]) . 'Address'}(); if ($address) { $merge_vars[$key] = array('addr1' => $address->getStreet(1), 'addr2' => $address->getStreet(2), 'city' => $address->getCity(), 'state' => !$address->getRegion() ? $address->getCity() : $address->getRegion(), 'zip' => $address->getPostcode(), 'country' => $address->getCountryId()); $telephone = $address->getTelephone(); if ($telephone) { $merge_vars['TELEPHONE'] = $telephone; } $company = $address->getCompany(); if ($company) { $merge_vars['COMPANY'] = $company; } } break; case 'date_of_purchase': $last_order = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('customer_email', $customer->getEmail())->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))->setOrder('created_at', 'desc')->getFirstItem(); if ($last_order->getId()) { $merge_vars[$key] = Mage::helper('core')->formatDate($last_order->getCreatedAt()); } break; case 'ee_customer_balance': $merge_vars[$key] = ''; if ($this->isEnterprise() && $customer->getId()) { $_customer = Mage::getModel('customer/customer')->load($customer->getId()); if ($_customer->getId()) { if (Mage::app()->getStore()->isAdmin()) { $websiteId = is_null($websiteId) ? Mage::app()->getStore()->getWebsiteId() : $websiteId; } $balance = Mage::getModel('enterprise_customerbalance/balance')->setWebsiteId($websiteId)->setCustomerId($_customer->getId())->loadByCustomer(); $merge_vars[$key] = $balance->getAmount(); } } break; case 'group_id': $group_id = (int) $customer->getData(strtolower($customAtt)); $customerGroup = Mage::helper('customer')->getGroups()->toOptionHash(); if ($group_id == 0) { $merge_vars[$key] = 'NOT LOGGED IN'; } else { $merge_vars[$key] = $customerGroup[$group_id]; } break; default: if ($value = (string) $customer->getData(strtolower($customAtt)) or $value = (string) $request->getPost(strtolower($customAtt))) { $merge_vars[$key] = $value; } break; } } } //GUEST if (!$customer->getId() && (!$request->getPost('firstname') || !$request->getPost('lastname'))) { $guestFirstName = $this->config('guest_name', $customer->getStoreId()); $guestLastName = $this->config('guest_lastname', $customer->getStoreId()); if ($guestFirstName) { $merge_vars['FNAME'] = $guestFirstName; } if ($guestLastName) { $merge_vars['LNAME'] = $guestLastName; } } //GUEST if ($includeEmail) { $merge_vars['EMAIL'] = $customer->getEmail(); } $groups = $customer->getListGroups(); $groupings = array(); if (is_array($groups) && count($groups)) { foreach ($groups as $groupId => $grupoptions) { $groupings[] = array('id' => $groupId, 'groups' => is_array($grupoptions) ? implode(', ', $grupoptions) : $grupoptions); } } $merge_vars['GROUPINGS'] = $groupings; //magemonkey_mergevars_after $blank = new Varien_Object(); Mage::dispatchEvent('magemonkey_mergevars_after', array('vars' => $merge_vars, 'customer' => $customer, 'newvars' => $blank)); if ($blank->hasData()) { $merge_vars = array_merge($merge_vars, $blank->toArray()); } //magemonkey_mergevars_after return $merge_vars; }
/** * Builds a Varien_Object containing all fields necessary to render * a payment redirect form * * @param int $orderIncrementId * @throws Mage_Payment_Exception * @return Varien_Object */ public final function getCheckoutFormFields($orderIncrementId = null) { if (null === $orderIncrementId) { $orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); } $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); if (!$order || !$order->getId()) { throw new Mage_Payment_Exception('Cannot load order with increment id "' . $orderIncrementId . '"'); } $language = Mage::getStoreConfig('general/locale/code') ?: 'en_GB'; $totalAmount = $this->formatAmount($order->getGrandTotal(), $order->getOrderCurrencyCode()); $fields = new Varien_Object(); $fields->setMerchant($this->getConfigData('merchant_id'))->setCurrency($this->getDibsCurrencyCode($order->getOrderCurrencyCode()))->setAmount($totalAmount)->setLanguage($language)->setData('orderId', $order->getIncrementId())->setData('acceptReturnUrl', $this->getReturnUrl())->setData('cancelReturnUrl', $this->getCancelUrl())->setData('callbackUrl', $this->getCallbackUrl()); if (trim($this->getConfigData('payment_type')) !== '') { $fields->setData('payType', $this->getConfigData('payment_type')); } if ($this->getConfigData('test')) { $fields->setTest('1'); } if ($this->getConfigData('payment_action') === Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE) { $fields->setData('capturenow', '1'); } $billingAddress = $order->getBillingAddress(); $fields->setData('billingFirstName', $this->_cleanDibsValue($billingAddress->getFirstname())); $fields->setData('billingLastName', $this->_cleanDibsValue($billingAddress->getLastname())); $fields->setData('billingAddress', $this->_cleanDibsValue($billingAddress->getStreet(1))); $street2 = $billingAddress->getStreet(2); if (!empty($street2)) { $fields->setData('billingAddress2', $this->_cleanDibsValue($street2)); } $email = $order->getCustomerEmail() ?: $billingAddress->getEmail(); $fields->setData('billingPostalCode', $this->_cleanDibsValue($billingAddress->getPostcode())); $fields->setData('billingPostalPlace', $this->_cleanDibsValue($billingAddress->getCity())); $fields->setData('billingEmail', $email); $fields->setData('billingMobile', $this->_cleanDibsValue($order->getTelephone())); $oiData = array(); $calculatedAmount = 0; $i = 1; foreach ($order->getAllItems() as $item) { if ($item->getParentItemId()) { // Only pass main products continue; } $name = $item->getName(); if (empty($name)) { // Gift wraps etc don't have names (what else do they have?) DIBS needs the name. $name = $item->getSku(); } $name = $this->_cleanDibsValue($name); $sku = $this->_cleanDibsValue($item->getSku()); $amount = $this->formatAmount($item->getPriceInclTax(), $order->getOrderCurrencyCode()); $row = (int) $item->getQtyOrdered() . ';' . $name . ';' . $amount . ';' . $sku; $oiData['oiRow' . $i++] = $row; $calculatedAmount += bcmul($amount, $item->getQtyOrdered()); } // Shipping, giftcards and discounts needs to be separate rows, use the // quote totals to determine what to print and exclude values that // are already included from other places $quoteId = $order->getQuoteId(); $quote = Mage::getModel('sales/quote')->load($quoteId); $quote->collectTotals(); $totalsToExclude = array('grand_total', 'subtotal', 'tax', 'klarna_tax'); foreach ($quote->getTotals() as $code => $total) { if (in_array($code, $totalsToExclude)) { continue; } switch ($code) { case 'giftcardaccount': case 'giftwrapping': case 'discount': case 'ugiftcert': $value = -abs($total->getValue()); if (empty($value)) { continue 2; } break; case 'shipping': // We have to somehow make sure that we use the correctly // calculated value, we can't rely on the shipping tax // being part of the quote totals $value = $order->getShippingTaxAmount() + $order->getShippingAmount(); break; default: $value = $total->getValue(); } $title = $total->getTitle(); if (empty($title)) { $title = $code; } $amount = $this->formatAmount($value, $order->getOrderCurrencyCode()); $row = '1;' . $title . ';' . $amount . ';' . $code; $oiData['oiRow' . $i++] = $row; $calculatedAmount += $amount; } if ($totalAmount === $calculatedAmount) { $fields->setData('oiTypes', 'QUANTITY;DESCRIPTION;AMOUNT;ITEMID'); $fields->setData('oiNames', 'Quantity;Product;Amount;SKU'); foreach ($oiData as $key => $value) { $fields->setData($key, $value); } } $hmac = $this->calculateMac($fields->toArray()); $fields->setData('MAC', $hmac); return $fields; }
/** * Capture * * @param Varien_Object $orderPayment * @param float $amount * @return Mage_Payment_Model_Abstract */ public function capture(Varien_Object $payment, $amount) { $log = Mage::getModel('allpago_mc/log'); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); if ($gwap->getStatus() != Allpago_Gwap_Model_Order::STATUS_CAPTURED) { // Processamento de pedidos não novos if ($gwap->getStatus() == Allpago_Gwap_Model_Order::STATUS_CREATED) { $this->authorize($payment, $amount); /** * reload item */ $gwap->clearInstance(); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTUREPAYMENT); $gwap->save(); } $url = Mage::helper('gwap')->getRequestURL(); if ($this->_cc) { $cc1 = new Varien_Object(unserialize(Mage::helper('core')->decrypt($this->_cc))); $cc2 = new Varien_Object(unserialize(Mage::helper('core')->decrypt($this->_cc2))); } else { $cc1 = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getInfo()))); $cc2 = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getInfo2()))); } $parameters1 = $cc1->toArray(); $parameters2 = $cc2->toArray(); $postString1 = Mage::helper('gwap')->buildPostString($parameters1); $postString2 = Mage::helper('gwap')->buildPostString($parameters2); $response1 = Mage::helper('gwap')->makeCurlRequest($url, $postString1); $response2 = Mage::helper('gwap')->makeCurlRequest($url, $postString2); $resultCode1 = explode('.', $response1['PROCESSING.CODE']); $resultCode1 = $resultCode1[2]; $resultCode2 = explode('.', $response2['PROCESSING.CODE']); $resultCode2 = $resultCode2[2]; if ($resultCode1 != '90') { $errorMsg = $gwap->getCcType() . ': Payment code: ' . $response1['PAYMENT.CODE'] . ' (' . $response1['PROCESSING.REASON'] . ' - ' . $response1['PROCESSING.RETURN'] . ')'; //Captura manual ativada if (Mage::getStoreConfig('payment/gwap_cc/captura')) { $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_ERROR, 'Ocorreu um erro', $errorMsg); } Mage::throwException($errorMsg); } if ($resultCode2 != '90') { $errorMsg = $gwap->getCcType2() . ': Payment code: ' . $response2['PAYMENT.CODE'] . ' (' . $response2['PROCESSING.REASON'] . ' - ' . $response2['PROCESSING.RETURN'] . ')'; //Captura manual ativada if (Mage::getStoreConfig('payment/gwap_cc/captura')) { $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_ERROR, 'Ocorreu um erro', $errorMsg); } // Em caso de erro, estornar primeiro cartão $removeResult = $this->removeCreditAuto($payment->getOrder(), $parameters1['PRESENTATION.AMOUNT'], $response1['IDENTIFICATION.UNIQUEID'], $gwap->getCcType(), 1); Mage::throwException($errorMsg . '<br/>' . $gwap->getCcType() . ': ' . $removeResult); } $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_CAPTURED, 'Pagamento capturado'); //Salva UNIQUEID da captura para possibilitar estorno $gwap->setInfo(serialize(array('UNIQUEID' => $response1['IDENTIFICATION.UNIQUEID']))); $gwap->setInfo2(serialize(array('UNIQUEID' => $response2['IDENTIFICATION.UNIQUEID']))); $gwap->setCaptureResult(serialize($this->getTID($resultCode1))); $gwap->setCaptureResult2(serialize($this->getTID2($resultCode2))); //Completar processo do pedido para o caso do RG gerar erro. $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTURED); $gwap->setErrorCode(null); $gwap->setErrorMessage(null); $gwap->setTries(0); $gwap->setAbandoned(0); $gwap->save(); } return $this; }
/** * Aggregate data for this tracker * * @param string $incremental * @param Mzax_Emarketing_Model_Campaign $campaign * @return Mzax_Emarketing_Model_Conversion_Tracker */ public function aggregate($incremental = null, Mzax_Emarketing_Model_Campaign $campaign = null) { $options = new Varien_Object(array('aggregator' => array('goals', 'tracker', 'dimension'), 'tracker_id' => $this->getId(), 'verbose' => false)); Mage::dispatchEvent($this->_eventPrefix . '_aggregate', array('options' => $options, 'campaign' => $campaign, 'tracker' => $this)); if ($incremental) { $options->setIncremental((int) $incremental); } if ($campaign) { if ($campaign instanceof Mzax_Emarketing_Model_Campaign) { $campaign = $campaign->getId(); } $options->setCampaignId((int) $campaign); } /* @var $report Mzax_Emarketing_Model_Report */ $report = Mage::getSingleton('mzax_emarketing/report'); $report->aggregate($options->toArray()); return $this; }
/** * validate module before saving * @access public * @return void * @author Marius Strajeru <*****@*****.**> */ public function validateAction() { $errors = array(); $response = new Varien_Object(); $response->setError(false); $data = $this->getRequest()->getPost(); $entities = $this->getRequest()->getPost('entity'); $settings = $this->getRequest()->getPost('settings'); if (empty($settings['namespace'])) { $error = new Varien_Object(); $error->setField('settings_namespace'); $error->setMessage(Mage::helper('modulecreator')->__('Fill in the Namespace')); $errors[] = $error->toArray(); } if (empty($settings['module_name'])) { $error = new Varien_Object(); $error->setField('settings_module_name'); $error->setMessage(Mage::helper('modulecreator')->__('Fill in the Module name')); $errors[] = $error->toArray(); } else { $validModule = Mage::helper('modulecreator')->validateModuleName($settings['module_name'], $settings['current_extension']); if (is_string($validModule)) { $error = new Varien_Object(); $error->setMessage($validModule); $error->setField('settings_module_name'); $errors[] = $error->toArray(); } } $validExtension = Mage::helper('modulecreator')->validateExtensionName($settings['namespace'], $settings['module_name'], $settings['current_extension']); if (is_string($validExtension)) { $error = new Varien_Object(); $error->setMessage($validExtension); $errors[] = $error->toArray(); } if (empty($entities)) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('Add at least one entity')); $errors[] = $error->toArray(); } else { //validate each entity $noAttributeEntities = false; $noNameEntities = false; foreach ($entities as $key => $entity) { if (empty($entity['name_singular'])) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('This is a required field.')); $error->setField('entity_' . $key . '_name_singular'); $errors[] = $error->toArray(); } if (empty($entity['name_plural'])) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('This is a required field.')); $error->setField('entity_' . $key . '_name_plural'); $errors[] = $error->toArray(); } if (!isset($entity['attributes']) && !$noAttributeEntities) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('There are entities without attribtues. Add attributes or remove them before continuing.')); $errors[] = $error->toArray(); $noAttributeEntities = true; } elseif (isset($entity['attributes'])) { //validate attributes foreach ($entity['attributes'] as $attrKey => $attribute) { if (is_numeric($attrKey)) { $validAttribute = Mage::helper('modulecreator')->validateAttributeName($attribute['code']); if (is_string($validAttribute)) { $error = new Varien_Object(); $error->setMessage($validAttribute); $error->setField('attribute_' . $key . '_' . $attrKey . '_code'); $errors[] = $error->toArray(); } } } } if ((!isset($entity['attributes']) || is_null($entity['attributes']['is_name'])) && !$noNameEntities) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('Each entity must have an attribute set to behave as "Name"')); $errors[] = $error->toArray(); $noNameEntities = true; } $validEntity = Mage::helper('modulecreator')->validateEntityName($settings['module_name'], @$entity['name_singular'], $settings['current_extension']); if (is_string($validEntity)) { $error = new Varien_Object(); $error->setMessage($validEntity); $error->setField('entity_' . $key . '_name_singular'); $errors[] = $error->toArray(); } } } try { $module = $this->_initModuleFromData($data); } catch (Exception $e) { $error = new Varien_Object(); $error->setMessage($e->getMessage()); $errors[] = $error->toArray(); } if (count($errors) > 0) { $response->setError(true); $response->setErrors($errors); } $this->getResponse()->setBody($response->toJson()); }
/** * Return Merge Fields mapped to Magento attributes * * @param object $customer * @param bool $includeEmail * @param integer $websiteId * @return array */ public function getMergeVars($customer, $includeEmail = FALSE, $websiteId = NULL) { $merge_vars = array(); $maps = $this->getMergeMaps($customer->getStoreId()); if (!$maps) { return; } $request = Mage::app()->getRequest(); //Add Customer data to Subscriber if is Newsletter_Subscriber is Customer if (!$customer->getDefaultShipping() && $customer->getEntityId()) { $customer->addData(Mage::getModel('customer/customer')->load($customer->getEntityId())->setStoreId($customer->getStoreId())->toArray()); } elseif ($customer->getCustomerId()) { $customer->addData(Mage::getModel('customer/customer')->load($customer->getCustomerId())->setStoreId($customer->getStoreId())->toArray()); } $merge_vars = $this->_setMaps($maps, $customer, $merge_vars, $websiteId); //GUEST if (!$customer->getId() && !$request->getPost('firstname')) { if ($customer->getSubscriberFirstname()) { $guestFirstName = $customer->getSubscriberFirstname(); } else { $guestFirstName = $this->config('guest_name', $customer->getStoreId()); } if ($guestFirstName) { $merge_vars['FNAME'] = $guestFirstName; } } if (!$customer->getId() && !$request->getPost('lastname')) { if ($customer->getSubscriberLastname()) { $guestLastName = $customer->getSubscriberLastname(); } else { $guestLastName = $this->config('guest_lastname', $customer->getStoreId()); } if ($guestLastName) { $merge_vars['LNAME'] = $guestLastName; } } //GUEST if ($includeEmail) { $merge_vars['EMAIL'] = $customer->getEmail(); } $groups = $customer->getListGroups(); $groupings = array(); if (is_array($groups) && count($groups)) { foreach ($groups as $groupId => $grupoptions) { if (is_array($grupoptions)) { $grupOptionsEscaped = array(); foreach ($grupoptions as $gopt) { $gopt = str_replace(",", "%C%", $gopt); $grupOptionsEscaped[] = $gopt; } $groupings[] = array('id' => $groupId, 'groups' => str_replace('%C%', '\\,', implode(', ', $grupOptionsEscaped))); } else { $groupings[] = array('id' => $groupId, 'groups' => str_replace(',', '\\,', $grupoptions)); } } } $merge_vars['GROUPINGS'] = $groupings; //magemonkey_mergevars_after $blank = new Varien_Object(); Mage::dispatchEvent('magemonkey_mergevars_after', array('vars' => $merge_vars, 'customer' => $customer, 'newvars' => $blank)); if ($blank->hasData()) { $merge_vars = array_merge($merge_vars, $blank->toArray()); } //magemonkey_mergevars_after return $merge_vars; }
/** * Capture * * @param Varien_Object $orderPayment * @param float $amount * @return Mage_Payment_Model_Abstract */ public function capture(Varien_Object $payment, $amount) { $log = Mage::getModel('allpago_mc/log'); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); if ($gwap->getStatus() != Allpago_Gwap_Model_Order::STATUS_CAPTURED) { // Processamento de pedidos não novos if ($gwap->getStatus() == Allpago_Gwap_Model_Order::STATUS_CREATED) { $this->authorize($payment, $amount); /** * reload item */ $gwap->clearInstance(); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTUREPAYMENT); $gwap->save(); } $url = $this->getRequestURL(); if ($this->_cc) { $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($this->_cc))); } else { $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getInfo()))); } $parameters = $cc->toArray(); $postString = $this->buildPostString($parameters); $cc = ''; $response = $this->makeCurlRequest($url, $postString); if ($this->_resultCode != '90') { $errorMsg = 'Payment code: ' . $response['PAYMENT.CODE'] . ' (' . $response['PROCESSING.REASON'] . ' - ' . $response['PROCESSING.RETURN'] . ')'; //Captura manual ativada if (Mage::getStoreConfig('payment/gwap_cc/captura')) { $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_ERROR, 'Ocorreu um erro', $errorMsg); } Mage::throwException($errorMsg); } $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_CAPTURED, 'Pagamento capturado'); //Salva UNIQUEID da captura para possibilitar estorno $gwap->setInfo(serialize(array('UNIQUEID' => $response['IDENTIFICATION.UNIQUEID']))); $gwap->setCaptureResult(serialize($this->_TID)); $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTURED); $gwap->setErrorCode(null); $gwap->setErrorMessage(null); $gwap->setTries(0); $gwap->setAbandoned(0); $gwap->save(); //Captura instantanea if ($this->_rg) { $cc = new Varien_Object($this->_rg); //Lote } else { $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getRegistrationCc()))); } // Se oneclick ativado cria(RG)/atualiza(RR) no gateway if ($this->isOneclickOrder($cc)) { $customerId = $payment->getOrder()->getCustomerId(); $registrationId = $this->getRegistrationInfo($customerId, substr($cc->getCcNumber(), -4)); if (!$registrationId) { /*/Update $response = $this->fetchCustomerRegistration($gwap, $registrationId); if ($this->_resultCode != '90') { $gwap->setRegistrationCc(null); $gwap->save(); $errorMsg = 'Payment code: ' . $response['PAYMENT.CODE'] . ' (' . $response['PROCESSING.REASON'] . ' - ' . $response['PROCESSING.RETURN'] . ')'; //Captura manual ativada if(Mage::getStoreConfig('payment/gwap_cc/captura')){ $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_ERROR, 'Ocorreu um erro', $errorMsg); } Mage::throwException($errorMsg); }*/ $this->newRegistrationInfo($customerId, $gwap); } } $gwap->setRegistrationCc(null); $gwap->save(); } return $this; }
/** * Capture * * @param Varien_Object $orderPayment * @param float $amount * @return Mage_Payment_Model_Abstract */ public function capture(Varien_Object $payment, $amount) { $log = Mage::getModel('allpago_mc/log'); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); if ($gwap->getStatus() != Allpago_Gwap_Model_Order::STATUS_CAPTURED) { // Autoriza pedido se estiver pendente if ($gwap->getStatus() == Allpago_Gwap_Model_Order::STATUS_CREATED) { $this->authorize($payment, $amount); /** * reload item */ $gwap->clearInstance(); $gwap = Mage::getModel('gwap/order')->load($payment->getOrder()->getId(), 'order_id'); $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTUREPAYMENT); $gwap->save(); } $url = $this->getRequestURL(); if ($this->_cc) { $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($this->_cc))); } else { $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getInfo()))); } $parameters = $cc->toArray(); $postString = $this->buildPostString($parameters); $cc = ''; $response = $this->makeCurlRequest($url, $postString); if ($this->_resultCode != '90') { $errorMsg = 'Payment code: ' . $response['PAYMENT.CODE'] . ' (' . $response['PROCESSING.REASON'] . ' - ' . $response['PROCESSING.RETURN'] . ')'; //Captura manual ativada if (Mage::getStoreConfig('payment/gwap_cc/captura')) { $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_ERROR, 'Ocorreu um erro', $errorMsg); } Mage::throwException($errorMsg); } $log->add($gwap->getOrderId(), 'Payment', 'capture()', Allpago_Mc_Model_Mc::STATUS_CAPTURED, 'Pagamento capturado'); //Salva UNIQUEID da captura para possibilitar estorno $gwap->setInfo(serialize(array('UNIQUEID' => $response['IDENTIFICATION.UNIQUEID']))); $gwap->setCaptureResult(serialize($this->_TID)); $gwap->setStatus(Allpago_Gwap_Model_Order::STATUS_CAPTURED); $gwap->setErrorCode(null); $gwap->setErrorMessage(null); $gwap->setTries(0); $gwap->setAbandoned(0); $gwap->save(); } return $this; }
/** * Create Zend_Currency object for current locale * * @param string $currency * @return Zend_Currency */ public function currency($currency) { Varien_Profiler::start('locale/currency'); if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) { $options = array(); try { $currencyObject = new Zend_Currency($currency, $this->getLocale()); } catch (Exception $e) { $currencyObject = new Zend_Currency($this->getCurrency(), $this->getLocale()); $options['name'] = $currency; $options['currency'] = $currency; $options['symbol'] = $currency; } $options = new Varien_Object($options); Mage::dispatchEvent('currency_display_options_forming', array('currency_options' => $options, 'base_code' => $currency)); $currencyObject->setFormat($options->toArray()); self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject; } Varien_Profiler::stop('locale/currency'); return self::$_currencyCache[$this->getLocaleCode()][$currency]; }
/** * Create Zend_Currency object for current locale * * @param string $currency * @return Zend_Currency */ public function currency($currency) { Varien_Profiler::start('locale/currency'); if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) { $options = array(); try { $currencyObject = new Zend_Currency($currency, $this->getLocale()); } catch (Exception $e) { /** * catch specific exceptions like "Currency 'USD' not found" * - back end falls with specific locals as Malaysia and etc. * * as we can see from Zend framework ticket * http://framework.zend.com/issues/browse/ZF-10038 * zend team is not going to change it behaviour in the near time */ $currencyObject = new Zend_Currency($currency); $options['name'] = $currency; $options['currency'] = $currency; $options['symbol'] = $currency; } $options = new Varien_Object($options); Mage::dispatchEvent('currency_display_options_forming', array('currency_options' => $options, 'base_code' => $currency)); $currencyObject->setFormat($options->toArray()); self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject; } Varien_Profiler::stop('locale/currency'); return self::$_currencyCache[$this->getLocaleCode()][$currency]; }
/** * Aggregate data for this campaign * * @param integer $incremental * @return Mzax_Emarketing_Model_Campaign */ public function aggregate($incremental = null) { $options = new Varien_Object(array('campaign_id' => $this->getId(), 'verbose' => false)); Mage::dispatchEvent($this->_eventPrefix . '_aggregate', array('options' => $options, 'campaign' => $this)); if ($incremental) { $options->setIncremental((int) $incremental); } /* @var $report Mzax_Emarketing_Model_Report */ $report = Mage::getSingleton('mzax_emarketing/report'); $report->aggregate($options->toArray()); return $this; }
/** * prepare collection for block to display * * @return Magestore_Marketingautomation_Block_Adminhtml_Contact_Grid */ protected function _prepareCollection() { $session = Mage::getModel('core/session'); $filterConditions = $session->getData('rp_conditions'); if (!$filterConditions) { $filterConditions = $this->_filterConditions; } $posorderCollection = Mage::getModel('webpos/posorder')->getCollection(); /* Jack - create an empty collection */ $collection = $posorderCollection; foreach ($collection->getItems() as $key => $item) { $collection->removeItemByKey($key); } /**/ /* Define variables and set default data */ $totalsSalesByUser = array(); $totalSales = 0; $incTimeStrings = array('2' => ' +1 day', '3' => ' +1 month', '4' => ' +1 day', '5' => ' +1 day', '6' => ' +1 week', '7' => ' +1 week'); $periodFormat = $filterConditions['period'] == 3 || $filterConditions['period'] == 6 || $filterConditions['period'] == 7 ? "Y-m-d" : "Y-m-d"; $specialPeriod = array('1', '2', '3', '4'); $stringTimeFrom = array('1' => 'monday this week', '2' => 'monday last week', '3' => 'first day of this month', '4' => 'first day of previous month'); $stringTimeTo = array('1' => 'sunday this week', '2' => 'sunday last week', '3' => 'last day of this month', '4' => 'last day of previous month'); $thisFriday = date($periodFormat, strtotime('friday this week')); $today = date($periodFormat); $locationIds = $this->locationIds; if (($filterConditions['from'] == '' || $filterConditions['to'] == '') && in_array($filterConditions['period'], $specialPeriod) == false) { $this->setCollection($collection); return parent::_prepareCollection(); } $startTime = in_array($filterConditions['range'], $specialPeriod) ? date($periodFormat, strtotime($stringTimeFrom[$filterConditions['range']])) : date($periodFormat, strtotime($filterConditions['from'])); $timeFrom = in_array($filterConditions['range'], $specialPeriod) ? date($periodFormat, strtotime($stringTimeFrom[$filterConditions['range']])) : date($periodFormat, strtotime($filterConditions['from'])); $timeTo = in_array($filterConditions['range'], $specialPeriod) ? date($periodFormat, strtotime($stringTimeTo[$filterConditions['range']])) : date("Y-m-d", strtotime($filterConditions['to'])); if ($timeFrom && $timeTo) { while ($timeFrom <= $timeTo) { $i = 0; foreach ($this->locationIds as $locationId => $displayName) { $isSave = true; if ($filterConditions['period'] == 1) { $endTime = $this->lastDayOf('year', new DateTime($timeFrom))->format('Y-m-d'); } else { if ($filterConditions['period'] == 3) { $endTime = $this->lastDayOf('month', new DateTime($timeFrom))->format('Y-m-d'); } else { $endTime = date('Y-m-d', strtotime($timeFrom . $incTimeStrings[$filterConditions['period']])); } } $endTime = strtotime($endTime) < strtotime($timeTo) ? $endTime : $timeTo; $itemDataObject = new Varien_Object(); if ($i == 0) { if ($filterConditions['period'] == 1) { $exTimeFrom = explode('-', $timeFrom); $itemDataObject->setData('period', $exTimeFrom[0]); } else { if ($filterConditions['period'] == 3) { $exTimeFrom = explode('-', $timeFrom); $itemDataObject->setData('period', $exTimeFrom[0] . '-' . $exTimeFrom[1]); } else { $itemDataObject->setData('period', $timeFrom); } } } else { $itemDataObject->setData('period', ''); } if ($itemDataObject->getData('period')) { $itemDataObject->setData('period', date('F j, Y', strtotime($itemDataObject->getData('period')))); } $webposOrderCollection = $this->getSalesCollection($timeFrom, $endTime, array('user_location_id' => $locationId)); $totalU = 0; if (count($webposOrderCollection) > 0) { foreach ($webposOrderCollection as $order) { $totalU += $order->getTotals(); } } if (!$totalU && $filterConditions['rp_settings']['show_empty_result'] == 'false') { $isSave = false; } if ($isSave) { $itemDataObject->setData('location', $displayName); $itemDataObject->setData('totals_sales', $totalU > 0 ? $totalU : '0.00'); $collection->addItem($itemDataObject); } $i++; } if ($filterConditions['period'] == 1 || $filterConditions['period'] == 3) { $timeFrom = date('Y-m-d', strtotime($endTime)); } else { $timeFrom = date($periodFormat, strtotime($timeFrom . $incTimeStrings[$filterConditions['period']])); } } /* get last item data $i = 0; foreach($this->locationIds as $locationId => $displayName){ $isSave = true; $beforeLastItem = new Varien_Object(); if($i == 0){ if($filterConditions['period'] == 1){ $exTimeFrom = explode('-',$timeTo); $beforeLastItem->setData('period',$exTimeFrom[0]); } else if($filterConditions['period'] == 3){ $exTimeFrom = explode('-',$timeTo); $beforeLastItem->setData('period',$exTimeFrom[0].'-'.$exTimeFrom[1]); } else $beforeLastItem->setData('period',$timeTo); } else $beforeLastItem->setData('period',''); if($beforeLastItem->getData('period')) $beforeLastItem->setData('period',date('F j, Y', strtotime($beforeLastItem->getData('period')))); $webposOrderCollection = $this->getSalesCollection($timeTo,$timeTo,array('user_location_id' => $locationId))->getFirstItem(); if( !$webposOrderCollection->getTotals() && $filterConditions['rp_settings']['show_empty_result'] == 'false') $isSave = false; if($isSave){ $beforeLastItem->setData('location',$displayName); $beforeLastItem->setData('totals_sales',$webposOrderCollection->getTotals()?$webposOrderCollection->getTotals():'0.00'); $collection->addItem($beforeLastItem); } $i++; } end last item*/ } /* set data for totals row */ $lastItemDataObject = new Varien_Object(); $lastItemDataObject->setData('period', 'Totals:'); $orders = $this->getSalesTotal($startTime, $endTime); $totalU = 0; if (count($orders) > 0) { foreach ($orders as $order) { $totalU += $order->getTotals(); } } $lastItemDataObject->setData('totals_sales', $totalU); $collection->addItem($lastItemDataObject); $this->setCollection($collection); /*set session for chart*/ $sessionObject = new Varien_Object(); foreach ($this->locationIds as $locationId => $locationName) { $orders = $this->getSalesTotal($startTime, $endTime, array('user_location_id' => $locationId)); $totalU = 0; if (count($orders) > 0) { foreach ($orders as $order) { $totalU += $order->getTotals(); } } $sessionObject->setData($locationName, $totalU); } Mage::getSingleton('core/session')->setData('total_sales', $sessionObject->toArray()); Mage::getSingleton('core/session')->setType('location'); $this->setTotalRow($sessionObject->toArray()); return parent::_prepareCollection(); }