/** * * Test applying utility method for price variation with positive variation * * @since 1.1.0 * * @group price * @group helper * * @covers \ingot\testing\utility\price::apply_variation() */ public function testPriceVarPositive() { $base_price = 10; $this->assertSame(ingot_sanitize_amount(15), ingot_sanitize_amount(\ingot\testing\utility\price::apply_variation(0.5, $base_price))); $this->assertSame(ingot_sanitize_amount(12), ingot_sanitize_amount(\ingot\testing\utility\price::apply_variation(0.2, $base_price))); $this->assertSame(ingot_sanitize_amount(18.5), ingot_sanitize_amount(\ingot\testing\utility\price::apply_variation(0.85, $base_price))); }
/** * Set price * * @since 1.1.0 * * @access protected * * @return mixed */ protected function set_price() { $this->set_variant(); $this->set_price_callback(); $this->set_product(); if (is_callable($this->price_callback)) { $variant = $this->variant; if (is_array($variant)) { $variation = price::get_price_variation($variant); $base_price = (double) call_user_func($this->price_callback, $this->product->ID); if (0 == $base_price || 0 == $variation) { $this->price = ingot_sanitize_amount($base_price); } $price = price::apply_variation($variation, $base_price); if ($price < 0) { $this->price = ingot_sanitize_amount($base_price); } $this->price = ingot_sanitize_amount($price); } } }