function getFormatedPrice() { if ($this->currentlySelectedFit() && ($customPrice = $this->customPrice($this->currentlySelectedFit()))) { return $customPrice; } return parent::getPrice(); }
public function isPriceSpecial(Mage_Catalog_Model_Product $product) { /* * Check if sale price is activated and if so if sale price is LESS than normal price * I.E., customer might be a Member, so the member price might be less than sale price */ $originalPrice = $product->getPrice(); $finalPrice = $product->getFinalPrice(); if ($finalPrice < $originalPrice) { return self::SPECIAL_PRICE; } /* * check if product is new */ $current_date = time(); // compare date $from_date = $product->getData('news_from_date'); // begin date $to_date = $product->getData('news_to_date'); // end date if ($this->isDateBetween($current_date, $from_date, $to_date)) { return self::NEW_PRODUCT; } return false; }
/** * Apply gift card amount to price * * @param Mage_Catalog_Model_Product $product * @param int $qty * @param double $finalPrice * @return double */ protected function _applyOptionsPrice($product, $qty, $finalPrice) { if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) { $amount = $product->getCustomOption('card_amount')->getValue(); $finalPrice += $amount; } return $finalPrice; }
/** * Apply gift card amount to price * * @param Mage_Catalog_Model_Product $product * @param int $qty * @param double $finalPrice * @return double */ protected function _applyOptionsPrice($product, $qty, $finalPrice) { if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) { $amount = Mage::helper('directory')->currencyConvert($product->getCustomOption('card_amount')->getValue(), Mage::app()->getStore()->getCurrentCurrencyCode(), Mage::app()->getStore()->getBaseCurrency()); //$amount = $product->getCustomOption('card_amount')->getValue(); $finalPrice += $amount; } return $finalPrice; }
/** * Get product regular price for rendering on frontend * * @param Mage_Catalog_Model_Product $product * @return int */ public function getRegularPrice($product) { $price = $product->getPrice(); if ($msrp = $product->getSimpleMsrp()) { if ($msrp > $price) { $price = $msrp; } } return $price; }
/** * Tries calculate price without discount; if can't returns null * @param $product * @param $store */ public function getCatalogRegularPrice(Mage_Catalog_Model_Product $product, $store = null) { switch ($product->getTypeId()) { case Mage_Catalog_Model_Product_Type::TYPE_GROUPED: case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE: case 'giftcard': return null; default: return $product->getPrice(); } }
/** * If tier price exist, return it, instead of base price. * * @param Mage_Catalog_Model_Product $product * @param float|null $qty * * @return float */ public function getBasePrice($product, $qty = null) { $price = (double) $product->getPrice(); $tierPrice = $this->_applyTierPrice($product, $qty, $price); if ($product->getSpecialPrice() && $product->getSpecialPrice() < $price && $qty == 1) { return $product->getSpecialPrice(); } else { if ($tierPrice) { return $tierPrice; } } return min($this->_applyGroupPrice($product, $price), $this->_applyTierPrice($product, $qty, $price), $this->_applySpecialPrice($product, $price)); }
/** * @param Mage_Catalog_Model_Product $child * @return $this * @throws InvalidArgumentException */ public function setPriceFromChild(Mage_Catalog_Model_Product $child) { if ($child === null) { throw new InvalidArgumentException("Product passed is a non-object"); } $price = $child->getPrice(); $specialPrice = $child->getSpecialPrice(); $specialFrom = $child->getSpecialFromDate(); $specialTo = $child->getSpecialToDate(); $this->setPrice($price, $specialPrice, $specialFrom, $specialTo); $this->_priceChild = $child; return $this; }
/** * Retrieve product final price * * @param integer $qty * @param Mage_Catalog_Model_Product $product * @return float */ public function getFinalPrice($qty = null, $product) { $finalPrice = $product->getPrice(); if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('giftcard_amount'); if ($customOption) { $finalPrice += $customOption->getValue(); } } $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice); $product->setData('final_price', $finalPrice); return max(0, $product->getData('final_price')); }
/** * 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 = $product->getPrice(); $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice); $finalPrice = $this->_applySpecialPrice($product, $finalPrice); $product->setFinalPrice($finalPrice); AO::dispatchEvent('catalog_product_get_final_price', array('product' => $product)); $finalPrice = $product->getData('final_price'); $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice); return max(0, $finalPrice); }
/** * 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); } }
/** * Add special fields to product get response * * @param Mage_Catalog_Model_Product $product */ protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product) { /** @var $productHelper Mage_Catalog_Helper_Product */ $productHelper = Mage::helper('catalog/product'); $productData = $product->getData(); $product->setWebsiteId($this->_getStore()->getWebsiteId()); // customer group is required in product for correct prices calculation $product->setCustomerGroupId($this->_getCustomerGroupId()); // calculate prices $finalPrice = $product->getFinalPrice(); $productData['regular_price_with_tax'] = $this->_applyTaxToPrice($product->getPrice(), true); $productData['regular_price_without_tax'] = $this->_applyTaxToPrice($product->getPrice(), false); $productData['final_price_with_tax'] = $this->_applyTaxToPrice($finalPrice, true); $productData['final_price_without_tax'] = $this->_applyTaxToPrice($finalPrice, false); $productData['is_saleable'] = $product->getIsSalable(); $productData['image_url'] = (string) Mage::helper('catalog/image')->init($product, 'image'); if ($this->getActionType() == self::ACTION_TYPE_ENTITY) { // define URLs $productData['url'] = $productHelper->getProductUrl($product->getId()); /** @var $cartHelper Mage_Checkout_Helper_Cart */ $cartHelper = Mage::helper('checkout/cart'); $productData['buy_now_url'] = $cartHelper->getAddUrl($product); /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */ $stockItem = $product->getStockItem(); if (!$stockItem) { $stockItem = Mage::getModel('cataloginventory/stock_item'); $stockItem->loadByProduct($product); } $productData['is_in_stock'] = $stockItem->getIsInStock(); /** @var $reviewModel Mage_Review_Model_Review */ $reviewModel = Mage::getModel('review/review'); $productData['total_reviews_count'] = $reviewModel->getTotalReviews($product->getId(), true, $this->_getStore()->getId()); $productData['tier_price'] = $this->_getTierPrices(); $productData['has_custom_options'] = count($product->getOptions()) > 0; } else { // remove tier price from response $product->unsetData('tier_price'); unset($productData['tier_price']); } $product->addData($productData); }
public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true) { $result = array(); $result['entity_id'] = $product->getEntityId(); $result['sku'] = $product->getSku(); $result['name'] = $product->getName(); $result['price'] = $product->getPrice(); $result['special_price'] = $product->getSpecialPrice(); $result['special_from_date'] = $product->getSpecialFromDate(); $result['special_to_date'] = $product->getSpecialToDate(); $result['cost'] = $product->getCost(); $result['description'] = $product->getDescription(); $result['short_description'] = $product->getShortDescription(); $result['weight'] = $product->getWeight(); if ($product->isVisibleInSiteVisibility()) { $result['url_path'] = $this->_getProductUrlWithCache($product); } $parentProduct = $this->_getParentProduct($product); if ($parentProduct != null) { $result['parent_id'] = $parentProduct->getEntityId(); $result['parent_sku'] = $parentProduct->getSku(); if (!$product->isVisibleInSiteVisibility()) { $result['name'] = $parentProduct->getName(); if ($parentProduct->isVisibleInSiteVisibility()) { $result['url_path'] = $this->_getProductUrlWithCache($parentProduct); } } if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) { $result['purchasable'] = $this->_isPurchasable($product, $parentProduct); $attributes = $parentProduct->getTypeInstance(true)->getUsedProductAttributes($parentProduct); $freshProduct = null; foreach ($attributes as $attribute) { if (!array_key_exists('configurable_attributes', $result)) { $result['configurable_attributes'] = array(); } $attr = array(); $attr['attribute_name'] = $attribute->getFrontend()->getLabel(); $attr['value'] = $product->getAttributeText($attribute->getAttributeCode()); if (empty($attr['value'])) { // use the EAV tables only if the flat table doesn't work if ($freshProduct == null) { $freshProduct = Mage::getModel('catalog/product')->load($product->getEntityId()); } $attr['value'] = $attribute->getFrontend()->getValue($freshProduct); } $result['configurable_attributes'][] = $attr; } } } if (!isset($result['purchasable'])) { $result['purchasable'] = $this->_isPurchasable($product); } $images = $this->_getProductImages($product); if (isset($images['image'])) { $result['image'] = $images['image']; } if (isset($images['small_image'])) { $result['small_image'] = $images['small_image']; } if (isset($images['thumbnail'])) { $result['thumbnail'] = $images['thumbnail']; } if ($includeExtras) { // Metas $metas = $this->_getMetas($storeId, $product, $parentProduct); if ($metas != null) { //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1']; //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2']; //if(isset($metas['meta3'])) $result['meta3'] = $metas['meta3']; //if(isset($metas['meta4'])) $result['meta4'] = $metas['meta4']; if (isset($metas['meta5'])) { $result['meta5'] = $metas['meta5']; } } //Custom For ST Bernard Sports // Set IsNew Flag if product is less then 45 days old. $result['meta4'] = strtotime($product->getCreatedAt()) + 45 * 24 * 60 * 60 < time() ? "False" : "True"; // Brand and Category $brandAndCategoryProduct = !$parentProduct || $product->isVisibleInSiteVisibility() ? $product : $parentProduct; $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct); if ($setSettings['brandAttribute'] != null) { $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']); } if ($setSettings['catFromMagento']) { $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct); if (isset($cats['category'])) { $result['category'] = $cats['category']; } if (isset($cats['sub_category'])) { $result['sub_category'] = $cats['sub_category']; } //Custom For ST Bernard Sports if (isset($cats['third_category'])) { $result['meta3'] = $cats['third_category']; } } else { if ($setSettings['catFromAttributes']) { if ($setSettings['categoryAttribute'] != null) { $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']); } if ($setSettings['subcategoryAttribute'] != null) { $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']); } } } // Inventory $result['in_stock'] = $product->isAvailable() ? "true" : "false"; $stockItem = $product->getStockItem(); if ($stockItem) { $result['qty_on_hand'] = $stockItem->getStockQty(); } // Related Products $result['links'] = $this->_getProductLinks($product); } $result['type'] = $product->getTypeId(); return $result; }
/** * Calculate price of selection * * @param Mage_Catalog_Model_Product $bundleProduct * @param Mage_Catalog_Model_Product $selectionProduct * @param decimal $selectionQty * @return decimal */ public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty = null, $multiplyQty = true) { if (is_null($selectionQty)) { $selectionQty = $selectionProduct->getSelectionQty(); } if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) { if ($multiplyQty) { return $selectionProduct->getFinalPrice($selectionQty) * $selectionQty; } else { return $selectionProduct->getFinalPrice($selectionQty); } } else { if ($selectionProduct->getSelectionPriceType()) { // percent return $bundleProduct->getPrice() * ($selectionProduct->getSelectionPriceValue() / 100) * $selectionQty; } else { // fixed return $selectionProduct->getSelectionPriceValue() * $selectionQty; } } }
/** * Retrieve product price * * @param Mage_Catalog_Model_Product $product * @return float */ public function getPrice($product) { return $product->getPrice(); }
/** * Return the "normal price" of the product, if it has a special price and this special price is active * * @param Mage_Catalog_Model_Product $product * @return mixed */ public function getOldPrice(Mage_Catalog_Model_Product $product) { $normalPrice = $product->getPrice(); $currentPrice = $product->getFinalPrice(); if ($normalPrice != $currentPrice) { return Mage::helper('tax')->getPrice($product, $normalPrice); } else { return false; } }
/** * Get tier prices (formatted) * * @param Mage_Catalog_Model_Product $product * @return array */ protected function _getTierPrices(Mage_Catalog_Model_Product $product) { if (null === $product) { return array(); } $prices = $product->getFormatedTierPrice(); $res = array(); if (is_array($prices)) { foreach ($prices as $price) { $price['price_qty'] = $price['price_qty'] * 1; if ($product->getPrice() != $product->getFinalPrice()) { if ($price['price'] < $product->getFinalPrice()) { $price['savePercent'] = ceil(100 - 100 / $product->getFinalPrice() * $price['price']); $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])), false); $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)), false); $res[] = $price; } } else { if ($price['price'] < $product->getPrice()) { $price['savePercent'] = ceil(100 - 100 / $product->getPrice() * $price['price']); $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])), false); $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)), false); $res[] = $price; } } } } return $res; }
/** * Calculate price of selection * * @param Mage_Catalog_Model_Product $bundleProduct * @param Mage_Catalog_Model_Product $selectionProduct * @param decimal $selectionQty * @return decimal */ public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty = null, $multiplyQty = true) { if (is_null($selectionQty)) { $selectionQty = $selectionProduct->getSelectionQty(); } if ($bundleProduct->getPriceType() == Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes_Extend::DYNAMIC) { if ($multiplyQty) { return $selectionProduct->getFinalPrice($selectionQty) * $selectionQty; } else { return $selectionProduct->getFinalPrice($selectionQty); } } else { if ($selectionProduct->getSelectionPriceType()) { return $bundleProduct->getPrice() * $selectionProduct->getSelectionPriceValue() / 100 * $selectionQty; } else { return $selectionProduct->getSelectionPriceValue() * $selectionQty; } } }
public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true) { $result = array(); $result['entity_id'] = $product->getEntityId(); $result['sku'] = $product->getSku(); $result['name'] = $product->getName(); $result['price'] = $product->getPrice(); $result['special_price'] = $product->getSpecialPrice(); $result['special_from_date'] = $product->getSpecialFromDate(); $result['special_to_date'] = $product->getSpecialToDate(); $result['cost'] = $product->getCost(); $result['description'] = $product->getDescription(); $result['short_description'] = $product->getShortDescription(); $result['weight'] = $product->getWeight(); if ($product->isVisibleInSiteVisibility()) { $prodUrlStr = $product->getProductUrl(); $prodUrl = Mage::getSingleton('core/url')->parseUrl($prodUrlStr); $result['url_path'] = substr($prodUrl->getPath(), 1); } $parentProduct = $this->_getParentProduct($product); if ($parentProduct != null) { $result['parent_id'] = $parentProduct->getEntityId(); $result['parent_sku'] = $parentProduct->getSku(); if (!$product->isVisibleInSiteVisibility()) { $result['name'] = $parentProduct->getName(); if ($parentProduct->isVisibleInSiteVisibility()) { $prodUrlStr = $parentProduct->getProductUrl(); $prodUrl = Mage::getSingleton('core/url')->parseUrl($prodUrlStr); $result['url_path'] = substr($prodUrl->getPath(), 1); } } if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) { $result['purchasable'] = $this->_isPurchasable($product, $parentProduct); $attributes = $parentProduct->getTypeInstance(true)->getUsedProductAttributes($parentProduct); foreach ($attributes as $attribute) { if (!array_key_exists('configurable_attributes', $result)) { $result['configurable_attributes'] = array(); } $attr = array(); $attr['attribute_name'] = $attribute->getFrontend()->getLabel(); $attr['value'] = $product->getAttributeText($attribute->getAttributeCode()); $result['configurable_attributes'][] = $attr; } } } if (!isset($result['purchasable'])) { $result['purchasable'] = $this->_isPurchasable($product); } $images = $this->_getProductImages($product); if (isset($images['image'])) { $result['image'] = $images['image']; } if (isset($images['small_image'])) { $result['small_image'] = $images['small_image']; } if (isset($images['thumbnail'])) { $result['thumbnail'] = $images['thumbnail']; } if ($includeExtras) { // Metas $metas = $this->_getMetas($storeId, $product, $parentProduct); if ($metas != null) { //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1']; //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2']; if (isset($metas['meta3'])) { $result['meta3'] = $metas['meta3']; } if (isset($metas['meta4'])) { $result['meta4'] = $metas['meta4']; } if (isset($metas['meta5'])) { $result['meta5'] = $metas['meta5']; } } // Brand and Category $brandAndCategoryProduct = !$parentProduct || $product->isVisibleInSiteVisibility() ? $product : $parentProduct; $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct); if ($setSettings['brandAttribute'] != null) { $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']); } if ($setSettings['catFromMagento']) { $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct); if (isset($cats['category'])) { $result['category'] = $cats['category']; } if (isset($cats['sub_category'])) { $result['sub_category'] = $cats['sub_category']; } } else { if ($setSettings['catFromAttributes']) { if ($setSettings['categoryAttribute'] != null) { $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']); } if ($setSettings['subcategoryAttribute'] != null) { $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']); } } } // Inventory $result['in_stock'] = $product->isAvailable() ? "true" : "false"; $stockItem = $product->getStockItem(); if ($stockItem) { $result['qty_on_hand'] = $stockItem->getStockQty(); } // Related Products $result['links'] = $this->_getProductLinks($product); } $result['type'] = $product->getTypeId(); return $result; }
public function __construct(Mage_Catalog_Model_Product $product) { $this->id = $product->getId(); $this->sku = $product->getSku(); $this->name = $product->getName(); $statuses = Mage::getModel('catalog/product_status')->getOptionArray(); $this->status = $statuses[$product->getStatus()]; $options = Mage::getModel('catalog/product_visibility')->getOptionArray(); $this->visibility = $options[$product->getVisibility()]; $this->price = (double) number_format($product->getPrice(), 2, '.', ''); $this->specialPrice = (double) number_format($product->getSpecialPrice(), 2, '.', ''); $this->url = $product->getProductUrl(); $this->imagePath = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getSmallImage()); $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product); $this->stock = (double) number_format($stock->getQty(), 2, '.', ''); $short_description = $product->getShortDescription(); //limit short description if (strlen($short_description) > 250) { $short_description = substr($short_description, 0, 250); } $this->short_description = $short_description; //category data $count = 0; $categoryCollection = $product->getCategoryCollection()->addNameToResult(); foreach ($categoryCollection as $cat) { $this->categories[$count]['Id'] = $cat->getId(); $this->categories[$count]['Name'] = $cat->getName(); $count++; } //website data $count = 0; $websiteIds = $product->getWebsiteIds(); foreach ($websiteIds as $websiteId) { $website = Mage::app()->getWebsite($websiteId); $this->websites[$count]['Id'] = $website->getId(); $this->websites[$count]['Name'] = $website->getName(); $count++; } //bundle product options if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { $optionCollection = $product->getTypeInstance()->getOptionsCollection(); $selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds()); $options = $optionCollection->appendSelections($selectionCollection); foreach ($options as $option) { $count = 0; $title = str_replace(' ', '', $option->getDefaultTitle()); $selections = $option->getSelections(); $sOptions = array(); foreach ($selections as $selection) { $sOptions[$count]['name'] = $selection->getName(); $sOptions[$count]['sku'] = $selection->getSku(); $sOptions[$count]['id'] = $selection->getProductId(); $sOptions[$count]['price'] = (double) number_format($selection->getPrice(), 2, '.', ''); $count++; } $this->{$title} = $sOptions; } } //configurable product options if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); foreach ($productAttributeOptions as $productAttribute) { $count = 0; $label = strtolower(str_replace(' ', '', $productAttribute['label'])); $options = array(); foreach ($productAttribute['values'] as $attribute) { $options[$count]['option'] = $attribute['default_label']; $options[$count]['price'] = (double) number_format($attribute['pricing_value'], 2, '.', ''); $count++; } $this->{$label} = $options; } } }
protected function _getDeliveryCost(Mage_Catalog_Model_Product $product) { $cost = 0; if ($this->_deliveryDefaultValue) { $cost = $this->_deliveryDefaultValue; } if ($this->_deliveryFreeFromPrice && $product->getPrice() > $this->_deliveryFreeFromPrice) { $cost = 0; } return $cost; }
/** * Inflate an API object from a product object * * @param Mage_Catalog_Model_Product $product Product * @param int $storeId Magento store ID * @param bool $includeExtras Retrieve all information * * @return array */ public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true) { $result = array(); $result['entity_id'] = $product->getEntityId(); $result['sku'] = $product->getSku(); $result['name'] = $product->getName(); $result['price'] = $product->getPrice(); $result['special_price'] = $product->getSpecialPrice(); $result['special_from_date'] = $product->getSpecialFromDate(); $result['special_to_date'] = $product->getSpecialToDate(); $result['cost'] = $product->getCost(); $result['description'] = $product->getDescription(); $result['short_description'] = $product->getShortDescription(); $result['weight'] = $product->getWeight(); if ($product->isVisibleInSiteVisibility()) { $result['url_path'] = $this->_getProductUrlWithCache($product); } $parentProduct = $this->_getParentProduct($product); if ($parentProduct != null) { $result['parent_id'] = $parentProduct->getEntityId(); $result['parent_sku'] = $parentProduct->getSku(); if (!$product->isVisibleInSiteVisibility()) { $result['name'] = $parentProduct->getName(); if ($parentProduct->isVisibleInSiteVisibility()) { $result['url_path'] = $this->_getProductUrlWithCache($parentProduct); } } if ($includeExtras && $this->_isConfigurableProduct($parentProduct)) { $result['purchasable'] = $this->_isPurchasable($product, $parentProduct); /* @var Mage_Catalog_Model_Product_Type_Configurable $typeInst */ $typeInst = $parentProduct->getTypeInstance(true); $attributes = $typeInst->getUsedProductAttributes($parentProduct); /* @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute */ foreach ($attributes as $attribute) { if (!array_key_exists('configurable_attributes', $result)) { $result['configurable_attributes'] = array(); } $result['configurable_attributes'][] = array('attribute_name' => $attribute->getAttributeCode()); } } } if (!isset($result['purchasable'])) { $result['purchasable'] = $this->_isPurchasable($product); } $images = $this->_getProductImages($product); if (isset($images['image'])) { $result['image'] = $images['image']; } if (isset($images['small_image'])) { $result['small_image'] = $images['small_image']; } if (isset($images['thumbnail'])) { $result['thumbnail'] = $images['thumbnail']; } if ($includeExtras) { $metas = $this->_getMetas($storeId, $product, $parentProduct); if ($metas != null) { /*if (isset($metas['meta3'])) { $result['meta3'] = $metas['meta3']; }*/ if (isset($metas['meta4'])) { $result['meta4'] = $metas['meta4']; } if (isset($metas['meta5'])) { $result['meta5'] = $metas['meta5']; } } //Custom for Sportys $stores = array(); foreach ($product->getStoreIds() as $storeID) { $store = Mage::getModel('core/store')->load($storeID); $stores[] = $store->getCode(); } $result["meta3"] = implode(',', $stores); // Brand and Category $brandCatProduct = $product; if ($parentProduct && !$product->isVisibleInSiteVisibility()) { $brandCatProduct = $parentProduct; } $setSettings = $this->_getProductAttributeSetSettings($brandCatProduct); if ($setSettings['brandAttribute'] != null) { $result['brand'] = $this->_getProductAttribute($brandCatProduct, $setSettings['brandAttribute']); } if ($setSettings['catFromMagento']) { $cats = $this->_getCategoryInformation($storeId, $brandCatProduct); if (isset($cats['category'])) { $result['category'] = $cats['category']; } if (isset($cats['sub_category'])) { $result['sub_category'] = $cats['sub_category']; } } else { if ($setSettings['catFromAttributes']) { if ($setSettings['categoryAttribute'] != null) { $result['category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['categoryAttribute']); } if ($setSettings['subcategoryAttribute'] != null) { $result['sub_category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['subcategoryAttribute']); } } } $result['attributes'] = $this->_getProductAttributes($product); // Inventory $result['in_stock'] = $product->isAvailable() ? "true" : "false"; /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */ $stockItem = $product->getStockItem(); if ($stockItem) { $result['qty_on_hand'] = $stockItem->getStockQty(); } // Related Products $result['links'] = $this->_getProductLinks($product); } $result['type'] = $product->getTypeId(); return $result; }
/** * Get product price including store conversion rate * * @param Mage_Catalog_Model_Product $product * @param null|string $format * @return float|string */ public function getProductPrice($product, $format = null) { try { $value = $product->getPrice(); $value = $this->_app->getStore()->convertPrice($value, $format); } catch (Exception $e) { $value = $e->getMessage(); } return $value; }
public function getObject(Mage_Catalog_Model_Product $product, $group_id = null) { $defaultData = array(); $transport = new Varien_Object($defaultData); Mage::dispatchEvent('algolia_product_index_before', array('product' => $product, 'custom_data' => $transport)); $defaultData = $transport->getData(); $defaultData = is_array($defaultData) ? $defaultData : explode("|", $defaultData); $customData = array('objectID' => $product->getId(), 'name' => $product->getName(), 'price' => $product->getPrice(), 'price_with_tax' => Mage::helper('tax')->getPrice($product, $product->getPrice(), true, null, null, null, null, false), 'url' => $product->getProductUrl(), 'description' => $product->getDescription()); $special_price = $product->getFinalPrice(); /** * Handle group price */ if ($group_id !== null) { $discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(Mage::app()->getLocale()->storeTimeStamp($product->getStoreId()), Mage::app()->getStore($product->getStoreId())->getWebsiteId(), $group_id, $product->getId()); if ($discounted_price !== false) { $special_price = $discounted_price; } } if ($special_price != $customData['price']) { $customData['special_price_from_date'] = strtotime($product->getSpecialFromDate()); $customData['special_price_to_date'] = strtotime($product->getSpecialToDate()); $customData['special_price'] = $special_price; $customData['special_price_with_tax'] = Mage::helper('tax')->getPrice($product, $special_price, true, null, null, null, null, false); $customData['special_price_formated'] = Mage::helper('core')->formatPrice($customData['special_price'], false); $customData['special_price_with_tax_formated'] = Mage::helper('core')->formatPrice($customData['special_price_with_tax'], false); } $customData['price_formated'] = Mage::helper('core')->formatPrice($customData['price'], false); $customData['price_with_tax_formated'] = Mage::helper('core')->formatPrice($customData['price_with_tax'], false); $categories = array(); $categories_with_path = array(); foreach ($this->getProductActiveCategories($product, $product->getStoreId()) as $categoryId) { $category = Mage::getModel('catalog/category')->load($categoryId); $categoryName = $category->getName(); if ($categoryName) { $categories[] = $categoryName; } $category->getUrlInstance()->setStore($product->getStoreId()); $path = array(); foreach ($category->getPathIds() as $treeCategoryId) { $name = $this->getCategoryName($treeCategoryId, $product->getStoreId()); if ($name) { $path[] = $name; } } $categories_with_path[] = $path; } foreach ($categories_with_path as $result) { for ($i = count($result) - 1; $i > 0; $i--) { $categories_with_path[] = array_slice($result, 0, $i); } } $categories_with_path = array_intersect_key($categories_with_path, array_unique(array_map('serialize', $categories_with_path))); $categories_hierarchical = array(); $level_name = 'level'; foreach ($categories_with_path as $category) { for ($i = 0; $i < count($category); $i++) { if (isset($categories_hierarchical[$level_name . $i]) === false) { $categories_hierarchical[$level_name . $i] = array(); } $categories_hierarchical[$level_name . $i][] = implode(' /// ', array_slice($category, 0, $i + 1)); } } foreach ($categories_hierarchical as &$level) { $level = array_unique($level); } foreach ($categories_with_path as &$category) { $category = implode(' /// ', $category); } $customData['categories'] = $categories_hierarchical; //array_values($categories_with_path); $customData['categories_without_path'] = $categories; if (false === isset($defaultData['thumbnail_url'])) { try { $customData['thumbnail_url'] = $product->getThumbnailUrl(); $customData['thumbnail_url'] = str_replace(array('https://', 'http://'), '//', $customData['thumbnail_url']); } catch (\Exception $e) { } } if (false === isset($defaultData['image_url'])) { try { $customData['image_url'] = $product->getImageUrl(); $customData['image_url'] = str_replace(array('https://', 'http://'), '//', $customData['image_url']); } catch (\Exception $e) { } } $additionalAttributes = $this->config->getProductAdditionalAttributes($product->getStoreId()); $sub_products = null; if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped') { if ($product->getTypeId() == 'grouped') { $sub_products = $product->getTypeInstance(true)->getAssociatedProducts($product); } if ($product->getTypeId() == 'configurable') { $sub_products = $product->getTypeInstance(true)->getUsedProducts(null, $product); } $min = PHP_INT_MAX; $max = 0; $min_with_tax = PHP_INT_MAX; $max_with_tax = 0; foreach ($sub_products as $sub_product) { $sub_product = Mage::getModel('catalog/product')->load($sub_product->getId()); $price = $sub_product->getPrice(); $price_with_tax = Mage::helper('tax')->getPrice($sub_product, $price, true, null, null, null, null, false); $min = min($min, $price); $max = max($max, $price); $min_with_tax = min($min_with_tax, $price_with_tax); $max_with_tax = max($max_with_tax, $price_with_tax); } $customData['min_formated'] = Mage::helper('core')->formatPrice($min, false); $customData['max_formated'] = Mage::helper('core')->formatPrice($max, false); $customData['min_with_tax_formated'] = Mage::helper('core')->formatPrice($min_with_tax, false); $customData['max_with_tax_formated'] = Mage::helper('core')->formatPrice($max_with_tax, false); } if (false === isset($defaultData['in_stock'])) { $stockItem = $product->getStockItem(); $customData['in_stock'] = (int) $stockItem->getIsInStock(); } // skip default calculation if we have provided these attributes via the observer in $defaultData if (false === isset($defaultData['ordered_qty']) && false === isset($defaultData['stock_qty'])) { $ordered_qty = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->addAttributeToFilter('sku', $product->getSku())->setOrder('ordered_qty', 'desc')->getFirstItem()->ordered_qty; $customData['ordered_qty'] = (int) $ordered_qty; $customData['stock_qty'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped') { $ordered_qty = 0; $stock_qty = 0; foreach ($sub_products as $sub_product) { $stock_qty += (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($sub_product)->getQty(); $ordered_qty += (int) $this->getReportForProduct($sub_product)->ordered_qty; } $customData['ordered_qty'] = $ordered_qty; $customData['stock_qty'] = $stock_qty; } if ($this->isAttributeEnabled($additionalAttributes, 'ordered_qty') == false) { unset($customData['ordered_qty']); } if ($this->isAttributeEnabled($additionalAttributes, 'stock_qty') == false) { unset($customData['stock_qty']); } } if ($this->isAttributeEnabled($additionalAttributes, 'rating_summary')) { $summaryData = Mage::getModel('review/review_summary')->setStoreId($product->getStoreId())->load($product->getId()); if ($summaryData['rating_summary']) { $customData['rating_summary'] = $summaryData['rating_summary']; } } foreach ($additionalAttributes as $attribute) { if (isset($customData[$attribute['attribute']])) { continue; } $value = $product->getData($attribute['attribute']); $attribute_ressource = $product->getResource()->getAttribute($attribute['attribute']); if ($attribute_ressource) { $attribute_ressource = $attribute_ressource->setStoreId($product->getStoreId()); if ($value === null) { /** Get values as array in children */ if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped') { $values = array(); foreach ($sub_products as $sub_product) { $sub_product = Mage::getModel('catalog/product')->load($sub_product->getId()); $value = $sub_product->getData($attribute['attribute']); if ($value) { $value_text = $sub_product->getAttributeText($attribute['attribute']); if ($value_text) { $values[] = $value_text; } else { $values[] = $attribute_ressource->getFrontend()->getValue($sub_product); } } } if (count($values) > 0) { $customData[$attribute['attribute']] = $values; } } } else { $value_text = $product->getAttributeText($attribute['attribute']); if ($value_text) { $value = $value_text; } else { $attribute_ressource = $attribute_ressource->setStoreId($product->getStoreId()); $value = $attribute_ressource->getFrontend()->getValue($product); } if ($value) { $customData[$attribute['attribute']] = $value; } } } } $customData = array_merge($customData, $defaultData); $customData['type_id'] = $product->getTypeId(); $this->castProductObject($customData); return $customData; }
function getFormatedPrice() { if ($this->vf_product->hasFitmentBeenSelected() && ($customPrice = $this->customPrice($this->vf_product->getFirstCurrentlySelectedFitment()))) { return $customPrice; } return parent::getPrice(); }
/** * Get calculated product price * * @param array $options * @param Mage_Catalog_Model_Product $product * @return double */ public function getCalculatedPrice(array $options, $product) { $price = $product->getPrice(); foreach ($product->getSuperAttributes() as $attribute) { if (isset($options[$attribute['attribute_id']])) { if ($value = $this->getValueByIndex($attribute['values'], $options[$attribute['attribute_id']])) { if ($value['pricing_value'] != 0) { $price += $product->getPricingValue($value); } } } } return $price; }
/** * @param Mage_Catalog_Model_Product $product * @return array */ public function getProductData(Mage_Catalog_Model_Product $product) { $id = $product->getId(); if (!$this->helper()->shouldUseRealProductId()) { $id = $product->getSku() ? $product->getSku() : md5($id); } $data = array('id' => $id, 'url' => $product->getProductUrl(), 'name' => $product->getName(), 'unit_price' => (double) $product->getPrice(), 'unit_sale_price' => (double) $product->getFinalPrice(), 'currency' => $this->_getCurrency(), 'description' => strip_tags($product->getShortDescription()), 'sku_code' => $product->getSku()); if ($this->helper()->shouldShowProductStockInfo()) { $data['stock'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); } $catIndex = $catNames = array(); $limit = 2; $k = 0; foreach ($product->getCategoryIds() as $catId) { if (++$k > $limit) { break; } if (!isset($catIndex[$catId])) { $catIndex[$catId] = Mage::getModel('catalog/category')->load($catId); } $catNames[] = $catIndex[$catId]->getName(); } if (isset($catNames[0])) { $data['category'] = $catNames[0]; } if (isset($catNames[1])) { $data['subcategory'] = $catNames[1]; } return $data; }
protected function _createPrice() { //TODO: use getFinalPrice() once we support start and end time return array('amount' => $this->_product->getPrice(), 'code' => Mage::app()->getStore($this->_storeId)->getBaseCurrencyCode()); }
/** * Get base price with apply Group, Tier, Special prises * * @param Mage_Catalog_Model_Product $product * @param float|null $qty * * @return float */ public function getBasePrice($product, $qty = null) { $price = (double) $product->getPrice(); return min($this->_applyGroupPrice($product, $price), $this->_applyTierPrice($product, $qty, $price), $this->_applySpecialPrice($product, $price)); }
public function testGetPrice() { $this->assertEmpty($this->_model->getPrice()); $this->_model->setPrice(10.0); $this->assertEquals(10.0, $this->_model->getPrice()); }