function getFinalPrice($qty = null) { if ($this->currentlySelectedFit() && ($customPrice = $this->customPrice($this->currentlySelectedFit()))) { return $customPrice; } return parent::getFinalPrice(); }
/** * set category path */ public function setCategoryPaths() { $result = array(); if ($this->_getExportHelper()->isProductVisibleInCategories($this->item)) { $itemsOrderOption = Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_ITEM_SORT); $linkedCategories = Mage::getResourceSingleton('shopgate/product')->getCategoryIdsAndPosition($this->item); foreach ($linkedCategories as $link) { $categoryItemObject = new Shopgate_Model_Catalog_CategoryPath(); $categoryItemObject->setUid($link['category_id']); switch ($itemsOrderOption) { case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_LAST_UPDATED: $sortIndex = Mage::getModel('core/date')->timestamp(strtotime($this->item->getUpdatedAt())); $categoryItemObject->setSortOrder($sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_NEWEST: $sortIndex = Mage::getModel('core/date')->timestamp(strtotime($this->item->getCreatedAt())); $categoryItemObject->setSortOrder(Shopgate_Framework_Model_Export_Product_Csv::MAX_TIMESTAMP - $sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_PRICE_DESC: $sortIndex = round($this->item->getFinalPrice() * 100, 0); $categoryItemObject->setSortOrder($sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_POSITION: $categoryItemObject->setSortOrder($link['max_position'] - $link['position']); break; default: $categoryItemObject->setSortOrder($link['position']); } $result[$link['category_id']] = $categoryItemObject; } } parent::setCategoryPaths($result); }
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; }
public function handleAddResponse(Mage_Catalog_Model_Product $product, Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Response_Http $response) { $output = array('product_id' => $product->getId(), 'product_price' => $product->getFinalPrice(), 'product_image' => (string) Mage::helper('catalog/image')->init($product, 'image')->resize(150, 150), 'product_qty' => 1, 'quote_total' => $this->_getQuote()->getSubtotal(), 'quote_qty' => $this->_getQuote()->getItemsQty(), 'success' => true); $transport = new Varien_Object($output); $this->_retrieveHtmlResponse($transport); Mage::dispatchEvent('swiftotter_addtocart_success_output', array('transport' => $transport)); $this->_send($response, $transport->getData(), 200); }
public function getFinalPrice($qty = null) { if (Mage::getSingleton('customer/session')->isLoggedIn()) { $helper = Mage::helper('ism_newstore_members'); $price = Mage::getModel('catalog/product')->load($this->getId())->_getData('ism_newstoremembers_price'); $customerId = Mage::getSingleton('customer/session')->getId(); if ($price !== null && $helper->isMemberValid($customerId) && $helper->isMemberAddress($customerId)) { return $price; } } return parent::getFinalPrice($qty); }
function getFinalPrice($qty = null) { if (!$this->currentlySelectedFit()) { return parent::getFinalPrice($qty); } $vehicle = $this->vf_product->getFirstCurrentlySelectedFitment(); if (!$vehicle) { return parent::getFinalPrice($qty); } $customPrice = $this->customPrice($vehicle); if ($customPrice) { return $customPrice; } return parent::getFinalPrice($qty); }
function getFinalPrice($qty = null) { if (!$this->currentlySelectedFit()) { return parent::getFinalPrice($qty); } $selection = $this->currentlySelectedFit(); $vehicle = $selection->getFirstVehicle(); if (!$vehicle) { return parent::getFinalPrice($qty); } $customPrice = $this->customPrice($vehicle); if ($customPrice) { return $customPrice; } return parent::getFinalPrice($qty); }
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(); $data['value'] = $object->getData($attribute->getAttributeCode()); if ($attribute->getAttributeCode() == 'price') { $result = array(); foreach ($this->_customerGroups as $group) { $object->setCustomerGroupId($group->getId()); $finalPrice = $object->getFinalPrice(); $row = $data; $row['customer_group_id'] = $group->getId(); $row['value'] = $finalPrice; $result[] = $row; } return $result; } return $data; }
/** * Retrieve product final price * * @param Mage_Catalog_Model_Product $product * @return float */ public function getFinalPrice($product) { return $product->getFinalPrice(); }
/** * Prepare price accordingly to percentage and store rates and round its * * @param Mage_Catalog_Model_Product $product * @param float|int|string $price * @param bool $isPercent * @return float */ protected function _preparePrice($product, $price, $isPercent = false) { if ($isPercent && !empty($price)) { $price = $product->getFinalPrice() * $price / 100; } $price = Mage::app()->getStore()->convertPrice($price); $price = Mage::app()->getStore()->roundPrice($price); return $price; }
/** * 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; } } }
/** * 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; } } }
/** * @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 _shouldExport(Mage_Catalog_Model_Product $product) { if ($this->_filterPrice && $product->getFinalPrice() < $this->_filterPrice) { return false; } if ($this->_isComplexProduct($product)) { return true; } if (!$this->_filterStock && !$product->getStockItem()->getIsInStock()) { return false; } if (!$this->_filterStock && $this->_filterStockFrom && $this->_stock[$product->getId()] < $this->_filterStockFrom) { return false; } return true; }
/** * add product in order * * @access protected * @param $product, $qty, $price * @return order object * */ function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1, $price) { if ($price) { $finalPrice = $price; } else { $finalPrice = $product->getFinalPrice(); } $rowTotal = $finalPrice * $qty; $options = $product->getCustomOptions(); $optionsByCode = array(); foreach ($options as $option) { $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())->setProduct($option->getProduct()); $optionsByCode[$quoteOption->getCode()] = $quoteOption; } $product->setCustomOptions($optionsByCode); // DECREMENTE O STOCK $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId()); if ($stockItem->getManageStock()) { $stockItem->setData('qty', $stockItem->getQty() - $product['qty']); } $stockItem->save(); $options = $product->getTypeInstance(true)->getOrderOptions($product); $orderItem = Mage::getModel('sales/order_item')->setStoreId($this->_storeId)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($product->getId())->setProductType($product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['rqty'])->setQtyOrdered($product['qty'])->setName($product->getName())->setSku($product->getSku())->setPrice($finalPrice)->setBasePrice($finalPrice)->setOriginalPrice($finalPrice)->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal)->setWeeeTaxApplied(serialize(array()))->setBaseWeeeTaxDisposition(0)->setWeeeTaxDisposition(0)->setBaseWeeeTaxRowDisposition(0)->setWeeeTaxRowDisposition(0)->setBaseWeeeTaxAppliedAmount(0)->setBaseWeeeTaxAppliedRowAmount(0)->setWeeeTaxAppliedAmount(0)->setWeeeTaxAppliedRowAmount(0)->setProductOptions($options); $this->_subTotal += $rowTotal; return $orderItem; }
public function getPointsByProduct(Mage_Catalog_Model_Product $product) { $price = $product->getFinalPrice(); return $this->_calculatePoints($price); }
/** * returning unit amount * * @param Mage_Catalog_Model_Product $product * @param bool $includingTax * * @return float|int */ protected function _getUnitAmount($product, $includingTax = false) { $useParent = false; if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_USE_ROOT_PRICES) && $this->_parentProduct != null && $this->_parentProduct->isConfigurable()) { $useParent = true; } if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_USE_PRICE_INDEX_ON_EXPORT)) { $index = Mage::getModel('catalog/product_indexer_price'); $price = $useParent ? $index->load($this->_parentProduct->getId())->getFinalPrice() : $index->load($product->getId())->getFinalPrice(); } else { $price = $useParent ? $this->_parentProduct->getFinalPrice() : $product->getFinalPrice(); } if ($price <= 0) { $rulePrice = $useParent ? Mage::helper("shopgate/export")->calcProductPriceRule($this->_parentProduct) : Mage::helper("shopgate/export")->calcProductPriceRule($product); $price = $useParent ? $this->_parentProduct->getFinalPrice() : $product->getFinalPrice(); if ($rulePrice && $rulePrice < $price) { $price = $rulePrice; } } if (null != $this->_parentProduct && $this->_parentProduct->isConfigurable() && $useParent) { $totalOffset = 0; $totalPercentage = 0; $superAttributes = $this->_parentProduct->getTypeInstance(true)->getConfigurableAttributes($this->_parentProduct); foreach ($superAttributes as $superAttribute) { $code = $superAttribute->getProductAttribute()->getAttributeCode(); $index = $product->getData($code); if ($superAttribute->hasData('prices')) { foreach ($superAttribute->getPrices() as $saPrice) { if ($index == $saPrice["value_index"]) { if ($saPrice["is_percent"]) { $totalPercentage += $saPrice["pricing_value"]; } else { $totalOffset += $saPrice["pricing_value"]; } break; } } } } if ($price == $this->_parentProduct->getPrice()) { $price += $price * $totalPercentage / 100; $price += $totalOffset; } } return Mage::helper('tax')->getPrice($product, $price, $includingTax); }
public function testSetGetFinalPrice() { $this->assertEquals(0, $this->_model->getFinalPrice()); $this->_model->setFinalPrice(10); $this->assertEquals(10, $this->_model->getFinalPrice()); }
/** * 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; } }
/** * 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); }
/** * Calculate final price of selection * with take into account tier price * * @param Mage_Catalog_Model_Product $bundleProduct * @param Mage_Catalog_Model_Product $selectionProduct * @param float $bundleQty * @param float $selectionQty * @param bool $multiplyQty * @param bool $takeTierPrice * @return float */ public function getSelectionFinalTotalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty, $multiplyQty = true, $takeTierPrice = true) { if (is_null($selectionQty)) { $selectionQty = $selectionProduct->getSelectionQty(); } if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) { $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1); } else { if ($selectionProduct->getSelectionPriceType()) { // percent $product = clone $bundleProduct; $product->setFinalPrice($this->getPrice($product)); Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $bundleQty)); $price = $product->getData('final_price') * ($selectionProduct->getSelectionPriceValue() / 100); } else { // fixed $price = $selectionProduct->getSelectionPriceValue(); } } $price = $this->getLowestPrice($bundleProduct, $price, $bundleQty); if ($multiplyQty) { $price *= $selectionQty; } return $price; }
public function getFinalPriceHtml(Mage_Catalog_Model_Product $product, $qty = 1) { $price = $product->getFinalPrice() * $qty; return $this->_renderPrice($product, $price); }
/** * Get formatted by currency product price * * @param Mage_Catalog_Model_Product $product * @return array || float */ public function getFormatedPrice($product) { return Mage::app()->getStore()->formatPrice($product->getFinalPrice()); }
function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1) { $rowTotal = $product->getFinalPrice() * $qty; $options = $product->getCustomOptions(); $optionsByCode = array(); foreach ($options as $option) { $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())->setProduct($option->getProduct()); $optionsByCode[$quoteOption->getCode()] = $quoteOption; } $product->setCustomOptions($optionsByCode); $options = $product->getTypeInstance(true)->getOrderOptions($product); $orderItem = Mage::getModel('sales/order_item')->setStoreId($this->_storeId)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($product->getId())->setProductType($product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['rqty'])->setQtyOrdered($product['qty'])->setName($product->getName())->setSku($product->getSku())->setPrice($product->getFinalPrice())->setBasePrice($product->getFinalPrice())->setOriginalPrice($product->getFinalPrice())->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal)->setWeeeTaxApplied(serialize(array()))->setBaseWeeeTaxDisposition(0)->setWeeeTaxDisposition(0)->setBaseWeeeTaxRowDisposition(0)->setWeeeTaxRowDisposition(0)->setBaseWeeeTaxAppliedAmount(0)->setBaseWeeeTaxAppliedRowAmount(0)->setWeeeTaxAppliedAmount(0)->setWeeeTaxAppliedRowAmount(0)->setProductOptions($options); $this->_subTotal += $rowTotal; return $orderItem; }