本文整理汇总了PHP中Varien_Object::setCategoryId方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Object::setCategoryId方法的具体用法?PHP Varien_Object::setCategoryId怎么用?PHP Varien_Object::setCategoryId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Object
的用法示例。
在下文中一共展示了Varien_Object::setCategoryId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configureAction
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;
}
}
示例2: optionsAction
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');
}
}
}
示例3: previewAction
/**
* 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');
}
}
}
示例4: configureAction
/**
* 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;
}
}
示例5: indexAction
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;
}
}
示例6: _initProduct
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);
}
示例7: _initProduct
/**
* 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);
}
示例8: imagesAction
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();
}
示例9: viewAction
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');
}
}
}
示例10: configureAction
/**
* 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;
}
}
示例11: writeTempFile
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');
//.........这里部分代码省略.........
示例12: configureAction
/**
* 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;
}
}
示例13: configureAction
/**
* 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;
}
}
示例14: productViewAction
/**
* 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);
}
}
示例15: viewAction
/**
* 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);
}
}