public function configureAction() { $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } if (!$quoteItem) { $this->_getSession()->addError($this->__('Quote item is not found.')); $this->_redirect('checkout/cart'); return; } try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); $id = $quoteItem->getProduct()->getId(); $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($id); if (is_array($parentIds) && count($parentIds)) { $id = current($parentIds); } Mage::helper('catalog/product_view')->prepareAndRender($id, $this, $params); } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot configure product.')); Mage::logException($e); $this->_goBack(); 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 { 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'); } } }
/** * Action to reconfigure cart item * Modified to allow configuration of simple items assigned to configurables. */ public function configureAction() { // Extract item and product to configure $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } $productId = $quoteItem->getProduct()->getId(); //Check to see if this is a simple assigned to a configurable. if ($quoteItem->getOptionByCode('cpid')) { $cpid = $quoteItem->getOptionByCode('cpid')->getValue(); $productId = (int) $cpid; } if (!$quoteItem) { $this->_getSession()->addError($this->__('Quote item is not found.')); $this->_redirect('checkout/cart'); return; } try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); Mage::helper('catalog/product_view')->prepareAndRender($productId, $this, $params); } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot configure product: ' . $quoteItem->getProduct()->getId())); Mage::logException($e); $this->_goBack(); return; } }
public function indexAction() { // Extract item and product to configure //$params = (int) $this->getRequest()->getParam(); //echo '<pre>s';print_r($params);exit; /*$id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } if (!$quoteItem) { $this->_getSession()->addError($this->__('Quote item is not found.')); $this->_redirect('checkout/cart'); return; }*/ try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setDesignerMode(true); //$params->setBuyRequest($quoteItem->getBuyRequest()); //echo '<pre>';print_r($params);exit; Mage::helper('catalog/product_view')->prepareAndRender('1', $this, $params); } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot Design product.')); Mage::logException($e); $this->_goBack(); return; } }
protected function _initProduct() { $categoryId = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); $productId = $this->getRequest()->getParam('id'); $params = new Varien_Object(); $params->setCategoryId($categoryId); return Mage::helper('catalog/product')->initProduct($productId, $this, $params); }
/** * Initialize requested product object * * @return Mage_Catalog_Model_Product */ protected function _initProduct() { $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); $params = new Varien_Object(); $params->setCategoryId($categoryId); return Mage::helper('catalog/product')->initProduct($productId, $this, $params); }
public function imagesAction() { $categoryId = (int) $this->getRequest()->getParam('category', false); $productId = (int) $this->getRequest()->getParam('id'); $params = new Varien_Object(); $params->setCategoryId($categoryId); if (!($product = $this->_initProduct($productId, $this, $params))) { if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { $this->_redirect(''); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); } return; } $this->loadLayout(); $this->renderLayout(); }
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'); } } }
/** * Action to reconfigure cart item */ public function configureAction() { // Extract item and product to configure $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } if (!$quoteItem) { $this->_getSession()->addError($this->__('Quote item is not found.')); $this->_redirect('checkout/cart'); return; } try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); Mage::helper('Mage_Catalog_Helper_Product_View')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params); } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot configure product.')); Mage::logException($e); $this->_goBack(); return; } }
public function writeTempFile($curr_page = 0, $length = 50, $filename = '') { $products = $this->getFeed()->getProductsCollection('', $curr_page, $length); $stock_collection = Mage::getResourceModel('cataloginventory/stock_item_collection'); $content = file_get_contents($this->getFeed()->getDirPath() . '/feed-' . $this->getFeed()->getId() . '-xml-product-block-template.tmp'); $fp = fopen($this->getFeed()->getTempFilePath(), 'a'); $log_fp = fopen(sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-' . $this->getFeed()->getId() . '.txt'), 'a'); $log_content = date("F j, Y, g:i:s a") . ', page:' . $curr_page . ', items selected:' . count($products) . "\n"; fwrite($log_fp, $log_content); fclose($log_fp); $store = Mage::getModel('core/store')->load($this->getFeed()->getStoreId()); $root_category = Mage::getModel('catalog/category')->load($store->getRootCategoryId()); if (Mage::getStoreConfig('gomage_feedpro/imagesettings/enable')) { $image_width = intval(Mage::getStoreConfig('gomage_feedpro/imagesettings/width')); $image_height = intval(Mage::getStoreConfig('gomage_feedpro/imagesettings/height')); } else { $image_width = 0; $image_height = 0; } foreach ($products as $_product) { $category_path = array(); $category = null; foreach ($_product->getCategoryIds() as $id) { $_category = $this->getFeed()->getCategoriesCollection()->getItemById($id); if (is_null($category) || $category && $_category && $category->getLevel() < $_category->getLevel()) { $category = $_category; } } if ($category) { $category_path = array($category->getName()); $parent_id = $category->getParentId(); if ($category->getLevel() > $root_category->getLevel()) { while ($_category = $this->getFeed()->getCategoriesCollection()->getItemById($parent_id)) { if ($_category->getLevel() <= $root_category->getLevel()) { break; } $category_path[] = $_category->getName(); $parent_id = $_category->getParentId(); } } } $product = new Varien_Object(); if ($category) { $product->setCategory($category->getName()); $product->setCategoryId($category->getEntityId()); $product->setCategorySubcategory(implode(' -> ', array_reverse($category_path))); } else { $product->setCategory(''); $product->setCategorySubcategory(''); } $template_attributes = $this->getAllVars($content); $custom_attributes = Mage::getResourceModel('gomage_feed/custom_attribute_collection'); $custom_attributes->load(); foreach ($template_attributes as $attribute_code) { $value = null; switch ($attribute_code) { case 'parent_sku': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $value = $parent_product->getSku(); } else { $value = ''; } break; case 'parent_base_image': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $_prod = Mage::getModel('catalog/product')->load($parent_product->getId()); } else { $_prod = Mage::getModel('catalog/product')->load($_product->getId()); } try { if ($image_width || $image_height) { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height); } else { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image'); } } catch (Exception $e) { $image_url = ''; } $value = $image_url; break; case 'price': if (in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) { $value = $store->convertPrice($_product->getMinimalPrice(), false, false); } else { $value = $store->convertPrice($_product->getPrice(), false, false); } break; case 'store_price': case 'final_price': $value = $store->convertPrice($_product->getFinalPrice(), false, false); break; case 'image': case 'gallery': case 'media_gallery': $_prod = Mage::getModel('catalog/product')->load($_product->getId()); try { if ($image_width || $image_height) { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height); } else { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image'); } } catch (Exception $e) { $image_url = ''; } $product->setData($attribute_code, $image_url); break; case 'image_2': case 'image_3': case 'image_4': case 'image_5': if (!$_product->hasData('media_gallery_images')) { $_prod = Mage::getModel('catalog/product')->load($_product->getId()); $_product->setData('media_gallery_images', $_prod->getMediaGalleryImages()); } $i = 0; foreach ($_product->getMediaGalleryImages() as $_image) { $i++; if ('image_' . $i == $attribute_code) { if ($image_width || $image_height) { $product->setData($attribute_code, (string) Mage::helper('catalog/image')->init($_product, 'image', $_image->getFile())->resize($image_width, $image_height)); } else { $product->setData($attribute_code, $_image['url']); } } } break; case 'parent_url': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $product->setParentUrl($parent_product->getProductUrl(false)); break; } $product->setParentUrl($_product->getProductUrl(false)); break; case 'url': $product->setUrl($_product->getProductUrl(false)); break; default: if (strpos($attribute_code, 'custom:') === 0) { $custom_code = trim(str_replace('custom:', '', $attribute_code)); if ($custom_attribute = $custom_attributes->getItemByColumnValue('code', $custom_code)) { $options = Zend_Json::decode($custom_attribute->getData('data')); foreach ($options as $option) { foreach ($option['condition'] as $condition) { switch ($condition['attribute_code']) { case 'product_type': $attr_value = $_product->getTypeId(); break; case 'price': if (in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) { $attr_value = $store->convertPrice($_product->getMinimalPrice(), false, false); } else { $attr_value = $store->convertPrice($_product->getPrice(), false, false); } break; case 'store_price': $attr_value = $store->convertPrice($_product->getFinalPrice(), false, false); break; case 'parent_url': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $attr_value = $parent_product->getProductUrl(false); break; } $attr_value = $_product->getProductUrl(false); break; case 'image': case 'gallery': case 'media_gallery': if (!$_product->hasData('product_base_image')) { $_prod = Mage::getModel('catalog/product')->load($_product->getId()); try { if ($image_width || $image_height) { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height); } else { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image'); } } catch (Exception $e) { $image_url = ''; } $_product->setData('product_base_image', $image_url); $attr_value = $image_url; } else { $attr_value = $_product->getData('product_base_image'); } break; case 'url': $attr_value = $_product->getProductUrl(false); break; case 'qty': if ($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())) { $attr_value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty()); } else { $attr_value = 0; } break; case 'is_in_stock': $attr_value = ceil(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock()); if (!$attr_value || $attr_value == '' || $attr_value == null) { $attr_value = 0; } // if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){ // // $attr_value = $stock_collection->getItemByColumnValue('product_id', $_product->getId())->getData('is_in_stock'); // // }else{ // // $attr_value = 0; // // } break; case 'category': $attr_value = $product->getCategory(); break; case 'category_id': $attr_value = $_product->getCategoryIds(); break; default: $attr_value = $_product->getData($condition['attribute_code']); } $cond_value = $condition['value']; $is_multi = false; if ($product_attribute = $_product->getResource()->getAttribute($condition['attribute_code'])) { if ($product_attribute->getFrontendInput() == 'multiselect') { $is_multi = true; $attr_value = explode(',', $attr_value); } } if ($condition['attribute_code'] == 'category_id') { $is_multi = true; } switch ($condition['condition']) { case 'eq': if (!$is_multi && $attr_value == $cond_value || $is_multi && in_array($cond_value, $attr_value)) { continue 2; } else { continue 3; } break; case 'neq': if (!$is_multi && $attr_value != $cond_value || $is_multi && !in_array($cond_value, $attr_value)) { continue 2; } else { continue 3; } break; case 'gt': if ($attr_value > $cond_value) { continue 2; } else { continue 3; } break; case 'lt': if ($attr_value < $cond_value) { continue 2; } else { continue 3; } break; case 'gteq': if ($attr_value >= $cond_value) { continue 2; } else { continue 3; } break; case 'lteq': if ($attr_value <= $cond_value) { continue 2; } else { continue 3; } break; case 'like': if (strpos($attr_value, $cond_value) !== false) { continue 2; } else { continue 3; } break; case 'nlike': if (strpos($attr_value, $cond_value) === false) { continue 2; } else { continue 3; } break; } } if (in_array($option['value_type'], array('percent', 'attribute'))) { switch ($option['value_type_attribute']) { case 'price': if (in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) { $attribute_value = $store->convertPrice($_product->getMinimalPrice(), false, false); } else { $attribute_value = $store->convertPrice($_product->getPrice(), false, false); } break; case 'store_price': $attribute_value = $store->convertPrice($_product->getFinalPrice(), false, false); break; case 'parent_url': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $attribute_value = $parent_product->getProductUrl(false); break; } $attribute_value = $_product->getProductUrl(false); break; case 'image': case 'gallery': case 'media_gallery': if (!$_product->hasData('product_base_image')) { $_prod = Mage::getModel('catalog/product')->load($_product->getId()); try { if ($image_width || $image_height) { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height); } else { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image'); } } catch (Exception $e) { $image_url = ''; } $_product->setData('product_base_image', $image_url); $attribute_value = $image_url; } else { $attribute_value = $_product->getData('product_base_image'); } break; case 'url': $attribute_value = $_product->getProductUrl(false); break; case 'qty': $attribute_value = ceil(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()); if (!$attribute_value || $attribute_value == '' || $attribute_value == null) { $attribute_value = 0; } // if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){ // // $attribute_value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty()); // // }else{ // // $attribute_value = 0; // // } break; case 'category': $attribute_value = $product->getCategory(); break; default: $attribute_value = $_product->getData($option['value_type_attribute']); } } if ($option['value_type'] == 'percent') { $value = floatval($attribute_value) / 100 * floatval($option['value']); } elseif ($option['value_type'] == 'attribute') { $value = $attribute_value; } else { $value = $option['value']; } break; } if ($value === null && $custom_attribute->getDefaultValue()) { switch ($custom_attribute->getDefaultValue()) { case 'price': if (in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) { $value = $store->convertPrice($_product->getMinimalPrice(), false, false); } else { $value = $store->convertPrice($_product->getPrice(), false, false); } break; case 'store_price': $value = $store->convertPrice($_product->getFinalPrice(), false, false); break; case 'parent_url': if (($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0) { $value = $parent_product->getProductUrl(false); break; } $value = $_product->getProductUrl(false); break; case 'image': case 'gallery': case 'media_gallery': if (!$_product->hasData('product_base_image')) { $_prod = Mage::getModel('catalog/product')->load($_product->getId()); try { if ($image_width || $image_height) { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height); } else { $image_url = (string) Mage::helper('catalog/image')->init($_prod, 'image'); } } catch (Exception $e) { $image_url = ''; } $_product->setData('product_base_image', $image_url); $value = $image_url; } else { $value = $_product->getData('product_base_image'); } break; case 'url': $value = $_product->getProductUrl(false); break; case 'qty': $value = ceil(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()); if (!$value || $value == '' || $value == null) { $value = 0; } // if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){ // // $value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty()); // // }else{ // // $value = 0; // // } break; case 'category': $value = $product->getCategory(); break; default: $value = $_product->getData($custom_attribute->getDefaultValue()); } } } } elseif ($attribute_model = $_product->getResource()->getAttribute($attribute_code)) { switch ($attribute_model->getFrontendInput()) { case 'select': case 'multiselect': $value = implode(', ', (array) $_product->getAttributeText($attribute_code)); break; default: $value = $_product->getData($attribute_code); break; } } break; } if ($value && !$product->getData($attribute_code)) { $product->setData($attribute_code, $value); } } $product->setDescription(strip_tags(preg_replace('/<br.*?>/s', "\r\n", $_product->getDescription()))); $product->setShortDescription(strip_tags(preg_replace('/<br.*?>/s', "\r\n", $_product->getShortDescription()))); $product->setQty(ceil(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty())); fwrite($fp, parent::setVars($content, $product) . "\r\n"); } fclose($fp); }
/** * Action to reconfigure wishlist item */ public function configureAction() { $id = (int) $this->getRequest()->getParam('id'); try { /* @var $item Mage_Wishlist_Model_Item */ $item = Mage::getModel('wishlist/item'); $item->loadWithOptions($id); if (!$item->getId()) { Mage::throwException($this->__('Cannot load wishlist item')); } $wishlist = $this->_getWishlist($item->getWishlistId()); if (!$wishlist) { return $this->norouteAction(); } Mage::register('wishlist_item', $item); $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $buyRequest = $item->getBuyRequest(); if (!$buyRequest->getQty() && $item->getQty()) { $buyRequest->setQty($item->getQty()); } if ($buyRequest->getQty() && !$item->getQty()) { $item->setQty($buyRequest->getQty()); Mage::helper('wishlist')->calculate(); } $params->setBuyRequest($buyRequest); Mage::helper('catalog/product_view')->prepareAndRender($item->getProductId(), $this, $params); } catch (Mage_Core_Exception $e) { Mage::getSingleton('customer/session')->addError($e->getMessage()); $this->_redirect('*'); return; } catch (Exception $e) { Mage::getSingleton('customer/session')->addError($this->__('Cannot configure product')); Mage::logException($e); $this->_redirect('*'); return; } }
/** * Action to reconfigure cart item */ public function configureAction() { // Extract item and product to configure $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; try { $cart = $this->_getCart(); $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { $this->_message($this->__('Quote item is not found.'), self::MESSAGE_STATUS_ERROR); return; } $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); $productHelper = Mage::helper('catalog/product'); $buyRequest = $params->getBuyRequest(); /** @var $product Mage_Catalog_Model_Product */ $product = $productHelper->initProduct($quoteItem->getProduct()->getId(), $this, $params); if ($buyRequest) { $productHelper->prepareProductOptions($product, $buyRequest); } if ($params->hasConfigureMode()) { $product->setConfigureMode($params->getConfigureMode()); } $this->loadLayout(false); $this->getLayout()->getBlock('xmlconnect.catalog.product')->setProduct($product); $this->renderLayout(); } catch (Exception $e) { $this->_message($this->__('Cannot configure product.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); return; } }
/** * Product view * * @return null */ public function productViewAction() { try { // Prepare data /** @var $productHelper Mage_Catalog_Helper_Product */ $productHelper = Mage::helper('catalog/product'); $productId = (int) $this->getRequest()->getParam('id'); $params = new Varien_Object(); $params->setCategoryId(false); // Standard algorithm to prepare and render product view page $product = $productHelper->initProduct($productId, $this, $params); $this->loadLayout(false); $this->getLayout()->getBlock('xmlconnect.catalog.product')->setProduct($product); $this->renderLayout(); return; } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { $this->_message($this->__('Unable to load product info.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } }
/** * 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'); } } }
/** * Configure failed item options * * @return void */ public function configureFailedAction() { $id = (int) $this->getRequest()->getParam('id'); $qty = $this->getRequest()->getParam('qty', 1); try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $buyRequest = new Varien_Object(array('product' => $id, 'qty' => $qty)); $params->setBuyRequest($buyRequest); Mage::helper('catalog/product_view')->prepareAndRender($id, $this, $params); } catch (Mage_Core_Exception $e) { $this->_getCustomerSession()->addError($e->getMessage()); $this->_redirect('*'); return; } catch (Exception $e) { $this->_getCustomerSession()->addError($this->__('Cannot configure product')); Mage::logException($e); $this->_redirect('*'); return; } }
public function checkoutCartConfigure($observer) { $action = $observer->getEvent()->getControllerAction(); if ($action->getRequest()->getParam('iswebposcart') == 'true') { $id = (int) $action->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } $result = array(); if (!$quoteItem) { $action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); return $action->getResponse()->setBody(''); } $viewHelper = Mage::helper('catalog/product_view'); $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); $productHelper = Mage::helper('catalog/product'); $productId = $quoteItem->getProduct()->getId(); try { $product = $productHelper->initProduct($productId, $action, $params); if (!$product) { $this->_getSession()->addError($viewHelper->__('Product is not loaded')); } else { if ($buyRequest = $params->getBuyRequest()) { $productHelper->prepareProductOptions($product, $buyRequest); } $product->setConfigureMode(true); Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product)); $viewHelper->initProductLayout($product, $action); $result['hasOptions'] = true; /* Daniel - doesn't allow add out of stock product to cart */ if (!$product->isAvailable()) { $result['outofstock'] = true; } /* end */ } } catch (Exception $e) { $this->_getSession()->addError(Mage::helper('checkout')->__('Cannot configure product.')); } $action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $params = $action->getRequest()->getParams(); try { 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 (isset($result['hasOptions'])) { 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'); } $productBlock->setData('submit_route_data', array('route' => 'checkout/cart/updateItemOptions', 'params' => array('id' => $id))); /* 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)); } }
public function editAction() { $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; $cart = $this->_getCart(); if ('POST' != $this->getRequest()->getMethod()) { if ($id) { $quoteItem = $cart->getQuote()->getItemById($id); } if (!$quoteItem) { $this->_getSession()->addError(Mage::helper('checkout')->__('Quote item is not found.')); $this->_goBack(); return; } try { $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); Mage::helper('icart/catalog_product_view')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params); } catch (Exception $e) { $this->_getSession()->addError(Mage::helper('checkout')->__('Cannot configure product.')); Mage::logException($e); $this->_goBack(); return; } return; } $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException(Mage::helper('checkout')->__('Quote item is not found.')); } if (isset($params['qty']) && $params['qty'] == 0) { $isRemoveItemFlag = true; $cart->removeItem($id); } else { $isRemoveItemFlag = false; $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { Mage::throwException($item); } if ($item->getHasError()) { Mage::throwException($item->getMessage()); } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { if ($isRemoveItemFlag) { $message = Mage::helper('icart')->__('%s was deleted form your shopping cart.', Mage::helper('core')->htmlEscape($quoteItem->getName())); } else { $message = Mage::helper('checkout')->__('%s was updated in your shopping cart.', Mage::helper('core')->htmlEscape($item->getProduct()->getName())); } $this->_getSession()->addSuccess($message); } //$this->_goBack(); } } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_getSession()->addNotice($e->getMessage()); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError($message); } } $this->getRequest()->setParam('error', 1); } catch (Exception $e) { $this->_getSession()->addException($e, Mage::helper('checkout')->__('Cannot update the item.')); Mage::logException($e); $this->getRequest()->setParam('error', 1); } $this->_forward('added'); }
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'); } } }