/** * 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; }
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; }
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); }
/** * 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; }
/** * 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); }
/** * 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')); }
/** * 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; }
/** * @param Mage_Catalog_Model_Product $product * @return string */ public function getProductUrl($product) { if ($product->getVisibleInSiteVisibilities()) { return $product->getUrlModel()->getUrl($product); } return '#'; }
/** * 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; }
/** * 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; }
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; }
/** * 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); }
/** * 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; }
/** * 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); }
public function setProduct(Mage_Catalog_Model_Product $product) { $store = Mage::app()->getStore($product->getStoreId()); $product->setStore($store); $this->_product = $product; return $this; }
/** * Returns the formatted string for the quantity chosen for the given selection * * @param Mage_Catalog_Model_Product $_selection * @param bool $includeContainer * @return string */ public function getSelectionQtyTitlePrice(Mage_Catalog_Model_Product $_selection, $includeContainer = true) { if ($this->isGuestView()) { return $_selection->getSelectionQty() * 1 . ' x ' . $this->escapeHtml($_selection->getName()); } return parent::getSelectionQtyTitlePrice($_selection, $includeContainer); }
public function getUrl(Mage_Catalog_Model_Product $product, $params = array()) { if (Mage::getVersion() >= 1.8) { $product->setData('url', ''); } return parent::getUrl($product, $params); }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $entry->cleanTaxes(); if (Mage::helper('tax')->getConfig()->priceIncludesTax()) { return $entry; } $calc = Mage::helper('tax')->getCalculator(); $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId()); $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId()); $targetCountry = Mage::getSingleton('googleshopping/config')->getTargetCountry($product->getStoreId()); $ratesTotal = 0; foreach ($rates as $rate) { if ($targetCountry == $rate['country']) { $regions = $this->_parseRegions($rate['state'], $rate['postcode']); $ratesTotal += count($regions); if ($ratesTotal > self::RATES_MAX) { Mage::throwException(Mage::helper('googleshopping')->__("Google shopping only supports %d tax rates per product", self::RATES_MAX)); } foreach ($regions as $region) { $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region)); } } } return $entry; }
/** * Retrieve url for add product to cart * * @param Mage_Catalog_Model_Product $product * @return string */ public function getAddUrl($product, $additional = array()) { $continueUrl = Mage::helper('core')->urlEncode($this->getCurrentUrl()); $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED; $routeParams = array( $urlParamName => $continueUrl, 'product' => $product->getEntityId() ); if (!empty($additional)) { $routeParams = array_merge($routeParams, $additional); } if ($product->hasUrlDataObject()) { $routeParams['_store'] = $product->getUrlDataObject()->getStoreId(); $routeParams['_store_to_url'] = true; } if ($this->_getRequest()->getRouteName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') { $routeParams['in_cart'] = 1; } return $this->_getUrl('checkout/cart/add', $routeParams); }
/** * Save Product Links process * * @param Mage_Catalog_Model_Product $product * @param array $data * @param int $typeId * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link */ public function saveProductLinks($product, $data, $typeId) { if (!is_array($data)) { $data = array(); } $attributes = $this->getAttributesByType($typeId); $deleteCondition = $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()) . $this->_getWriteAdapter()->quoteInto(' AND link_type_id=?', $typeId); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $linkedProductId => $linkInfo) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('product_id' => $product->getId(), 'linked_product_id' => $linkedProductId, 'link_type_id' => $typeId)); $linkId = $this->_getWriteAdapter()->lastInsertId(); foreach ($attributes as $attributeInfo) { $attributeTable = $this->getAttributeTypeTable($attributeInfo['type']); if ($attributeTable && isset($linkInfo[$attributeInfo['code']])) { $this->_getWriteAdapter()->insert($attributeTable, array('product_link_attribute_id' => $attributeInfo['id'], 'link_id' => $linkId, 'value' => $linkInfo[$attributeInfo['code']])); } } } /** * Grouped product relations should be added to relation table */ if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) { } return $this; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $config = Mage::getSingleton('Mage_GoogleShopping_Model_Config'); $targetCountry = $config->getTargetCountry($product->getStoreId()); $value = $config->getCountryInfo($targetCountry, 'language', $product->getStoreId()); return $this->_setAttribute($entry, 'content_language', self::ATTRIBUTE_TYPE_TEXT, $value); }
/** * Get product final price via configurable product's tier pricing structure. * Uses qty of parent item to determine price. * * @param Mage_Catalog_Model_Product $product * * @return float */ private function _calcConfigProductTierPricing($product) { $tierPrice = PHP_INT_MAX; if ($items = $this->_getAllVisibleItems()) { // map mapping the IDs of the parent products with the quantities of the corresponding simple products $idQuantities = array(); // go through all products in the quote foreach ($items as $item) { /** @var Mage_Sales_Model_Quote_Item $item */ if ($item->getParentItem()) { continue; } // this is the product ID of the parent! $id = $item->getProductId(); // map the parent ID with the quantity of the simple product $idQuantities[$id][] = $item->getQty(); } // compute the total quantity of items of the configurable product if (array_key_exists($product->getId(), $idQuantities)) { $totalQty = array_sum($idQuantities[$product->getId()]); $tierPrice = $product->getPriceModel()->getBasePrice($product, $totalQty); } } return $tierPrice; }
/** * Get product final price * * @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); $product->getTypeInstance(true)->setStoreFilter($product->getStore(), $product); $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product); $selectedAttributes = array(); if ($product->getCustomOption('attributes')) { $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue()); } $basePrice = $finalPrice; foreach ($attributes as $attribute) { $attributeId = $attribute->getProductAttribute()->getId(); $value = $this->_getValueByIndex($attribute->getPrices() ? $attribute->getPrices() : array(), isset($selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] : null); if ($value) { if ($value['pricing_value'] != 0) { $finalPrice += $this->_calcSelectionPrice($value, $basePrice); } } } $product->setFinalPrice($finalPrice); return max(0, $product->getData('final_price')); }
/** * @param Mage_Catalog_Model_Product $product * @return boolean */ public function productHasOptions(Mage_Catalog_Model_Product $product) { if (count($product->getOptions()) > 0) { return true; } return false; }
/** * Recursively apply custom design settings to product if it's container * category custom_use_for_products option is setted to 1. * If not or product shows not in category - applyes product's internal settings * * @deprecated after 1.4.2.0-beta1, functionality moved to Mage_Catalog_Model_Design * @param Mage_Catalog_Model_Category|Mage_Catalog_Model_Product $object * @param Mage_Core_Model_Layout_Update $update */ protected function _applyCustomDesignSettings($object, $update) { if ($object instanceof Mage_Catalog_Model_Category) { // lookup the proper category recursively if ($object->getCustomUseParentSettings()) { $parentCategory = $object->getParentCategory(); if ($parentCategory && $parentCategory->getId() && $parentCategory->getLevel() > 1) { $this->_applyCustomDesignSettings($parentCategory, $update); } return; } // don't apply to the product if (!$object->getCustomApplyToProducts()) { return; } } if ($this->_designProductSettingsApplied) { return; } $date = $object->getCustomDesignDate(); if (array_key_exists('from', $date) && array_key_exists('to', $date) && Mage::app()->getLocale()->isStoreDateInInterval(null, $date['from'], $date['to'])) { if ($object->getPageLayout()) { $this->_designProductSettingsApplied['layout'] = $object->getPageLayout(); } $this->_designProductSettingsApplied['update'] = $object->getCustomLayoutUpdate(); } }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $url = $product->getProductUrl(false); if ($url) { if (!Mage::getStoreConfigFlag('web/url/use_store')) { $urlInfo = parse_url($url); $store = $product->getStore()->getCode(); if (isset($urlInfo['query']) && $urlInfo['query'] != '') { $url .= '&___store=' . $store; } else { $url .= '?___store=' . $store; } } $links = $entry->getLink(); if (!is_array($links)) { $links = array(); } $link = $entry->getService()->newLink(); $link->setHref($url); $link->setRel('alternate'); $link->setType('text/html'); if ($product->getName()) { $link->setTitle($product->getName()); } $links[0] = $link; $entry->setLink($links); } return $entry; }
public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null) { $data = array(); $data['store_id'] = $attribute->getStoreId(); $data['entity_id'] = $object->getId(); $data['attribute_id'] = $attribute->getId(); $result = array(); $values = $object->getData($attribute->getAttributeCode()); if (!is_array($values)) { return $result; } foreach ($values as $row) { if (isset($row['delete']) && $row['delete']) { continue; } $data['qty'] = $row['price_qty']; $data['value'] = $row['price']; if ($row['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) { foreach ($this->_customerGroups as $group) { $data['customer_group_id'] = $group->getId(); $result[] = $data; } } else { $data['customer_group_id'] = $row['cust_group']; $result[] = $data; } } return $result; }
/** * Prepare tier prices for save * * @param Mage_Catalog_Model_Product $product * @param array $tierPrices * @return array */ public function prepareTierPrices($product, $tierPrices = null) { if (!is_array($tierPrices)) { return null; } $updateValue = array(); foreach ($tierPrices as $tierPrice) { if (!is_object($tierPrice) || !isset($tierPrice->qty) || !isset($tierPrice->price)) { $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices')); } if (!isset($tierPrice->website) || $tierPrice->website == 'all') { $tierPrice->website = 0; } else { try { $tierPrice->website = Mage::app()->getWebsite($tierPrice->website)->getId(); } catch (Mage_Core_Exception $e) { $tierPrice->website = 0; } } if (intval($tierPrice->website) > 0 && !in_array($tierPrice->website, $product->getWebsiteIds())) { $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid tier prices. The product is not associated to the requested website.')); } if (!isset($tierPrice->customer_group_id)) { $tierPrice->customer_group_id = 'all'; } if ($tierPrice->customer_group_id == 'all') { $tierPrice->customer_group_id = Mage_Customer_Model_Group::CUST_GROUP_ALL; } $updateValue[] = array('website_id' => $tierPrice->website, 'cust_group' => $tierPrice->customer_group_id, 'price_qty' => $tierPrice->qty, 'price' => $tierPrice->price); } return $updateValue; }
/** * After Save Attribute manipulation * * @param Mage_Catalog_Model_Product $object * @return Mage_Catalog_Model_Product_Attribute_Backend_Price */ public function afterSave($object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); /** * Orig value is only for existing objects */ $oridData = $object->getOrigData(); $origValueExist = $oridData && array_key_exists($this->getAttribute()->getAttributeCode(), $oridData); if ($object->getStoreId() != 0 || !$value || $origValueExist) { return $this; } if ($this->getAttribute()->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE) { $baseCurrency = Mage::app()->getBaseCurrencyCode(); $storeIds = $object->getStoreIds(); if (is_array($storeIds)) { foreach ($storeIds as $storeId) { $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); if ($storeCurrency == $baseCurrency) { continue; } $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); if (!$rate) { $rate = 1; } $newValue = $value * $rate; $object->addAttributeUpdate($this->getAttribute()->getAttributeCode(), $newValue, $storeId); } } } return $this; }
/** * 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) { $url = $product->getProductUrl(false); if ($url) { $config = Mage::getSingleton('googleshoppingapi/config'); if (!Mage::getStoreConfigFlag('web/url/use_store') && $config->getAddStoreCodeToUrl()) { Mage::log($config->getAddStoreCodeToUrl() ? "true" : "false"); $urlInfo = parse_url($url); $store = $product->getStore()->getCode(); if (isset($urlInfo['query']) && $urlInfo['query'] != '') { $url .= '&___store=' . $store; } else { $url .= '?___store=' . $store; } } if ($config->getAddUtmSrcGshopping($product->getStoreId())) { $url .= '&utm_source=GoogleShopping'; } if ($customUrlParameters = $config->getCustomUrlParameters($product->getStoreId())) { $url .= $customUrlParameters; } $shoppingProduct->setLink($url); } return $shoppingProduct; }