本文整理汇总了PHP中Mage_Catalog_Model_Product::getCategoryId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getCategoryId方法的具体用法?PHP Mage_Catalog_Model_Product::getCategoryId怎么用?PHP Mage_Catalog_Model_Product::getCategoryId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getCategoryId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductUrl
/**
* Get product url
*
* @param Mage_Catalog_Model_Product $product
* @param bool $useSid
* @return string
*/
public function getProductUrl($product, $useSid = true)
{
$cacheUrlKey = 'url_' . ($product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 'NONE') . '_' . intval($useSid);
$url = $product->getData($cacheUrlKey);
if (is_null($url)) {
if ($product->getStoreId()) {
$this->getUrlInstance()->setStore($product->getStoreId());
}
// auto add SID to URL
$originalSid = $this->getUrlInstance()->getUseSession();
$this->getUrlInstance()->setUseSession($useSid);
if ($product->hasData('request_path') && $product->getRequestPath() != '') {
$this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($product->getRequestPath()));
$this->getUrlInstance()->setUseSession($originalSid);
return $this->getData($cacheUrlKey);
}
if (VPROF) {
Varien_Profiler::start('REWRITE: ' . __METHOD__);
}
$rewrite = $this->getUrlRewrite();
if ($product->getStoreId()) {
$rewrite->setStoreId($product->getStoreId());
} else {
$rewrite->setStoreId(AO::app()->getStore()->getId());
}
$idPath = 'product/' . $product->getId();
if ($product->getCategoryId() && !$product->getDoNotUseCategoryId() && AO::getStoreConfig('catalog/seo/product_use_categories')) {
$idPath .= '/' . $product->getCategoryId();
}
$rewrite->loadByIdPath($idPath);
//echo $this->getUrlInstance()->getBaseUrl();
if ($rewrite->getId()) {
$this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath()));
if (VPROF) {
Varien_Profiler::stop('REWRITE: ' . __METHOD__);
}
$this->getUrlInstance()->setUseSession($originalSid);
return $this->getData($cacheUrlKey);
}
if (VPROF) {
Varien_Profiler::stop('REWRITE: ' . __METHOD__);
}
if (VPROF) {
Varien_Profiler::start('REGULAR: ' . __METHOD__);
}
$url = $this->getUrlInstance()->getUrl('catalog/product/view', array('id' => $product->getId(), 's' => $product->getUrlKey(), 'category' => $product->getCategoryId()));
$this->getUrlInstance()->setUseSession($originalSid);
if (VPROF) {
Varien_Profiler::stop('REGULAR: ' . __METHOD__);
}
}
return $url;
}
示例2: testGetCategoryId
public function testGetCategoryId()
{
$this->assertFalse($this->_model->getCategoryId());
$category = new Varien_Object(array('id' => 5));
Mage::register('current_category', $category);
try {
$this->assertEquals(5, $this->_model->getCategoryId());
Mage::unregister('current_category');
} catch (Exception $e) {
Mage::unregister('current_category');
throw $e;
}
}
示例3: getNewUrl
/**
* Retrieve url for new review creation
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getNewUrl($product)
{
$params = array('id' => $product->getId());
if ($product->getCategoryId()) {
$params['category'] = $product->getCategoryId();
}
return $this->_getUrl('review/product/list', $params);
}
示例4: getProductUrl
/**
* Get product url
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getProductUrl($product)
{
Varien_Profiler::start('REWRITE: ' . __METHOD__);
$rewrite = $this->getUrlRewrite();
if ($product->getStoreId()) {
$rewrite->setStoreId($product->getStoreId());
}
$idPath = 'product/' . $product->getId();
if ($product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
$idPath .= '/' . $product->getCategoryId();
}
$rewrite->loadByIdPath($idPath);
if ($rewrite->getId()) {
$url = $this->getUrlInstance()->getBaseUrl() . $rewrite->getRequestPath();
Varien_Profiler::stop('REWRITE: ' . __METHOD__);
return $url;
}
Varien_Profiler::stop('REWRITE: ' . __METHOD__);
Varien_Profiler::start('REGULAR: ' . __METHOD__);
$url = $this->getUrlInstance()->getUrl('catalog/product/view', array('id' => $product->getId(), 's' => $product->getUrlKey(), 'category' => $product->getCategoryId()));
Varien_Profiler::stop('REGULAR: ' . __METHOD__);
return $url;
}
示例5: _changeUrlKey
/**
* @param Mage_Catalog_Model_Product $product
* @return boolean
*/
protected function _changeUrlKey(Mage_Catalog_Model_Product &$product)
{
if ($product->getCategoryId() || !$this->_getHelper()->isUrlRewriteEnable()) {
return false;
}
//if category already exist or rewrite categories is disabled
$categoryIds = $product->getCategoryIds();
$categoryId = null;
$product->setData("request_path", null);
/** Process categories if they exists */
if (is_array($categoryIds) && count($categoryIds)) {
$categoryId = $categoryIds[count($categoryIds) - 1];
//get the last element
}
return $this->_getUrlModel()->getProductUrl($product, null, $categoryId);
}
示例6: getProductData
/**
* Create Product array from Mage_Catalog_Model_Product
*
* @param Mage_Catalog_Model_Product $product
* @return array
*/
public function getProductData(Mage_Catalog_Model_Product $product)
{
try {
$data = array('url' => $product->getProductUrl(), 'title' => htmlspecialchars($product->getName()), 'spider' => 1, 'price' => $product->getPrice(), 'description' => urlencode($product->getDescription()), 'tags' => htmlspecialchars($product->getMetaKeyword()), 'images' => array(), 'vars' => array('sku' => $product->getSku(), 'storeId' => '', 'typeId' => $product->getTypeId(), 'status' => $product->getStatus(), 'categoryId' => $product->getCategoryId(), 'categoryIds' => $product->getCategoryIds(), 'websiteIds' => $product->getWebsiteIds(), 'storeIds' => $product->getStoreIds(), 'groupPrice' => $product->getGroupPrice(), 'formatedPrice' => $product->getFormatedPrice(), 'calculatedFinalPrice' => $product->getCalculatedFinalPrice(), 'minimalPrice' => $product->getMinimalPrice(), 'specialPrice' => $product->getSpecialPrice(), 'specialFromDate' => $product->getSpecialFromDate(), 'specialToDate' => $product->getSpecialToDate(), 'relatedProductIds' => $product->getRelatedProductIds(), 'upSellProductIds' => $product->getUpSellProductIds(), 'getCrossSellProductIds' => $product->getCrossSellProductIds(), 'isSuperGroup' => $product->isSuperGroup(), 'isGrouped' => $product->isGrouped(), 'isConfigurable' => $product->isConfigurable(), 'isSuper' => $product->isSuper(), 'isSalable' => $product->isSalable(), 'isAvailable' => $product->isAvailable(), 'isVirtual' => $product->isVirtual(), 'isRecurring' => $product->isRecurring(), 'isInStock' => $product->isInStock(), 'weight' => $product->getSku()));
// Add product images
if (self::validateProductImage($product->getImage())) {
$data['images']['full'] = array("url" => $product->getImageUrl());
}
if (self::validateProductImage($product->getSmallImage())) {
$data['images']['smallImage'] = array("url" => $product->getSmallImageUrl($width = 88, $height = 77));
}
if (self::validateProductImage($product->getThumbnail())) {
$data['images']['thumb'] = array("url" => $product->getThumbnailUrl($width = 75, $height = 75));
}
return $data;
return $data;
} catch (Exception $e) {
Mage::logException($e);
}
}
示例7: getUrl
/**
* Retrieve Product URL using UrlDataObject
*
* @param Mage_Catalog_Model_Product $product
* @param array $params
* @return string
*/
public function getUrl(Mage_Catalog_Model_Product $product, $params = array())
{
$routePath = '';
$routeParams = $params;
$storeId = $product->getStoreId();
if (isset($params['_ignore_category'])) {
unset($params['_ignore_category']);
$categoryId = null;
} else {
$categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
}
if ($product->hasUrlDataObject()) {
$requestPath = $product->getUrlDataObject()->getUrlRewrite();
$routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
} else {
$requestPath = $product->getRequestPath();
if (empty($requestPath) && $requestPath !== false) {
$idPath = sprintf('product/%d', $product->getEntityId());
if ($categoryId) {
$idPath = sprintf('%s/%d', $idPath, $categoryId);
}
$rewrite = $this->getUrlRewrite();
$rewrite->setStoreId($storeId)->loadByIdPath($idPath);
if ($rewrite->getId()) {
$requestPath = $rewrite->getRequestPath();
$product->setRequestPath($requestPath);
} else {
$product->setRequestPath(false);
}
}
}
if (isset($routeParams['_store'])) {
$storeId = Mage::app()->getStore($routeParams['_store'])->getId();
}
if ($storeId != Mage::app()->getStore()->getId()) {
$routeParams['_store_to_url'] = true;
}
if (!empty($requestPath)) {
$routeParams['_direct'] = $requestPath;
} else {
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
}
// reset cached URL instance GET query params
if (!isset($routeParams['_query'])) {
$routeParams['_query'] = array();
}
return $this->getUrlInstance()->setStore($storeId)->getUrl($routePath, $routeParams);
}
示例8: _getCategoryIdForUrl
/**
* Check product category
*
* @param Mage_Catalog_Model_Product $product
* @param array $params
*
* @return int|null
*/
protected function _getCategoryIdForUrl($product, $params)
{
if (isset($params['_ignore_category'])) {
return null;
} else {
return $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
}
}