本文整理汇总了PHP中Mage_Catalog_Model_Product::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getResource方法的具体用法?PHP Mage_Catalog_Model_Product::getResource怎么用?PHP Mage_Catalog_Model_Product::getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getAttributeValue
private function _getAttributeValue(Mage_Catalog_Model_Product $product, $attributeCode)
{
$attribute = $product->getResource()->getAttribute($attributeCode);
if ($attribute) {
return $attribute->getFrontend()->getValue($product);
}
}
示例2: 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)
{
// get category from product attribute
Mage::log(__LINE__ . $product->getResource()->getAttribute('google_shopping_category'));
$value = $product->getResource()->getAttribute('google_shopping_category')->getFrontend()->getValue($product);
$value = preg_replace('/\\d+ /', '', $value);
$shoppingProduct->setGoogleProductCategory($value);
return $shoppingProduct;
}
示例3: getTierPrice
/**
* Get product tier price by qty
*
* @param double $qty
* @param Mage_Catalog_Model_Product $product
* @return double
*/
public function getTierPrice($qty = null, $product)
{
$allGroups = Mage_Customer_Model_Group::CUST_GROUP_ALL;
#$defaultGroup = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID);
$prices = $product->getData('tier_price');
/**
* Load tier price
*/
if (is_null($prices)) {
if ($attribute = $product->getResource()->getAttribute('tier_price')) {
$attribute->getBackend()->afterLoad($product);
$prices = $product->getData('tier_price');
}
}
if (is_null($prices) || !is_array($prices)) {
if (!is_null($qty)) {
return $product->getPrice();
}
return array(array('price' => $product->getPrice(), 'price_qty' => 1, 'cust_group' => $allGroups));
}
$custGroup = $this->_getCustomerGroupId($product);
if ($qty) {
// starting with quantity 1 and original price
$prevQty = 1;
$prevPrice = $product->getPrice();
$prevGroup = $allGroups;
foreach ($prices as $price) {
if ($price['cust_group'] != $custGroup && $price['cust_group'] != $allGroups) {
// tier not for current customer group nor is for all groups
continue;
}
if ($qty < $price['price_qty']) {
// tier is higher than product qty
continue;
}
if ($price['price_qty'] < $prevQty) {
// higher tier qty already found
continue;
}
if ($price['price_qty'] == $prevQty && $prevGroup != $allGroups && $price['cust_group'] == $allGroups) {
// found tier qty is same as current tier qty but current tier group is ALL_GROUPS
continue;
}
$prevPrice = $price['price'];
$prevQty = $price['price_qty'];
$prevGroup = $price['cust_group'];
}
return $prevPrice;
} else {
foreach ($prices as $i => $price) {
if ($price['cust_group'] != $custGroup && $price['cust_group'] != $allGroups) {
unset($prices[$i]);
}
}
}
return $prices ? $prices : array();
}
示例4: _validateUrlKey
/**
* Check unique url_key value in catalog_product_entity_url_key table.
*
* @param Mage_Catalog_Model_Product $object
* @return Mage_Catalog_Model_Product_Attribute_Backend_Urlkey
* @throws Mage_Core_Exception
*/
protected function _validateUrlKey($object)
{
$connection = $object->getResource()->getReadConnection();
$select = $connection->select()->from($this->getAttribute()->getBackendTable(), array('count' => new Zend_Db_Expr('COUNT(\'value_id\')')))->where($connection->quoteInto('entity_id <> ?', $object->getId()))->where($connection->quoteInto('value = ?', $object->getUrlKey()));
$result = $connection->fetchOne($select);
if ((int) $result) {
throw new Mage_Core_Exception(Mage::helper('catalog')->__("Product with the '%s' url_key attribute already exists.", $object->getUrlKey()));
}
return $this;
}
示例5: getAmounts
/**
* Load and set gift card amounts into product object
*
* @param Mage_Catalog_Model_Product $product
*/
public function getAmounts($product)
{
$allGroups = Mage_Customer_Model_Group::CUST_GROUP_ALL;
$prices = $product->getData('giftcard_amounts');
if (is_null($prices)) {
if ($attribute = $product->getResource()->getAttribute('giftcard_amounts')) {
$attribute->getBackend()->afterLoad($product);
$prices = $product->getData('giftcard_amounts');
}
}
return $prices ? $prices : array();
}
示例6: getProduct
/**
* Get custom configurable product
*
* @return Mage_Catalog_Model_Product
*/
public function getProduct()
{
if (!$this->_product) {
$this->_product = Mage::getModel('catalog/product')->setStoreId($this->getStoreId());
$id = $this->_product->getResource()->getIdBySku($this->_sku);
$this->_product->load($id);
if (!$this->_product->getId()) {
Mage::log('CustomConfigurable configurable product could not be loaded', null, 'aydus_customconfigurable.log');
}
}
return $this->_product;
}
示例7: _encodeProduct
/**
* Encodes a single Magento Product.
*
* @param Mage_Catalog_Model_Product $product
*
* @return RTDProduct
*/
protected function _encodeProduct(Mage_Catalog_Model_Product $product)
{
$encodedProduct = new RTDProduct();
$customMapping = Mage::getConfig()->getNode('rtd_mappings/product/export');
$attributeTypes = array('multiselect', 'dropdown');
foreach ($customMapping->asArray() as $magentoKey => $rtdKey) {
try {
$attribute = $product->getResource()->getAttribute($magentoKey);
if ($attribute != false && in_array($attribute->getFrontendInput(), $attributeTypes)) {
$encodedProduct->setParam($rtdKey, $product->getAttributeText($magentoKey));
} else {
$encodedProduct->setParam($rtdKey, $product->{'get' . $magentoKey}());
}
} catch (Exception $ex) {
Mage::log($ex->getMessage(), null, 'realtimedespatch.log');
}
}
if (Mage::getStoreConfigFlag('sixbysix_realtimedespatch/product_export/image_export')) {
$this->_swapPlaceholderWithParentImage($product, $encodedProduct);
}
return $encodedProduct;
}
示例8: setAttributes
/**
* @param Mage_Catalog_Model_Product $parent
*/
public function setAttributes($parent)
{
$result = array();
if ($this->getIsChild() && $parent->isConfigurable()) {
/** @var Mage_Catalog_Model_Product_Type_Configurable $productTypeInstance */
$productTypeInstance = $parent->getTypeInstance(true);
$allowAttributes = $productTypeInstance->getConfigurableAttributes($parent);
foreach ($allowAttributes as $attribute) {
/** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
$itemAttribute = new Shopgate_Model_Catalog_Attribute();
$attribute = $attribute->getProductAttribute();
if ($attribute == null) {
continue;
}
$itemAttribute->setGroupUid($attribute->getAttributeId());
$attrValue = $this->item->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend();
$itemAttribute->setLabel($attrValue->getValue($this->item));
$result[] = $itemAttribute;
}
}
parent::setAttributes($result);
}
示例9: getAttributesPerProduct
/**
* getAttributesPerProduct
*
* @param Mage_Catalog_Model_Product $product
* @return array
*/
public function getAttributesPerProduct($product)
{
$attributeCodes = Mage::helper('merchandiser')->getAttributeCodes();
$currency = $this->getCurrency();
if (is_null($attributeCodes)) {
return array();
}
$attributes = array();
foreach ($attributeCodes as $attributeCode) {
if (strcmp($attributeCode, '') == 0) {
continue;
}
$eavAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', $attributeCode);
if ($eavAttribute->getId() == null) {
continue;
}
$resource = $product->getResource()->getAttribute($attributeCode);
$label = $resource->getFrontendLabel();
$value = $resource->getFrontend()->getValue($product);
if ($value) {
if ($eavAttribute->getFrontendInput() == 'price') {
$value = $currency->formatPrecision($value, 2);
}
$attributes[] = array('label' => $label, 'value' => $value);
}
}
return $attributes;
}
示例10: _getGiftWrappingLabel
/**
* get gift wrapping label
*
* @param Mage_Catalog_Model_Product $product
*
* @return null|string
*/
protected function _getGiftWrappingLabel(Mage_Catalog_Model_Product $product)
{
// set this label only once
if (null === $this->_giftWrappingLabel) {
$this->_giftWrappingLabel = $this->_getHelper()->__('Gift Wrapping');
if (empty($this->_giftWrappingLabel)) {
$this->_giftWrappingLabel = $product->getResource()->getAttribute('gift_wrapping_available')->getStoreLabel();
}
}
return $this->_giftWrappingLabel;
}
示例11: _getRefValueByProductAndNumber
/**
* Get proper ref value for given product
*
* @param Mage_Catalog_Model_Product $product
* @param int $refNumber
* @param int $storeId
* @return null|string
*/
protected function _getRefValueByProductAndNumber($product, $refNumber, $storeId)
{
$value = null;
$helperMethod = 'getRef' . $refNumber . 'AttributeCode';
$refCode = Mage::helper('avatax')->{$helperMethod}($storeId);
if ($refCode && $product->getResource()->getAttribute($refCode)) {
try {
$value = (string) $product->getResource()->getAttribute($refCode)->getFrontend()->getValue($product);
} catch (Exception $e) {
Mage::logException($e);
}
}
return $value;
}
示例12: _loadAttributeOnProduct
/**
* Load a single attribute value onto a product.
*
* This method is not nice. I only keep it because if it reduces
* the number of support requests, when people specify attributes
* in the template string but don't have them loaded on product
* collections.
*
* @param Mage_Catalog_Model_Product $product
* @param string $attributeCode
* @return $this
*/
protected function _loadAttributeOnProduct(Mage_Catalog_Model_Product $product, $attributeCode)
{
$value = $product->getResource()->getAttributeRawValue($product->getId(), $attributeCode, Mage::app()->getStore()->getId());
$product->setData($attributeCode, $value);
return $this;
}
示例13: _removeNotApplicableAttributes
/**
* Remove don't applicable attributes data
*
* @param Mage_Catalog_Model_Product $product
*/
protected function _removeNotApplicableAttributes($product)
{
$eavConfig = Mage::getSingleton('Mage_Eav_Model_Config');
$entityType = $product->getResource()->getEntityType();
foreach ($eavConfig->getEntityAttributeCodes($entityType, $product) as $attributeCode) {
$attribute = $eavConfig->getAttribute($entityType, $attributeCode);
$applyTo = $attribute->getApplyTo();
if (is_array($applyTo) && count($applyTo) > 0 && !in_array($product->getTypeId(), $applyTo)) {
$product->unsetData($attribute->getAttributeCode());
}
}
}
示例14: _getProductAttributeValue
/**
* Get product attribute value
*
* @param Mage_Catalog_Model_Product $product
* @param string $code
* @return string
*/
protected function _getProductAttributeValue($product, $code)
{
$value = '';
if ($code && $product->getResource()->getAttribute($code)) {
try {
$value = (string) $product->getResource()->getAttribute($code)->getFrontend()->getValue($product);
} catch (Exception $e) {
Mage::logException($e);
}
}
return $value;
}
示例15: getProductData
/**
* @param Mage_Catalog_Model_Product $product
* @param array $additionalAttributes
* @return array
*/
public function getProductData(Mage_Catalog_Model_Product $product, $additionalAttributes = array())
{
$product_data = array();
$attributes = array_merge((array) $this->config->attributes, $additionalAttributes);
// store
$store = Mage::getModel('core/store')->load($product->getStoreId());
foreach ($attributes as $attribute) {
if ($attribute->type == 'constant') {
$value = $attribute->value;
} elseif ($attribute->type == 'product_attribute') {
// if this is a normal product attribute, retrieve it's frontend
// representation, or the default value if it doesn't have a value
// for this attribute
if ($product->getData($attribute->magento) === null) {
if (isset($attribute->default)) {
$value = $attribute->default;
} else {
$value = '';
}
} else {
/** @var $attributeObj Mage_Catalog_Model_Resource_Eav_Attribute */
$attributeObj = $product->getResource()->getAttribute($attribute->magento);
$value = $attributeObj->getFrontend()->getValue($product);
// The output helper performs this check as well, but we don't want to unnecessarily send off
// every single attribute to this helper if we can avoid it.
if ($attributeObj->getIsWysiwygEnabled()) {
$value = $this->catalogOutputHelper->productAttribute($product, $value, $attribute->magento);
}
}
} elseif ($attribute->type == 'stock_attribute') {
$value = $product->getStockItem()->getData($attribute->magento);
if ($value === null) {
if (isset($attribute->default)) {
$value = $attribute->default;
} else {
$value = '';
}
}
} elseif ($attribute->type == 'computed') {
// if this is a computed attribute, handle it depending on its code
switch ($attribute->magento) {
case 'final_price':
$price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);
$value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
$value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
break;
case 'special_price':
$price = Mage::helper('tax')->getPrice($product, $product->getSpecialPrice(), true);
$value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
$value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
break;
case 'price':
$price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);
$value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
$value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
break;
case 'product_link':
$value = $this->getCleanProductUrl($product);
break;
case 'image_url':
$value = (string) Mage::helper('catalog/image')->init($product, 'image');
break;
case 'instock_y_n':
$value = $product->isSaleable() ? "Y" : "N";
// myshopping
break;
case 'availability_yes_no':
$value = $product->isSaleable() ? "yes" : "no";
break;
case 'availability_google':
$value = $product->isSaleable() ? 'in stock' : 'out of stock';
break;
case 'currency':
$value = Mage::getStoreConfig('mehulchaudhari_feedsgenerator/' . $this->config->config_path . '/currency');
break;
case 'google_taxonomy':
if (!isset($attribute->exclude_cats)) {
$attribute->exclude_cats = array();
}
$categoryIds = $this->getCategoryPathIds($product, $attribute->exclude_cats);
if (count($categoryIds) > 0) {
$categoryId = $categoryIds[count($categoryIds) - 1];
$category = Mage::getModel('catalog/category')->load($categoryId);
$value = $category->getResource()->getAttribute('google_product_category')->getFrontend()->getValue($category);
} else {
$value = '';
}
break;
case 'category_path':
case 'category_last':
if (!isset($attribute->exclude_cats)) {
$attribute->exclude_cats = array();
}
$value = $this->getCategoryPath($product, $attribute->exclude_cats);
if ($attribute->magento == 'category_last') {
//.........这里部分代码省略.........