public function optionsAction() { $productId = $this->getRequest()->getParam('product_id'); // Prepare helper and params $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId(false); $params->setSpecifyOptions(false); // Render page try { Mage::getSingleton('core/session')->setReferrerUrl($this->_getRefererUrl()); $viewHelper->prepareAndRender($productId, $this, $params); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } }
/** * This is a straigh copy/paste of * * Mage_Catalog_ProductController::viewAction() * * Only change is that I replaced the $viewHelper so that we could * hook into prepareAndRender() */ public function previewAction() { // Get initial data from request $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); $specifyOptions = $this->getRequest()->getParam('options'); // Prepare helper and params $viewHelper = Mage::helper('tadic_avp/catalog_product_view'); $params = new Varien_Object(); $params->setCategoryId($categoryId); $params->setSpecifyOptions($specifyOptions); // Render page try { $viewHelper->prepareAndRender($productId, $this, $params); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } }
public function windowAction() { // Get data from request and load product $product_id = $this->getRequest()->getParams(); $product = Mage::getModel('catalog/product')->load($product_id['product_id']); // Prepare helper and params $params = new Varien_Object(); $params->setSpecifyOptions(false); //$params->setCategoryId($categoryId); //initilize product and render page $viewHelper = Mage::helper('catalog/product_view'); $viewHelper->prepareAndRender($product->getId(), $this, $params); }
public function getOptionsHtml($controller, $productId = null) { $specifyOptions = $controller->getRequest()->getParam('options'); // Prepare helper and params $viewHelper = Mage::helper('ajaxcart/product_view'); $params = new Varien_Object(); //$params->setCategoryId($categoryId); $params->setSpecifyOptions($specifyOptions); try { $viewHelper->prepareAndRender($productId, $controller, $params); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { } else { Mage::logException($e); } } }
public function viewAction() { // Get initial data from request $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); $specifyOptions = $this->getRequest()->getParam('options'); $redirectskus = Mage::getStoreConfig('configuration/configuration_steelsku/skusredirectionfilter'); $catalogloav = Mage::getModel('catalog/product')->load($productId); $categories = $catalogloav->getCategoryIds(); $load_sku = $catalogloav->getSku(); $skus = explode(',', trim($redirectskus)); if (in_array(282, $categories) && !in_array($load_sku, $skus)) { $this->_redirect('building-material/tmt-steel.html'); return; } // Prepare helper and params $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId($categoryId); $params->setSpecifyOptions($specifyOptions); // Render page try { $viewHelper->prepareAndRender($productId, $this, $params); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } }
/** * Product view action */ public function viewAction() { $html = $this->_loadCache(); if ($html === false) { // Get initial data from request $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); $path = (string) $this->getRequest()->getParam('path'); $path = str_replace("_!_", "/", $path); $path[0] == "\\/" ? $path = substr($path, 1, strlen($path)) : $path; $tableName = Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'); $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $query = "select MAIN_TABLE.`product_id` from `{$tableName}` as MAIN_TABLE where MAIN_TABLE.`request_path` in('{$path}')"; $readresult = $write->query($query); if ($row = $readresult->fetch()) { $productId = $row['product_id']; } $this->_cacheTags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_' . $productId; //print_r($this->getCacheTags()); $specifyOptions = $this->getRequest()->getParam('options'); // Prepare helper and params $viewHelper = Mage::helper('quickshop/product_view'); $params = new Varien_Object(); $params->setCategoryId($categoryId); $params->setSpecifyOptions($specifyOptions); // Render page try { $viewHelper->prepareAndRender($productId, $this, $params); $html = $this->getLayout()->getBlock('root')->toHtml(); $this->_saveCache($html); $this->getResponse()->setBody($html); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } } else { $this->getResponse()->setBody($html); } }
/** * Product options action */ public function optionsAction() { try { $storeId = Mage::app()->getStore()->getStoreId(); $params = $this->getRequest()->getParams(); if (isset($params['url'])) { $url = $params['url']; if (preg_match('/product/', $url)) { $arr = explode('catalog/product/view/id/', $url); $id = explode('/', end($arr)); $id = (int) $id[0]; if ($id == 0) { $parts = parse_url($url); $arr = explode('/', $parts['path']); $urlPath = end($arr); $p = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('url_path', $urlPath)->getFirstItem(); $id = (int) $p->getId(); } } elseif (preg_match('/item/', $url)) { $arr = explode('/item/', $url); $itemId = explode('/', end($arr)); $itemId = (int) $itemId[0]; $item = Mage::getModel('wishlist/item')->load($itemId); $id = $item->getProductId(); if ($id == 0) { $parts = parse_url($url); $arr = explode('/', $parts['path']); $urlPath = end($arr); $collection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('request_path', array('like' => '%' . $urlPath . '%'))->addFieldToFilter('store_id', array('eq' => $storeId)); $id = (int) $collection->getFirstItem()->getProductId(); } } else { $parts = parse_url($url); $arr = explode('/', $parts['path']); $urlPath = end($arr); $collection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('request_path', array('like' => '%' . $urlPath . '%'))->addFieldToFilter('store_id', array('eq' => $storeId)); $id = (int) $collection->getFirstItem()->getProductId(); } } if (isset($params['item'])) { $itemId = (int) $params['item']; $item = Mage::getModel('wishlist/item')->load($itemId); $id = (int) $item->getProductId(); } $product = Mage::getModel('catalog/product')->load($id); /** * Check product availability */ if (!$product->getId()) { echo $this->__('Unable to find Product ID.'); return; } else { $productId = $product->getId(); // Prepare helper and params $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId(false); $params->setSpecifyOptions(false); // Render page try { $viewHelper->prepareAndRender($productId, $this, $params); } catch (Exception $ex) { if ($ex->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { echo $this->__('Unable to find Product ID.'); return; } } else { Mage::logException($ex); echo $this->__('Unable to find Product ID.'); return; } } } } catch (Exception $ex) { echo $this->__('Unable to find Product ID.'); return; } }
public function optionsAction() { $productId = $this->getRequest()->getParam('product_id'); // Prepare helper and params $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId(false); $params->setSpecifyOptions(false); // Render page try { $productHelper = Mage::helper('catalog/product'); if (!$params) { $params = new Varien_Object(); } // Standard algorithm to prepare and rendern product view page $product = $productHelper->initProduct($productId, $this, $params); if (!$product) { throw new Mage_Core_Exception($this->__('Product is not loaded'), $this->ERR_NO_PRODUCT_LOADED); } $buyRequest = $params->getBuyRequest(); if ($buyRequest) { $productHelper->prepareProductOptions($product, $buyRequest); } if ($params->hasConfigureMode()) { $product->setConfigureMode($params->getConfigureMode()); } Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product)); if ($params->getSpecifyOptions()) { $notice = $product->getTypeInstance(true)->getSpecifyOptionMessage(); Mage::getSingleton('catalog/session')->addNotice($notice); } Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId()); /***********************/ $design = Mage::getSingleton('catalog/design'); $settings = $design->getDesignSettings($product); if ($settings->getCustomDesign()) { $design->applyCustomDesign($settings->getCustomDesign()); } $update = $this->getLayout()->getUpdate(); $update->addHandle('default'); $this->addActionLayoutHandles(); $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId()); $update->addHandle('PRODUCT_' . $product->getId()); $this->loadLayoutUpdates(); // Apply custom layout update once layout is loaded $layoutUpdates = $settings->getLayoutUpdates(); if ($layoutUpdates) { if (is_array($layoutUpdates)) { foreach ($layoutUpdates as $layoutUpdate) { $update->addUpdate($layoutUpdate); } } } $this->generateLayoutXml()->generateLayoutBlocks(); // Apply custom layout (page) template once the blocks are generated /* if ($settings->getPageLayout()) { $controller->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout()); } */ $currentCategory = Mage::registry('current_category'); $root = $this->getLayout()->getBlock('root'); if ($root) { $controllerClass = $this->getFullActionName(); if ($controllerClass != 'catalog-product-view') { $root->addBodyClass('catalog-product-view'); } $root->addBodyClass('product-' . $product->getUrlKey()); if ($currentCategory instanceof Mage_Catalog_Model_Category) { $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey()); } } /***********************/ $this->initLayoutMessages(array('catalog/session', 'tag/session', 'checkout/session'))->renderLayout(); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } }
public function loadAllProductsOptionsAction() { $result = array('products' => array()); try { $alertError = Mage::getSingleton('core/session')->getMiniCartAlertError(true); // Get initial data from request $categoryId = (int) $this->getRequest()->getParam('category', false); $products = $this->getRequest()->getParam('products'); foreach ($products as $requestPath) { Mage::unregister('current_product'); Mage::unregister('product'); Mage::unregister('current_category'); Mage::unregister('storeId'); Mage::unregister('_singleton/catalog/product_type'); Mage::unregister('_singleton/catalog/product_option'); $this->getLayout()->getUpdate()->resetHandles(); if (is_numeric($requestPath)) { $productId = $requestPath; } else { $productId = (int) $this->_getProductIdByRequestPath($requestPath); } $params = new Varien_Object(); $params->setCategoryId($categoryId); $params->setSpecifyOptions($this->getRequest()->getParam('options')); $finalPrice = null; $qty = null; /** @var $productHelper Mage_Catalog_Helper_Product */ $productHelper = Mage::helper('catalog/product'); if (method_exists($productHelper, 'initProduct')) { $product = $productHelper->initProduct($productId, $this, $params); } else { $this->getRequest()->setParam('id', $productId); $product = $this->_initProduct(); } if (!$product) { throw new Exception('Product is not loaded'); } $buyRequest = $params->getBuyRequest(); if ($buyRequest) { $productHelper->prepareProductOptions($product, $buyRequest); } Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product)); if (method_exists($productHelper, 'initProduct')) { Mage::helper('catalog/product_view')->initProductLayout($product, $this); } else { $this->_initProductLayout($product); } if ($product->getTypeId() == 'grouped') { $viewBlockGrouped = $this->getLayout()->getBlock('product.info.grouped'); $html = $viewBlockGrouped->toHtml(); if ($this->getDataHelper()->isEnabledGroupedConfiguration()) { $html .= '<script type="text/javascript">optionsPrice = {};if(typeof tierPriceElement == \'undefined\'){tierPriceElement = {update:function(){}};}</script>'; $html .= '<div id="product_addtocart_form"></div>'; $html .= str_replace('var optionsPrice', 'optionsPrice', $this->getLayout()->getBlock('grouped_product_edit')->toHtml()); $html = str_replace('var bundle', 'bundle', $html); } } else { $additionalJs = ''; $optionsBlock = $this->getLayout()->getBlock('product.info.options.wrapper'); $viewBlock = $this->getLayout()->getBlock('product.info'); if ($product->getTypeId() == 'bundle') { $viewBlockBundle = $this->getLayout()->getBlock('product.info.bundle'); $additionalJs = "taxCalcMethod = '" . Mage::helper('tax')->getConfig()->getAlgorithm($product->getStore()) . "';"; $additionalJs .= "CACL_UNIT_BASE = '" . Mage_Tax_Model_Calculation::CALC_UNIT_BASE . "';"; $additionalJs .= "CACL_ROW_BASE = '" . Mage_Tax_Model_Calculation::CALC_ROW_BASE . "';"; $additionalJs .= "CACL_TOTAL_BASE = '" . Mage_Tax_Model_Calculation::CALC_TOTAL_BASE . "';"; $additionalJs .= 'optionsPrice.tierPrices = [];bundle = new Product.Bundle(' . $viewBlockBundle->getJsonConfig() . ');'; $additionalJs .= "if(typeof Itoris.BundlePromotions == 'undefined'){Itoris.BundlePromotions = Class.create();}"; } $html = '<script type="text/javascript">'; $html .= 'optionsPrice = new MiniCartProductOptionsPrice(' . $viewBlock->getJsonConfig() . ');'; $html .= $additionalJs . '</script>'; if ($product->getHasOptions() || $product->getTypeId() != 'simple') { $calendar = Mage::app()->getLayout()->createBlock('core/html_calendar')->setTemplate('page/js/calendar.phtml'); $html .= $calendar->toHtml() . $optionsBlock->toHtml(); } } if ($this->getDataHelper()->isEnabledDynamicProductOptions()) { $html = $this->_addDynamicOptionsHtml($html); } $result['products'][] = array('content' => $html, 'product_name' => $product->getName(), 'product_id' => $product->getId(), 'product_type' => $product->getTypeId(), 'price' => Mage::app()->getStore()->formatPrice($finalPrice ? $finalPrice : Mage::helper('tax')->getPrice($product, $product->getFinalPrice()), false), 'qty' => $qty ? (int) $qty : 1, 'request_path' => $requestPath); } $result['alert_error'] = $alertError; } catch (Exception $e) { $result['error'] = 'Product has not been loaded'; $result['error_d'] = $e->getMessage(); } $this->getResponse()->setBody(Zend_Json::encode($result)); }
public function optionsAction() { $productId = $this->getRequest()->getParam('id'); if (empty($productId)) { $path = base64_decode($this->getRequest()->getParam('path')); $oRewrite = Mage::getModel('core/url_rewrite')->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($path); $productId = $oRewrite->getProductId(); } // Prepare helper and params $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId(false); $params->setSpecifyOptions(false); // Render page try { $viewHelper->prepareAndRender($productId, $this, $params); } catch (Exception $e) { if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } } else { Mage::logException($e); $this->_forward('noRoute'); } } }
public function catalogProductView($observer) { $action = $observer->getEvent()->getControllerAction(); if ($action->getRequest()->getParam('iswebposcart') == 'true') { $categoryId = (int) $action->getRequest()->getParam('category', false); $productId = (int) $action->getRequest()->getParam('id'); $specifyOptions = $action->getRequest()->getParam('options'); $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId($categoryId); $params->setSpecifyOptions($specifyOptions); $productHelper = Mage::helper('catalog/product'); $result = array(); try { $product = $productHelper->initProduct($productId, $action, $params); if (!$product) { $this->_getSession->addError($viewHelper->__('Product is not loaded')); } Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product)); $viewHelper->initProductLayout($product, $action); /* Daniel - doesn't allow add out of stock product to cart */ if (!$product->isAvailable()) { $result['outofstock'] = true; } /* end */ } catch (Exception $e) { return $this; } $action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $params = $action->getRequest()->getParams(); try { $result['hasOptions'] = true; if (isset($params['groupmessage']) && $action->getLayout()->getMessagesBlock()) { $action->getLayout()->getMessagesBlock()->addMessages($this->_getSession()->getMessages(true)); $action->getLayout()->getMessagesBlock()->setEscapeMessageFlag($this->_getSession()->getEscapeMessages(true)); $result['message'] = $action->getLayout()->getMessagesBlock()->getGroupedHtml(); } else { $this->_getSession()->getMessages(true); $this->_getSession()->getEscapeMessages(true); } if ($typeBlock = Mage::getStoreConfig("webpos/product/{$product->getTypeId()}")) { $productBlock = $action->getLayout()->createBlock($typeBlock, 'ajaxcart_product_view'); } else { $productBlock = $action->getLayout()->createBlock('webpos/product_view', 'ajaxcart_product_view'); } /* add all js $result['optionjs'] = $productBlock->getJsItems(); */ /* Daniel - updated - js from colorselectorplus */ $optionjss = array(); /* add js from other extensions - for example: $optionjss[] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS).'cjm/colorselectorplus/colorselected.js'; $optionjss[] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);.'js/colorselectorplus/colorselected.js'; */ $result['optionjs'] = $optionjss; /* end */ $result['optionhtml'] = $productBlock->toHtml(); } catch (Exception $e) { } $action->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } }