本文整理汇总了PHP中Mage_Catalog_Model_Product类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product类的具体用法?PHP Mage_Catalog_Model_Product怎么用?PHP Mage_Catalog_Model_Product使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Catalog_Model_Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initProductLayout
/**
* Initialize product view layout
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_ProductController
*/
protected function _initProductLayout($product)
{
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
$update->addHandle('PRODUCT_' . $product->getId());
if ($product->getPageLayout()) {
$this->getLayout()->helper('page/layout')->applyHandle($product->getPageLayout());
}
$this->loadLayoutUpdates();
$update->addUpdate($product->getCustomLayoutUpdate());
$this->generateLayoutXml()->generateLayoutBlocks();
if ($product->getPageLayout()) {
$this->getLayout()->helper('page/layout')->applyTemplate($product->getPageLayout());
}
$currentCategory = Mage::registry('current_category');
if ($root = $this->getLayout()->getBlock('root')) {
$root->addBodyClass('product-' . $product->getUrlKey());
if ($currentCategory instanceof Mage_Catalog_Model_Category) {
$root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey());
}
}
return $this;
}
示例2: createIndexData
public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
{
$searchEntityId = $object->getId();
$priceAttributeId = $this->getTierPriceAttribute()->getId();
if ($object->isGrouped()) {
$priceAttributeId = $this->getPriceAttribute()->getId();
$associated = $object->getTypeInstance(true)->getAssociatedProducts($object);
$searchEntityId = array();
foreach ($associated as $product) {
$searchEntityId[] = $product->getId();
}
}
if (!count($searchEntityId)) {
return false;
}
$result = array();
$data = array();
$data['store_id'] = $object->getStoreId();
$data['entity_id'] = $object->getId();
$search['store_id'] = $object->getStoreId();
$search['entity_id'] = $searchEntityId;
$search['attribute_id'] = $priceAttributeId;
foreach ($this->_customerGroups as $group) {
$search['customer_group_id'] = $group->getId();
$data['customer_group_id'] = $group->getId();
$value = $this->_getResource()->getMinimalValue($search);
if (is_null($value)) {
continue;
}
$data['value'] = $value;
$result[] = $data;
}
return $result;
}
示例3: setUp
protected function setUp()
{
$this->_product = Mage::getModel('Mage_Catalog_Model_Product');
$this->_product->load(1);
$this->_block = Mage::app()->getLayout()->createBlock('Mage_Catalog_Block_Product_View_Type_Configurable');
$this->_block->setProduct($this->_product);
}
示例4: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param Mage_Catalog_Model_Product $product
* @param Google_Service_ShoppingContent_Product $shoppingProduct
* @return Google_Service_ShoppingContent_Product
*/
public function convertAttribute($product, $shoppingProduct)
{
$availableUnits = array('mg', 'g', 'kg', 'ml', 'cl', 'l', 'cbm', 'cm', 'm', 'sqm');
$basePriceAmount = $product->getBasePriceAmount();
$basePriceUnit = strtolower($product->getBasePriceUnit());
$unitPricingMeasure = $basePriceAmount . ' ' . $basePriceUnit;
$basePriceReferenceAmount = $product->getBasePriceBaseAmount();
$basePriceReferenceUnit = strtolower($product->getBasePriceBaseUnit());
$unitPricingBaseMeasure = $basePriceReferenceAmount . ' ' . $basePriceReferenceUnit;
// skip attribute if unit not available
if (!in_array($basePriceUnit, $availableUnits) || !in_array($basePriceReferenceUnit, $availableUnits)) {
return $shoppingProduct;
}
if (!empty($basePriceAmount) && !empty($basePriceReferenceAmount)) {
$unitPricingMeasure = new Google_Service_ShoppingContent_ProductUnitPricingMeasure();
$unitPricingMeasure->setUnit($basePriceUnit);
$unitPricingMeasure->setValue($basePriceAmount);
$unitPricingBaseMeasure = new Google_Service_ShoppingContent_ProductUnitPricingBaseMeasure();
$unitPricingBaseMeasure->setUnit($basePriceReferenceUnit);
$unitPricingBaseMeasure->setValue($basePriceReferenceAmount);
$shoppingProduct->setUnitPricingMeasure($unitPricingMeasure);
$shoppingProduct->setUnitPricingBaseMeasure($unitPricingBaseMeasure);
}
return $shoppingProduct;
}
示例5: _prepareProduct
/**
* Processes the product and its options before adding it to a quote or a wishlist
*
* @param Varien_Object $buyRequest request object
* @param Mage_Catalog_Model_Product $product product ibject
* @param string $processMode process mode: strict for cart, lite for wishlist
*
* @return array|string
*/
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
{
if ($this->_isStrictProcessMode($processMode)) {
return Mage::helper('solvingmagento_affiliateproduct')->__('Affiliate product %s cannot be added to cart. ' . ' On the product detail page click the "Go to parent site" button to access the product.', $product->getName());
}
return parent::_prepareProduct($buyRequest, $product, $processMode);
}
示例6: getFinalPrice
/**
* Returns product final price depending on options chosen
*
* @param double $qty
* @param Mage_Catalog_Model_Product $product
* @return double
*/
public function getFinalPrice($qty = null, $product)
{
if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
return $product->getCalculatedFinalPrice();
}
$finalPrice = parent::getFinalPrice($qty, $product);
if ($product->hasCustomOptions()) {
/* @var $typeInstance Mage_Catalog_Model_Product_Type_Grouped */
$typeInstance = $product->getTypeInstance(true);
$associatedProducts = $typeInstance->setStoreFilter($product->getStore(), $product)->getAssociatedProducts($product);
foreach ($associatedProducts as $childProduct) {
/* @var $childProduct Mage_Catalog_Model_Product */
$option = $product->getCustomOption('associated_product_' . $childProduct->getId());
if (!$option) {
continue;
}
$childQty = $option->getValue();
if (!$childQty) {
continue;
}
$finalPrice += $childProduct->getFinalPrice($childQty) * $childQty;
}
}
$product->setFinalPrice($finalPrice);
Mage::dispatchEvent('catalog_product_type_grouped_price', array('product' => $product));
return max(0, $product->getData('final_price'));
}
示例7: _getProductHelper
/**
* Returns helper for product type
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Helper_Product_Configuration_Interface
*/
protected function _getProductHelper($product)
{
// Retrieve whole array of renderers
$productHelpers = $this->getProductHelpers();
if (!is_array($productHelpers)) {
$column = $this->getColumn();
if ($column) {
$grid = $column->getGrid();
if ($grid) {
$productHelpers = $grid->getProductConfigurationHelpers();
$this->setProductHelpers($productHelpers ? $productHelpers : array());
}
}
}
// Check whether we have helper for our product
$productType = $product->getTypeId();
if (isset($productHelpers[$productType])) {
$helperName = $productHelpers[$productType];
} else {
if (isset($productHelpers['default'])) {
$helperName = $productHelpers['default'];
} else {
$helperName = 'catalog/product_configuration';
}
}
$helper = Mage::helper($helperName);
if (!$helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface) {
Mage::throwException($this->__("Helper for options rendering doesn't implement required interface."));
}
return $helper;
}
示例8: getProductUrl
/**
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getProductUrl($product)
{
if ($product->getVisibleInSiteVisibilities()) {
return $product->getUrlModel()->getUrl($product);
}
return '#';
}
示例9: saveGallery
/**
* Put the gallery value into the document collection
*
* @param Mage_Catalog_Model_Product $product The product we want to save the gallery for
* @param string $attributeCode The attribute code of the saved gallery
* @param array $savedGallery The content of the gallery to be saved
*
* @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media Self reference
*/
public function saveGallery($product, $attributeCode, $savedGallery)
{
$updateFilter = array('_id' => new MongoInt32($product->getId()));
$updateValue = array('galleries.' . $attributeCode => array_values($savedGallery));
$this->_getDocumentCollection()->update($updateFilter, array('$set' => $updateValue));
return $this;
}
示例10: redirectToProductPage
/**
* Redirect to product page
*
* @param \Mage_Catalog_Model_Product $product
*/
public function redirectToProductPage(Mage_Catalog_Model_Product $product)
{
$response = Mage::app()->getResponse();
$response->setRedirect($product->getProductUrl());
$response->sendResponse();
exit;
}
示例11: inRestrictProducts
public static function inRestrictProducts(Mage_Catalog_Model_Product $oProduct)
{
$product_disabled = false;
$restrict_groups = Mage::getStoreConfig('zeo_actions_setting/product_price/customer_groups');
$restrict_groups = trim($restrict_groups);
$restrict_groups = trim($restrict_groups, ",");
if ($restrict_groups != "") {
$restrict_groups_array = explode(",", $restrict_groups);
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if (in_array($groupId, $restrict_groups_array)) {
return true;
}
}
$restrict_categories = Mage::getStoreConfig('zeo_actions_setting/product_price/catalog_categories');
$restrict_categories = trim($restrict_categories);
$restrict_categories = trim($restrict_categories, ",");
if ($restrict_categories != "") {
$restrict_categories_array = explode(",", $restrict_categories);
$product_categpries = $oProduct->getCategoryIds();
$final_cats = array_intersect($restrict_categories_array, $product_categpries);
if (count($final_cats) > 0) {
return true;
}
}
return $product_disabled;
}
示例12: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param Mage_Catalog_Model_Product $product
* @param Google_Service_ShoppingContent_Product $shoppingProduct
* @return Google_Service_ShoppingContent_Product
*/
public function convertAttribute($product, $shoppingProduct)
{
$config = Mage::getSingleton('googleshoppingapi/config');
$targetCountry = $config->getTargetCountry($product->getStoreId());
$value = $config->getCountryInfo($targetCountry, 'language', $product->getStoreId());
$shoppingProduct->setContentLanguage($value);
}
示例13: _getProductPrice
/**
* Get unit/final price for a product model.
*
* @param Mage_Catalog_Model_Product $product the product model.
* @param bool $finalPrice if final price.
* @param bool $inclTax if tax is to be included.
*
* @return float
*/
protected function _getProductPrice($product, $finalPrice = false, $inclTax = true)
{
$price = 0;
switch ($product->getTypeId()) {
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
// Get the bundle product "from" price.
$price = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax);
break;
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
// Get the grouped product "starting at" price.
/** @var $tmpProduct Mage_Catalog_Model_Product */
$tmpProduct = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addAttributeToFilter('entity_id', $product->getId())->setPage(1, 1)->addMinimalPrice()->addTaxPercents()->load()->getFirstItem();
if ($tmpProduct) {
$price = $tmpProduct->getMinimalPrice();
if ($inclTax) {
$price = Mage::helper('tax')->getPrice($tmpProduct, $price, true);
}
}
break;
default:
$price = $finalPrice ? $product->getFinalPrice() : $product->getPrice();
if ($inclTax) {
$price = Mage::helper('tax')->getPrice($product, $price, true);
}
break;
}
return $price;
}
示例14: getAddUrl
/**
* Retrieve url for add product to cart
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getAddUrl($product, $additional = array())
{
/**
* Identify continue shopping url
*/
if ($currentProduct = Mage::registry('current_product')) {
/**
* go to product view page
*/
$continueShoppingUrl = $currentProduct->getProductUrl();
} elseif ($currentCategory = Mage::registry('current_category')) {
/**
* go to category view page
*/
$continueShoppingUrl = $currentCategory->getCategoryUrl();
} else {
$continueShoppingUrl = $this->_getUrl('*/*/*', array('_current' => true));
}
$params = array(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode($continueShoppingUrl), 'product' => $product->getId());
if ($this->_getRequest()->getModuleName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') {
$params['in_cart'] = 1;
}
if (count($additional)) {
$params = array_merge($params, $additional);
}
return $this->_getUrl('checkout/cart/add', $params);
}
示例15: setProduct
public function setProduct(Mage_Catalog_Model_Product $product)
{
$store = Mage::app()->getStore($product->getStoreId());
$product->setStore($store);
$this->_product = $product;
return $this;
}