Exemplo n.º 1
0
 /**
  * Warning: this is a copy-paste from testGetFinalPrice(), but the method has different interface
  */
 public function testGetChildFinalPrice()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     // fixture
     // regular & tier prices
     $this->assertEquals(10.0, $this->_model->getChildFinalPrice('', '', $product, 1));
     $this->assertEquals(8.0, $this->_model->getChildFinalPrice('', '', $product, 2));
     $this->assertEquals(5.0, $this->_model->getChildFinalPrice('', '', $product, 5));
     // with options
     $product->addCustomOption('option_ids', implode(',', array_keys($product->getOptions())));
     foreach ($product->getOptions() as $id => $option) {
         $product->addCustomOption("option_{$id}", $option->getValue());
     }
     $this->assertEquals(13.0, $this->_model->getChildFinalPrice('', '', $product, 1));
 }
Exemplo n.º 2
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @param float                      $productQty
  * @param Mage_Catalog_Model_Product $childProduct
  * @param float                      $childProductQty
  *
  * @return float
  */
 public function getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
 {
     // Bail if the parameters are unexpected and let the core code handle (or fail)
     if (!$product instanceof Mage_Catalog_Model_Product || !$childProduct instanceof Mage_Catalog_Model_Product) {
         return parent::getChildFinalPrice($product, $productQty, $childProduct, $childProductQty);
     }
     // If the parent product type is unexpected then bail and let core handle
     $type = $product->getTypeInstance(true);
     if (!$type instanceof OpenMage_KittedProduct_Model_Product_Type) {
         return parent::getChildFinalPrice($product, $productQty, $childProduct, $childProductQty);
     }
     // Calculate the normal, unadjusted linked items total
     $calculatedTotal = 0.0;
     foreach ($type->getAssociatedProducts($product, false) as $associatedProduct) {
         $calculatedTotal += $associatedProduct->getPrice() * $associatedProduct->getQty();
     }
     // Generate a child price multiplier
     $priceMultiplier = $calculatedTotal > 0.0 ? $product->getPrice() / $calculatedTotal : 1.0;
     // Generate the normal final price
     $finalPrice = $childProduct->getFinalPrice($childProductQty);
     // Multiply the final price by the multiplier to get the adjusted final price
     $finalPrice *= $priceMultiplier;
     // Round the final price
     $finalPrice = $product->getStore()->roundPrice($finalPrice);
     return $finalPrice;
 }