public function run()
 {
     Price::create(['min' => '0', 'max' => '1000000']);
     Price::create(['min' => '1000000', 'max' => '10000000']);
     Price::create(['min' => '10000000', 'max' => '100000000']);
     Price::create(['min' => '100000000']);
 }
Esempio n. 2
0
 public function __construct($controller, $name, $quantity = null, $redirectURL = null)
 {
     parent::__construct($controller, $name, FieldList::create(), FieldList::create(), null);
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript('swipestripe/javascript/ProductForm.js');
     $this->product = $controller->data();
     $this->quantity = $quantity;
     $this->redirectURL = $redirectURL;
     $this->fields = $this->createFields();
     $this->actions = $this->createActions();
     $this->validator = $this->createValidator();
     $this->setupFormErrors();
     $this->addExtraClass('product-form');
     //Add a map of all variations and prices to the page for updating the price
     $map = array();
     $variations = $this->product->Variations();
     $productPrice = $this->product->Price();
     if ($variations && $variations->exists()) {
         foreach ($variations as $variation) {
             if ($variation->isEnabled()) {
                 $variationPrice = $variation->Price();
                 $amount = Price::create();
                 $amount->setAmount($productPrice->getAmount() + $variationPrice->getAmount());
                 $amount->setCurrency($productPrice->getCurrency());
                 $amount->setSymbol($productPrice->getSymbol());
                 $map[] = array('price' => $amount->Nice(), 'options' => $variation->Options()->column('ID'), 'free' => _t('Product.FREE', 'Free'));
             }
         }
     }
     $this->setAttribute('data-map', json_encode($map));
 }
Esempio n. 3
0
 public function Amount()
 {
     // TODO: Multi currency
     $order = $this->Order();
     $amount = Price::create();
     $amount->setAmount($this->Price);
     $amount->setCurrency($order->BaseCurrency);
     $amount->setSymbol($order->BaseCurrencySymbol);
     return $amount;
 }
Esempio n. 4
0
 public function Amount()
 {
     $amount = Price::create();
     $amount->setCurrency($this->Currency);
     $amount->setAmount($this->Price);
     $amount->setSymbol(ShopConfig::current_shop_config()->BaseCurrencySymbol);
     //Transform amount for applying discounts etc.
     $this->extend('updateAmount', $amount);
     return $amount;
 }
Esempio n. 5
0
 /**
  * Add shipping region code dropdown to form.
  * @return FieldList
  */
 public function getFormFields()
 {
     $fields = new FieldList();
     $field = new StreakGST_ModifierField($this, self::description());
     /** @var Price $price */
     $price = Price::create();
     $price->setAmount($this->GST);
     $field->setAmount($price);
     $fields->push($field);
     return $fields;
 }
Esempio n. 6
0
 public function run()
 {
     Price::create(['price_id' => 1, 'low_price' => 0, 'high_price' => 50]);
     Price::create(['price_id' => 2, 'low_price' => 50, 'high_price' => 100]);
     Price::create(['price_id' => 3, 'low_price' => 100, 'high_price' => 300]);
     Price::create(['price_id' => 4, 'low_price' => 300, 'high_price' => 500]);
     Price::create(['price_id' => 5, 'low_price' => 500, 'high_price' => 1000]);
     Price::create(['price_id' => 1, 'low_price' => 0, 'high_price' => 50]);
     Price::create(['price_id' => 2, 'low_price' => 50, 'high_price' => 100]);
     Price::create(['price_id' => 3, 'low_price' => 100, 'high_price' => 300]);
     Price::create(['price_id' => 4, 'low_price' => 300, 'high_price' => 500]);
     Price::create(['price_id' => 5, 'low_price' => 500, 'high_price' => 1000]);
     Price::create(['price_id' => 5, 'low_price' => 500, 'high_price' => 1000]);
 }
Esempio n. 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('min' => 'required|integer|min:0', 'max' => 'integer|min:0');
     $input = Input::except('_token');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::action('PriceController@create')->withErrors($validator);
     } else {
         if ($input['max'] == '') {
             $input['max'] = NULL;
         }
         $id = Price::create($input)->id;
         return Redirect::action('PriceController@index');
     }
 }
 /**
  * Add shipping region code dropdown to form.
  * @return FieldList
  */
 public function getFormFields()
 {
     $fields = new FieldList();
     if ($shippingRegion = $this->Region()) {
         $field = new StreakRegionShippingModifierField($this, $this->Description, $shippingRegion->ID);
         /** @var Price $price */
         $price = Price::create();
         $price->setAmount($this->Price);
         $field->setAmount($price);
         $fields->push($field);
     }
     if (!$fields->exists()) {
         Requirements::javascript('swipestreak-regionalshipping/javascript/RegionalShippingModifierField.js');
     }
     return $fields;
 }
require_once "DataBase/Priceset.php";
require_once "DataBase/Group.php";
require_once "DataBase/Price.php";
$db_action = var_get_post("db_action", "");
$product = new Product();
$tax = new Tax();
$category = new Category();
$priceset = new Priceset();
$price = new Price();
$group = new Group();
switch ($db_action) {
    case "new":
        $product->create(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", "")));
        $priceset_list = $priceset->get();
        for ($i = 0; $i < count($priceset_list); $i++) {
            $price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
        }
        break;
    case "edit":
        $product->update(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", "")));
        $priceset_list = $priceset->get();
        for ($i = 0; $i < count($priceset_list); $i++) {
            if ($price->exists(var_post("priceset_id_" . $i, ""), var_post("product_id", ""))) {
                $price->update(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
            } else {
                $price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
            }
        }
        break;
    case "delete":
        $product->delete(var_get("product_id", ""));
Esempio n. 10
0
 /**
  * Calculate the total paid for this order, only 'Success' payments
  * are considered.
  * 
  * @return Price With value and currency of total paid
  */
 public function TotalPaid()
 {
     $paid = 0;
     if ($this->Payments()) {
         foreach ($this->Payments() as $payment) {
             if ($payment->Status == 'Success') {
                 $paid += $payment->Amount->getAmount();
             }
         }
     }
     $totalPaid = Price::create();
     $totalPaid->setAmount($paid);
     $totalPaid->setCurrency($this->BaseCurrency);
     $totalPaid->setSymbol($this->BaseCurrencySymbol);
     return $totalPaid;
 }
Esempio n. 11
0
 /**
  * Change product price after it is in the cart, check that price has not changed in cart
  */
 public function testAddProductToCartChangePrice()
 {
     $productA = $this->objFromFixture('Product', 'productA');
     $this->logInAs('admin');
     $productA->doPublish();
     $this->logOut();
     $this->get(Director::makeRelative($productA->Link()));
     $this->submitForm('ProductForm_ProductForm', null, array('Quantity' => 1));
     $order = Cart::get_current_order();
     $items = $order->Items();
     $firstItem = $items->First();
     $this->assertEquals(1, $order->Items()->Count());
     $this->assertEquals($productA->Price, $firstItem->Price);
     $newAmount = Price::create();
     $newAmount->setAmount(72.34);
     $newAmount->setCurrency('NZD');
     DataObject::flush_and_destroy_cache();
     $this->logInAs('admin');
     $productA->Price = $newAmount->getAmount();
     $productA->doPublish();
     $this->logOut();
     $this->get(Director::makeRelative($productA->Link()));
     $this->submitForm('ProductForm_ProductForm', null, array('Quantity' => 1));
     $order = Cart::get_current_order();
     $items = $order->Items();
     $firstItem = $items->First();
     $secondItem = $items->Last();
     $this->assertEquals(2, $order->Items()->Count());
     $this->assertTrue(in_array(500, $order->Items()->column('Price')));
     $this->assertTrue(in_array(72.34, $order->Items()->column('Price')));
 }
Esempio n. 12
0
 /**
  * @param float $value
  * @param string $currency
  * @return OptionalPrice
  */
 public static function create($value = null, $currency = null)
 {
     return parent::create($value, $currency);
 }