class Product { public $id; public $name; public $category; public $discount; public $price; public function getRealPrice() { return $this->discount ? $this->discount->calculate($this->realPrice) : $this->realPrice; } }
Those. There is a separate discount object that we can assign at any time. Depending on it, the real price will vary.
class Category { public $id; public $name; public $noAmount; }
There is no change.
class Order implements Countable, Iterator { public $id; /** * Массив объектов Product * @var array() */ $productList; public function getTotalPrice() { // подсчет общей стоимости } /* Реализация интерфейсов */ }
Here is a list of products as in the answer @ S.Pronin, but you need to make this object model iterable and Countable (if possible), then you can write something like count($order) , or foreach($order as $product)
And finally, a discount:
class Discount { public $id; public $discount; public function calculate($price) { return $price - $price * $this->discount; //например, скидка 15%, тогда $discount должен быть 0.15 } }
Such a discount model is suitable, for example, for discounts of the type “Disposal - all by 50% each”, then one object is assigned for all goods, and it is possible to simply change M% to N%. Of course, if each product has its own unique discount, this method does not quite fit.