Create item price, price tier, and item type entities for regional pricing. #780
This commit is contained in:
parent
b51160e9d0
commit
9447f64312
3 changed files with 195 additions and 0 deletions
53
src/Entity/ItemPrice.php
Normal file
53
src/Entity/ItemPrice.php
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="item_price")
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ItemPrice
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="items")
|
||||||
|
* @ORM\JoinColumn(name="price_tier_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
protected $price_tier;
|
||||||
|
|
||||||
|
// item type
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="ItemType", inversedBy="item_prices")
|
||||||
|
* @ORM\JoinColumn(name="item_type_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
protected $item_type;
|
||||||
|
|
||||||
|
// could be battery id or service offering id, loosely coupled
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
protected $item_id;
|
||||||
|
|
||||||
|
// current price
|
||||||
|
// NOTE: we need to move the decimal point two places to the left to get actual value
|
||||||
|
// we want to avoid floating point problems
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
protected $item_price;
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/Entity/ItemType.php
Normal file
69
src/Entity/ItemType.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="item_type", indexes={
|
||||||
|
* @ORM\Index(name="item_type_idx", columns={"code"})
|
||||||
|
* })
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ItemType
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $code;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->code = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode($code)
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode()
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
}
|
||||||
73
src/Entity/PriceTier.php
Normal file
73
src/Entity/PriceTier.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="price_tier")
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PriceTier
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// name of price tier
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
// supported areas under price tier
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="json")
|
||||||
|
*/
|
||||||
|
protected $meta_areas;
|
||||||
|
|
||||||
|
// items under a price tier
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="ItemPrice", mappedBy="price_tier")
|
||||||
|
*/
|
||||||
|
protected $items;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->meta_areas = [];
|
||||||
|
|
||||||
|
$this->items = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addMetaArea($id, $value)
|
||||||
|
{
|
||||||
|
$this->meta_areas[$id] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllMetaAreas()
|
||||||
|
{
|
||||||
|
return $this->meta_areas;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue