/** * * @throws Exception * @return Varien_Object */ public function process() { $cacheId = $this->_getCacheKey(); $response = $cacheId ? Mage::app()->loadCache($cacheId) : false; if ($response) { $response = unserialize($response); } if (!$response instanceof Varien_Object) { $client = new Zend_Http_Client(self::API_URI, $this->_clientConfig); $client->setMethod(Zend_Http_Client::POST); $client->setParameterPost($this->getParams()); $result = $client->request(); $data = Zend_Json::decode($result->getBody()); if ($data['status'] != 201) { throw new Exception("Premailer failed to run: {$data['message']} #{$data['status']}"); } $htmlClient = new Zend_Http_Client($data['documents']['html'], $this->_clientConfig); $textClient = new Zend_Http_Client($data['documents']['txt'], $this->_clientConfig); $response = new Varien_Object(); $response->setVersion($data['version']); $response->setHtml($htmlClient->request()->getBody()); $response->setText($textClient->request()->getBody()); if ($cacheId) { $data = Mage::app()->saveCache(serialize($response), $cacheId, array(self::CACHE_KEY), 60 * 60); } } return $response; }
public function addAfterToHtml($html, Mage_Core_Block_Abstract $block) { $transportObject = new Varien_Object(); $transportObject->setHtml($html); Mage::dispatchEvent('aitunits_core_block_template_to_html_after', array('block' => $block, 'transport' => $transportObject)); $html = $transportObject->getHtml(); return $html; }
public function getGroupedHtml() { $html = parent::getGroupedHtml(); $_transportObject = new Varien_Object(); $_transportObject->setHtml($html); Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => $_transportObject)); $html = $_transportObject->getHtml(); return $html; }
/** * Returns product price block html * * @param Mage_Catalog_Model_Product $product * @param boolean $displayMinimalPrice */ public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '') { $html = parent::getPriceHtml($product, $displayMinimalPrice, $idSuffix); $container = new Varien_Object(); $container->setHtml($html); Mage::dispatchEvent('block_catalog_product_get_price_html', array('block' => $this, 'container' => $container)); $html = $container->getHtml(); return $html; }
/** * Retrieve messages in HTML format grouped by type * * @param string $type * @return string */ public function getGroupedHtml() { $html = parent::getGroupedHtml(); /** * Use single transport object instance for all blocks */ $_transportObject = new Varien_Object(); $_transportObject->setHtml($html); Mage::dispatchEvent('core_block_messages_get_grouped_html_after', array('block' => $this, 'transport' => $_transportObject)); $html = $_transportObject->getHtml(); return $html; }
/** * @test * @loadFixture testGoogleAnonymizationDisabled */ public function testGoogleAnonymizationDisabled() { $block = $this->app()->getLayout()->createBlock('googleanalytics/ga')->setTemplate('googleanalytics/ga.phtml'); $transport = new Varien_Object(); $transport->setHtml($block->toHtml()); $event = new Varien_Event(); $event->setData('block', $block); $event->setData('transport', $transport); $observer = new Varien_Event_Observer(); $observer->setEvent($event); $this->_model->setGAAnonymizerCode($observer); $this->assertNotContains('_anonymizeIp', $observer->getEvent()->getTransport()->getHtml()); }
/** * Add content of template block below price html if defined in config * * @return string */ public function _toHtml() { $html = trim(parent::_toHtml()); if (empty($html) || !Mage::getStoreConfigFlag('catalog/price/display_block_below_price')) { return $html; } if ($this->getTemplate() != $this->_tierPriceDefaultTemplate) { $htmlObject = new Varien_Object(); $htmlObject->setParentHtml($html); $htmlTemplate = $this->getLayout()->createBlock('core/template')->setTemplate('germansetup/price_info.phtml')->setFormattedTaxRate($this->getFormattedTaxRate())->setIsIncludingTax($this->isIncludingTax())->setIsIncludingShippingCosts($this->isIncludingShippingCosts())->setIsShowShippingLink($this->isShowShippingLink())->toHtml(); $htmlObject->setHtml($htmlTemplate); Mage::dispatchEvent('germansetup_after_product_price', array('html_obj' => $htmlObject, 'block' => $this)); $html = $htmlObject->getPrefix(); $html .= $htmlObject->getParentHtml(); $html .= $htmlObject->getHtml(); $html .= $htmlObject->getSuffix(); } return $html; }
protected function _toHtml() { if (!Mage::getStoreConfig('jeroenvermeulen_solarium/results/autocomplete_product_suggestions')) { return parent::_toHtml(); } $productIds = $this->getSuggestProductIds(); if (empty($productIds)) { return parent::_toHtml(); } else { // Magento by default starts with a hidden <li>, don't know why. $html = '<ul class="product_suggest"><li style="display: none"></li>'; $transport = new Varien_Object(); $transport->setHtml(null); // Event listener can fill this with HTML, <li> tags. Mage::dispatchEvent('jeroenvermeulen_solarium_get_product_suggest_html', array('product_ids' => $productIds, 'transport' => $transport)); if (!is_null($transport->getHtml())) { $html .= $transport->getHtml(); } else { $productCollection = $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToSelect(array('name', 'thumbnail', 'product_url')); $counter = 0; foreach ($productCollection as $product) { $rowClass = ++$counter % 2 ? 'odd' : 'even'; $imageUrl = Mage::helper('catalog/image')->init($product, 'thumbnail')->resize('50'); $showName = Mage::helper('core/string')->truncate($product->getName(), 100); $html .= sprintf('<li title="%s" class="%s" data-url="%s">', htmlentities($product->getName()), $rowClass, htmlentities($product->getProductUrl())); $html .= '<span class="suggestions-productimage">'; $html .= sprintf('<img src="%s" />', htmlentities($imageUrl)); $html .= '</span>'; $html .= '<span class="suggestions-productname">'; $html .= htmlentities($showName); $html .= '</span>'; $html .= '</li>'; } } $html .= '</ul>'; } return $html; }
/** * render the html for 1 bundled sales object item line <tr>$trInner</tr> * * @param $pdfItem * @param $subItems * @param $vertSpacing * @param bool $styleOverride * @param int $position * * @return string * @access public */ public function getPdfBundleItemRow($pdfItem, $subItems, $vertSpacing, $styleOverride = false, $position = 1) { $columns = $this->getPdfColumnHeaders(); if ($columns) { //check if the subitems of the bundle have separate prices $subItemsSum = 0; foreach ($subItems as $bundleItem) { $subItemsSum += $bundleItem['price']; } //don't display bundle price if subitems have prices if ($subItemsSum > 0) { $html = Mage::app()->getLayout()->createBlock('pdfcustomiser/pdf_item')->setPdfHelper($this)->setPdfItem($pdfItem)->setSubItems($subItems)->setVertSpacing($vertSpacing)->setStyleOverride($styleOverride)->setPosition($position)->setTemplate('fooman/pdfcustomiser/bundle-with-subitems.phtml')->toHtml(); } else { $pdfItem['productDetails']['Subitems'] = array(); foreach ($subItems as $bundleItem) { $bundleItem['Name'] = $bundleItem['productDetails']['Name']; //keep BC $pdfItem['productDetails']['Subitems'][] = $bundleItem; } $html = $this->getPdfItemRow($pdfItem, $vertSpacing, $styleOverride, $position); } } $transport = new Varien_Object(); $transport->setHtml($html); Mage::dispatchEvent('fooman_pdfcustomiser_pdf_item_row_bundle', array('item' => $pdfItem, 'subitems' => $subItems, 'transport' => $transport)); return $transport->getHtml(); }
/** * Mark content via the event transport mechanism. Magento 1.4.1+ * * @param $containerArgs array * @param $transport Varien_Object * @return void */ public function markContentViaTransport($containerArgs, Varien_Object $transport) { $transport->setHtml("<!-- BRIM_FPC {$containerArgs['name']} {$this->registerBlockUpdateData($containerArgs)} -->\n" . $transport->getHtml() . "\n" . "<!-- /BRIM_FPC {$containerArgs['name']} -->"); }
/** * Produce and return block's html output * * It is a final method, but you can override _toHtml() method in descendants if needed. * * @return string */ public final function toHtml() { Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this)); if (Mage::getStoreConfig('advanced/modules_disable_output/' . $this->getModuleName())) { return ''; } /* START: Added by Cm_Diehard */ // if setBlockIsDynamic and setSuppressOutput then we automatically render only a placeholder tag. if ($this->getBlockIsDynamic() && Mage::registry('diehard_lifetime')) { if ($this->getSuppressOutput()) { return '<div id="' . substr($this->getDiehardSelector(), 1) . '"></div>'; } else { if (FALSE) { return '<!-- DIEHARD_BLOCK|' . $this->getDiehardSelector() . '|' . json_encode($this->getCacheKeyInfo()) . ' -->'; } } } /* END: Added by Cm_Diehard */ $html = $this->_loadCache(); if ($html === false) { $translate = Mage::getSingleton('core/translate'); /** @var $translate Mage_Core_Model_Translate */ if ($this->hasData('translate_inline')) { $translate->setTranslateInline($this->getData('translate_inline')); } $this->_beforeToHtml(); $html = $this->_toHtml(); $this->_saveCache($html); if ($this->hasData('translate_inline')) { $translate->setTranslateInline(true); } } $html = $this->_afterToHtml($html); /** * Check framing options */ if ($this->_frameOpenTag) { $html = '<' . $this->_frameOpenTag . '>' . $html . '<' . $this->_frameCloseTag . '>'; } /** * Use single transport object instance for all blocks */ if (self::$_transportObject === null) { self::$_transportObject = new Varien_Object(); } self::$_transportObject->setHtml($html); Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => self::$_transportObject)); $html = self::$_transportObject->getHtml(); return $html; }
/** * Processing block html after rendering * * @param string $html * @return string */ protected function _afterToHtml($html) { $html = parent::_afterToHtml($html); $transport = new Varien_Object(); $transport->setHtml($html); Mage::dispatchEvent('checkout_block_cart_sidebar_aftertohtml', array('block' => $this, 'transport' => $transport)); return $transport->getHtml(); }
public function templateHtmlAction() { $response = new Varien_Object(); $response->setError(false); $templateId = $this->getRequest()->getParam('template'); /* @var $template Mzax_Emarketing_Model_Template */ $template = Mage::getModel('mzax_emarketing/template')->load($templateId); $response->setHtml($template->getBody()); $this->getResponse()->setHeader('Content-Type', 'application/json')->setBody($response->toJson()); }
public function testShowWarningForOpenInvoicePayments() { $transport = new Varien_Object(); $transport->setHtml('Foo'); $observer = Mage::getModel('ops/observer'); $event = new Varien_Event_Observer(); $event->setBlock(''); $observer->appendPartialCaptureWarningForOpenInvoice($event); $this->assertEquals('Foo', $transport->getHtml()); $order = new Varien_Object(); $payment = new Varien_Object(); $methodInstance = Mage::getModel('ops/payment_openInvoiceNl'); $payment->setMethodInstance($methodInstance); $order->setPayment($payment); $invoice = $this->getModelMock('sales/order_invoice', array('getOrder')); $invoice->expects($this->any())->method('getOrder')->will($this->returnValue($order)); Mage::register('current_invoice', $invoice); $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_invoice_totals'); $blockMock = $this->getBlockMock('ops/adminhtml_sales_order_invoice_warning_openInvoice', array('renderView')); $blockMock->expects($this->once())->method('renderView')->will($this->returnValue('<b>warning</b>')); $this->replaceByMock('block', 'ops/adminhtml_sales_order_invoice_warning_openInvoice', $blockMock); $event->setBlock($block); $event->setTransport($transport); $observer->appendPartialCaptureWarningForOpenInvoice($event); $this->assertEquals('Foo<b>warning</b>', $transport->getHtml()); $this->assertNotEquals('Bar<span>warning</span>', $transport->getHtml()); Mage::unregister('current_invoice'); }
public function testAppendParcelAnnouncementValidationToShipping() { $sessionMock = $this->getModelMockBuilder('checkout/session')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'checkout/session', $sessionMock); $sessionMock = $this->getModelMockBuilder('customer/session')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'customer/session', $sessionMock); $intrashipConfigMock = $this->getModelMock('intraship/config', array('isEnabled')); $intrashipConfigMock->expects($this->any())->method('isEnabled')->will($this->returnValue(true)); $this->replaceByMock('model', 'intraship/config', $intrashipConfigMock); $this->store = Mage::app()->getStore(0)->load(0); $this->store->setConfig('intraship/dhlaccount/active', true); $transport = new Varien_Object(); $transport->setHtml('Foo'); $observer = Mage::getModel('dhlaccount/observer'); $event = new Varien_Object(); $block = Mage::app()->getLayout()->getBlockSingleton('checkout/onepage_shipping'); $blockMock = $this->getBlockMock('dhlaccount/checkout_onepage_parcelannouncement', array('renderView')); $blockMock->expects($this->once())->method('renderView')->will($this->returnValue('<b>Foo</b>')); $this->replaceByMock('block', 'dhlaccount/checkout_onepage_parcelannouncement', $blockMock); $event->setBlock($block); $event->setTransport($transport); $observer->appendParcelAnnouncementValidationToShipping($event); $this->assertEquals('Foo<b>Foo</b>', $transport->getHtml()); $this->assertNotEquals('<b>Foo</b>', $transport->getHtml()); }
public function getEmptyBlockHtml($block) { Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $block)); if (Mage::getStoreConfig('advanced/modules_disable_output/' . $block->getModuleName())) { return ''; } /** * Use single transport object instance for all blocks */ $transportObject = new Varien_Object(); $transportObject->setHtml(''); Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $block, 'transport' => $transportObject)); $html = $transportObject->getHtml(); return $html; }
/** * Produce and return block's html output * * It is a final method, but you can override _toHtml() method in descendants if needed. * * @return string */ public final function toHtml() { Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this)); if (Mage::getStoreConfig('advanced/modules_disable_output/' . $this->getModuleName())) { return ''; } $html = $this->_loadCache(); if ($html === false) { $translate = Mage::getSingleton('core/translate'); /** @var $translate Mage_Core_Model_Translate */ if ($this->hasData('translate_inline')) { $translate->setTranslateInline($this->getData('translate_inline')); } $this->_beforeToHtml(); $html = $this->_toHtml(); $this->_saveCache($html); if ($this->hasData('translate_inline')) { $translate->setTranslateInline(true); } } $html = $this->_afterToHtml($html); /** * Check framing options */ if ($this->_frameOpenTag) { $html = '<' . $this->_frameOpenTag . '>' . $html . '<' . $this->_frameCloseTag . '>'; } /** * Use single transport object instance for all blocks */ if (self::$_transportObject === null) { self::$_transportObject = new Varien_Object(); } self::$_transportObject->setHtml($html); Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => self::$_transportObject)); $html = self::$_transportObject->getHtml(); return $html; }
/** * For a given product price block check if the product is active * - if it is active then set the price html as the default message * * @param Mage_Catalog_Block_Product_Price $oBlock * @param Varien_Object $oTransport */ protected function transformPriceBlock($oBlock, $oTransport) { $oProduct = $oBlock->getProduct(); $iCurrentProductId = $oProduct->getId(); if ($this->oB2BHelper->isProductActive($oProduct) === false) { // To stop duplicate information being displayed validate that we only do this once per product if ($iCurrentProductId !== self::$iLastProductId) { self::$iLastProductId = $iCurrentProductId; $oTransport->setHtml($this->oB2BHelper->getLoginMessage()); } else { $oTransport->setHtml(''); } $this->setSymmetricsProductType($oProduct); } }
/** * Produce and return block's html output * * It is a final method, but you can override _toHtml() method in descendants if needed. * * @return string */ public final function toHtml() { // MSP HACK: Start /* @var $ltsCache MSP_LTS2_Model_Cache */ $ltsCache = Mage::getSingleton('msp_lts2/cache'); if ($ltsCache->isActive() && !Mage::helper('msp_lts2')->isAdminArea() && $ltsCache->canCacheAction()) { $blockName = $this->getNameInLayout(); $blockCacheHandling = $ltsCache->getBlockCacheHandling($blockName); if (in_array($blockCacheHandling, array(MSP_LTS2_Model_Rule_Cache::HANDLING_CACHE))) { $cacheKey = $ltsCache->getBlockCacheKey($blockName); if ($ltsCache->cacheItemExists($cacheKey)) { $ltsCache->setCacheBlockStatus($blockName, MSP_LTS2_Model_Cache::CACHE_STATUS_HIT); return $ltsCache->getBlockPlaceholder($blockName, true); } } } // MSP HACK: End Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this)); if (Mage::getStoreConfig('advanced/modules_disable_output/' . $this->getModuleName())) { return ''; } $html = $this->_loadCache(); if ($html === false) { $translate = Mage::getSingleton('core/translate'); /** @var $translate Mage_Core_Model_Translate */ if ($this->hasData('translate_inline')) { $translate->setTranslateInline($this->getData('translate_inline')); } $this->_beforeToHtml(); $html = $this->_toHtml(); $this->_saveCache($html); if ($this->hasData('translate_inline')) { $translate->setTranslateInline(true); } } $html = $this->_afterToHtml($html); /** * Check framing options */ if ($this->_frameOpenTag) { $html = '<' . $this->_frameOpenTag . '>' . $html . '<' . $this->_frameCloseTag . '>'; } /** * Use single transport object instance for all blocks */ if (self::$_transportObject === null) { self::$_transportObject = new Varien_Object(); } self::$_transportObject->setHtml($html); Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => self::$_transportObject)); $html = self::$_transportObject->getHtml(); // MSP HACK: Start if ($ltsCache->isActive() && !Mage::helper('msp_lts2')->isAdminArea() && $ltsCache->canCacheAction()) { if (in_array($blockCacheHandling, array(MSP_LTS2_Model_Rule_Cache::HANDLING_CACHE))) { $ltsCache->setBlock($blockName, $html); } elseif (in_array($blockCacheHandling, array(MSP_LTS2_Model_Rule_Cache::HANDLING_NOCACHE))) { $ltsCache->setTmpBlock($blockName, $html); } if (in_array($blockCacheHandling, array(MSP_LTS2_Model_Rule_Cache::HANDLING_CACHE, MSP_LTS2_Model_Rule_Cache::HANDLING_NOCACHE))) { return $ltsCache->getBlockPlaceholder($blockName); } } // MSP HACK: End return $html; }
/** * Appends the points balance in the header somewhere * @param Mage_Catalog_Block_Product_List $block * @param Varien_Object $transport */ public function appendToCatalogListing($block, $transport) { // Should we be checking this auto-integration? if (!Mage::getStoreConfigFlag('rewards/autointegration/product_listing')) { return $this; } // Block is a price block. if (!$block instanceof Mage_Catalog_Block_Product_List) { return $this; } $all_products = $block->getLoadedProductCollection(); $html = $transport->getHtml(); $html = $this->_getNewCatalogListingHtml($html, $all_products); $transport->setHtml($html); return $this; }