1: <?php
2:
3: namespace mcfedr\Paypal\Products;
4:
5: /**
6: * Describes a product to be sold
7: * Some vars effect selling
8: * Some are set when receiving a notification
9: */
10: class CartProduct extends Product {
11:
12: /**
13: * quanitity of product to sell
14: * @var int
15: */
16: public $quantity;
17:
18: /**
19: * overall handling fee for these items
20: * @var double
21: */
22: public $handling;
23:
24: /**
25: * discount given for all these items
26: * @var double
27: */
28: public $discount;
29:
30: /**
31: * tax for all these items
32: * @var double
33: */
34: public $tax;
35:
36: /**
37: * cost of shipping the first of these items
38: * @var double
39: */
40: public $shipping;
41:
42: /**
43: * cost of shipping further items
44: * @var double
45: */
46: public $shipping2;
47:
48: /**
49: * weight of this item if your account is setup to use weight base shipping
50: * @var double
51: */
52: public $weight;
53:
54: /**
55: * total amount paid for these items
56: * Set when received by notification
57: * @var double
58: */
59: public $total;
60:
61: /**
62: * total amount of shipping paid for these items
63: * Set when received by notification
64: * @var double
65: */
66: public $shippingTotal;
67:
68: /**
69: * Get a product from $vars
70: *
71: * @param array $vars
72: * @param string $number use when more than one product eg '1', '2'
73: */
74: public function __construct($vars = null, $number = '') {
75: parent::__construct($vars, $number);
76:
77: if (!is_null($vars)) {
78: if (isset($vars["quantity$number"])) {
79: $this->quantity = $vars["quantity$number"];
80: }
81: if (isset($vars["mc_shipping$number"])) {
82: $this->shippingTotal = $vars["mc_shipping$number"];
83: }
84: if (isset($vars["mc_handling$number"])) {
85: $this->handling = $vars["mc_handling$number"];
86: }
87: if (isset($vars["mc_gross_$number"])) {
88: $this->total = $vars["mc_gross_$number"];
89: $this->amount = $this->total - (empty($this->shippingTotal) ? 0 : $this->shippingTotal) - (empty($this->handling) ? 0 : $this->handling);
90: }
91: else if (isset($vars["mc_gross$number"])) {
92: $this->total = $vars["mc_gross$number"];
93: $this->amount = $this->total - (empty($this->shippingTotal) ? 0 : $this->shippingTotal) - (empty($this->handling) ? 0 : $this->handling);
94: }
95: }
96: }
97:
98: /**
99: * Sets up the array with paypal vars for $product
100: *
101: * @param array $params
102: * @param string $suffix used when more than one product is set eg "_1", "_2"
103: */
104: public function setParams(&$params, $suffix = '') {
105: parent::setParams($params, $suffix);
106:
107: $params["amount$suffix"] = $this->amount;
108: $params["quantity$suffix"] = empty($this->quantity) ? 1 : $this->quantity;
109: if (!empty($this->discount)) {
110: $params["discount_amount$suffix"] = $this->discount;
111: }
112: if (!empty($this->tax)) {
113: $params["tax$suffix"] = $this->tax;
114: }
115: if (!empty($this->shipping)) {
116: $params["shipping$suffix"] = $this->shipping;
117: if (!empty($this->shipping2)) {
118: $params["shipping2$suffix"] = $this->shipping2;
119: }
120: else {
121: $params["shipping2$suffix"] = $this->shipping;
122: }
123: }
124: if (!empty($this->handling)) {
125: $params["handling$suffix"] = $this->handling;
126: }
127: if (!empty($this->weight)) {
128: $params["weight$suffix"] = $this->weight;
129: }
130: }
131:
132: }
133: