Fees.php 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ 0T5wIQDa4dJN/CnrBV0wDQkJPdnUa87QAVpitVHnQi4=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.01]
  11. */
  12. /**
  13. * fees table service class
  14. */
  15. namespace Ppb\Service;
  16. use Ppb\Db\Table\Fees as FeesTable,
  17. Ppb\Service,
  18. Cube\Db\Expr,
  19. Ppb\Db\Table\Row\User,
  20. Ppb\Db\Table\Row\Category,
  21. Ppb\Db\Table\Row\TaxType,
  22. Ppb\Db\Table\Row\Voucher;
  23. class Fees extends AbstractService
  24. {
  25. /**
  26. * default calculation type
  27. */
  28. const DEFAULT_CALCULATION_TYPE = 'flat';
  29. /**
  30. * default fee type
  31. */
  32. const DEFAULT_TYPE = 'default';
  33. /**
  34. * listing setup/sale
  35. */
  36. const SETUP = 'setup';
  37. const SALE = 'sale';
  38. const HPFEAT = 'hpfeat';
  39. const CATFEAT = 'catfeat';
  40. const HIGHLIGHTED = 'highlighted';
  41. const BOLD = 'bold';
  42. const IMAGES = 'image';
  43. const MEDIA = 'video';
  44. const DIGITAL_DOWNLOADS = 'download';
  45. const ADDL_CATEGORY = 'addl_category_id';
  46. const BUYOUT = 'buyout_price';
  47. const RESERVE = 'reserve_price';
  48. const MAKE_OFFER = 'enable_make_offer';
  49. const ITEM_SWAP = 'item_swap';
  50. const SUBTITLE = 'subtitle';
  51. /**
  52. * user verification
  53. */
  54. const USER_VERIFICATION = 'user_verification';
  55. /**
  56. * user signup
  57. */
  58. const SIGNUP = 'signup';
  59. /**
  60. * store subscription
  61. */
  62. const STORE_SUBSCRIPTION = 'store_subscription';
  63. /**
  64. * additional constants
  65. */
  66. const NB_FREE_IMAGES = 'free_images';
  67. const NB_FREE_MEDIA = 'free_media';
  68. const NB_FREE_DOWNLOADS = 'free_downloads';
  69. /**
  70. *
  71. * fees to be applied
  72. * overridden by child classes
  73. *
  74. * @var array
  75. */
  76. protected $_fees = array();
  77. /**
  78. *
  79. * types of fees that will have tiers enabled
  80. *
  81. * @var array
  82. */
  83. protected $_feesTiers = array(
  84. self::SETUP,
  85. self::SALE
  86. );
  87. /**
  88. *
  89. * types of fees that cannot be set as category specific
  90. *
  91. * @var array
  92. */
  93. protected $_feesNoCategory = array(
  94. self::SIGNUP,
  95. );
  96. /**
  97. *
  98. * constants which should not have the preferred sellers reduction applied on
  99. *
  100. * @var array
  101. */
  102. protected $_additionalConstants = array(
  103. self::NB_FREE_IMAGES,
  104. self::NB_FREE_MEDIA,
  105. self::NB_FREE_DOWNLOADS,
  106. );
  107. /**
  108. *
  109. * the name of the fee, used to compare against the fees tiers array
  110. *
  111. * @var string
  112. */
  113. protected $_feeName;
  114. /**
  115. *
  116. * category id to calculate the fee against
  117. * (only if custom_fees = true)
  118. *
  119. * @var int
  120. */
  121. protected $_categoryId;
  122. /**
  123. *
  124. * the amount for which the fee is to be calculated
  125. * (applies to percentage based fees)
  126. *
  127. * @var float
  128. */
  129. protected $_amount;
  130. /**
  131. *
  132. * currency that the amount (if set) is in.
  133. * if different than the site's currency, calculate an exchange rate for percentage fees
  134. *
  135. * @var string
  136. */
  137. protected $_currency;
  138. /**
  139. *
  140. * currencies table service
  141. *
  142. * @var \Ppb\Service\Table\Currencies
  143. */
  144. protected $_currencies;
  145. /**
  146. *
  147. * flag to disable fees
  148. *
  149. * @var bool
  150. */
  151. protected $_disableFees = false;
  152. /**
  153. *
  154. * the tax that will apply to the fees
  155. *
  156. * @var \Ppb\Db\Table\Row\TaxType
  157. */
  158. protected $_taxType;
  159. /**
  160. *
  161. * voucher object that will apply to the fees
  162. *
  163. * @var \Ppb\Db\Table\Row\Voucher
  164. */
  165. protected $_voucher;
  166. /**
  167. *
  168. * payment completed redirect url in array or string format
  169. *
  170. * @var array|string
  171. */
  172. protected $_redirect;
  173. /**
  174. *
  175. * fee type - default fees have this field as null
  176. * will be used for listing types that will require their own fees like wanted ads etc
  177. *
  178. * @var string
  179. */
  180. protected $_type = self::DEFAULT_TYPE;
  181. /**
  182. *
  183. * transaction details
  184. *
  185. * @var mixed
  186. */
  187. protected $_transactionDetails;
  188. /**
  189. *
  190. * class constructor
  191. */
  192. public function __construct()
  193. {
  194. parent::__construct();
  195. $this->setTable(
  196. new FeesTable());
  197. }
  198. /**
  199. *
  200. * set fees array
  201. *
  202. * @param array $fees
  203. *
  204. * @return $this
  205. */
  206. public function setFees($fees)
  207. {
  208. $this->_fees = $fees;
  209. return $this;
  210. }
  211. /**
  212. *
  213. * get fees array or the name of a certain fee if key is specified
  214. *
  215. * @param string $key
  216. *
  217. * @return array|string
  218. */
  219. public function getFees($key = null)
  220. {
  221. if (array_key_exists($key, $this->_fees)) {
  222. return $this->_fees[$key];
  223. }
  224. return $this->_fees;
  225. }
  226. /**
  227. *
  228. * get fees tiers array
  229. *
  230. * @return array
  231. */
  232. public function getFeesTiers()
  233. {
  234. return $this->_feesTiers;
  235. }
  236. /**
  237. *
  238. * set fees tiers array
  239. *
  240. * @param array $feesTiers
  241. *
  242. * @return $this
  243. */
  244. public function setFeesTiers($feesTiers)
  245. {
  246. $this->_feesTiers = $feesTiers;
  247. return $this;
  248. }
  249. /**
  250. *
  251. * check if a fee has tiers
  252. *
  253. * @param string|null $feeName
  254. *
  255. * @return bool
  256. */
  257. public function hasTiers($feeName = null)
  258. {
  259. if ($feeName === null) {
  260. $feeName = $this->_feeName;
  261. }
  262. return (in_array($feeName, $this->_feesTiers));
  263. }
  264. /**
  265. *
  266. * get fees with no category array
  267. *
  268. * @return array
  269. */
  270. public function getFeesNoCategory()
  271. {
  272. return $this->_feesNoCategory;
  273. }
  274. /**
  275. *
  276. * set fees with no category array
  277. *
  278. * @param array $feesNoCategory
  279. *
  280. * @return $this
  281. */
  282. public function setFeesNoCategory($feesNoCategory)
  283. {
  284. $this->_feesNoCategory = $feesNoCategory;
  285. return $this;
  286. }
  287. /**
  288. *
  289. * check if a fee has no categories option
  290. *
  291. * @param string|null $feeName
  292. *
  293. * @return bool
  294. */
  295. public function hasNoCategory($feeName = null)
  296. {
  297. if ($feeName === null) {
  298. $feeName = $this->_feeName;
  299. }
  300. return (in_array($feeName, $this->_feesNoCategory));
  301. }
  302. /**
  303. *
  304. * get fee name
  305. *
  306. * @return string
  307. * @throws \RuntimeException
  308. */
  309. public function getFeeName()
  310. {
  311. if ($this->_feeName === null) {
  312. throw new \RuntimeException(
  313. "A fee name is required when querying the fees table.");
  314. }
  315. return $this->_feeName;
  316. }
  317. /**
  318. *
  319. * set the fee name
  320. *
  321. * @param string $feeName
  322. *
  323. * @return $this
  324. */
  325. public function setFeeName($feeName)
  326. {
  327. $this->_feeName = $feeName;
  328. return $this;
  329. }
  330. /**
  331. *
  332. * set user data
  333. *
  334. * @param int|string|\Ppb\Db\Table\Row\User $user
  335. *
  336. * @return $this
  337. * @throws \InvalidArgumentException
  338. */
  339. public function setUser($user)
  340. {
  341. if (is_int($user) || is_string($user)) {
  342. $userService = new Service\Users();
  343. $user = $userService->findBy('id', $user);
  344. }
  345. if (!$user instanceof User) {
  346. throw new \InvalidArgumentException("The method requires a string, an integer or an object of type \Ppb\Db\Table\Row\User.");
  347. }
  348. $this->_user = $user;
  349. return $this;
  350. }
  351. /**
  352. *
  353. * get calculation amount
  354. *
  355. * @return float
  356. */
  357. public function getAmount()
  358. {
  359. return $this->_amount;
  360. }
  361. /**
  362. *
  363. * set calculation amount
  364. *
  365. * @param float $amount
  366. *
  367. * @return $this
  368. */
  369. public function setAmount($amount)
  370. {
  371. $this->_amount = $amount;
  372. return $this;
  373. }
  374. /**
  375. *
  376. * get currency for the amount for which the fee is to be calculated
  377. *
  378. * @return string
  379. */
  380. public function getCurrency()
  381. {
  382. return $this->_currency;
  383. }
  384. /**
  385. *
  386. * set currency for the amount for which the fee is to be calculated
  387. *
  388. * @param string $currency
  389. *
  390. * @return $this
  391. */
  392. public function setCurrency($currency)
  393. {
  394. $this->_currency = $currency;
  395. return $this;
  396. }
  397. /**
  398. *
  399. * get category id
  400. *
  401. * @return int
  402. */
  403. public function getCategoryId()
  404. {
  405. return $this->_categoryId;
  406. }
  407. /**
  408. *
  409. * set fee category id, but only if custom fees are enabled
  410. *
  411. * @param int $categoryId
  412. *
  413. * @return $this
  414. */
  415. public function setCategoryId($categoryId)
  416. {
  417. if ($categoryId > 0) {
  418. $categories = new Service\Table\Relational\Categories();
  419. $mainCategory = $categories->getRoot($categoryId);
  420. if ($mainCategory instanceof Category) {
  421. $categoryId = ($mainCategory->getData('custom_fees')) ? $mainCategory->getData('id') : null;
  422. }
  423. else {
  424. $categoryId = null;
  425. }
  426. }
  427. $this->_categoryId = $categoryId;
  428. return $this;
  429. }
  430. /**
  431. *
  432. * get currencies table service
  433. *
  434. * @return \Ppb\Service\Table\Currencies
  435. */
  436. public function getCurrencies()
  437. {
  438. if (!$this->_currencies instanceof Service\Table\Currencies) {
  439. $this->setCurrencies(
  440. new Service\Table\Currencies());
  441. }
  442. return $this->_currencies;
  443. }
  444. /**
  445. *
  446. * set currencies service
  447. *
  448. * @param \Ppb\Service\Table\Currencies $currencies
  449. *
  450. * @return $this
  451. */
  452. public function setCurrencies(Service\Table\Currencies $currencies)
  453. {
  454. $this->_currencies = $currencies;
  455. return $this;
  456. }
  457. /**
  458. *
  459. * get fees calculation flag
  460. *
  461. * @return bool
  462. */
  463. public function isDisabledFees()
  464. {
  465. return $this->_disableFees;
  466. }
  467. /**
  468. *
  469. * set fees calculation flag
  470. *
  471. * @param bool $disableFees
  472. *
  473. * @return $this
  474. */
  475. public function disableFees($disableFees = true)
  476. {
  477. $this->_disableFees = (bool)$disableFees;
  478. return $this;
  479. }
  480. /**
  481. *
  482. * set tax type object
  483. *
  484. * @param \Ppb\Db\Table\Row\TaxType $taxType
  485. *
  486. * @return $this
  487. */
  488. public function setTaxType(TaxType $taxType)
  489. {
  490. $this->_taxType = $taxType;
  491. return $this;
  492. }
  493. /**
  494. *
  495. * get tax type object
  496. *
  497. * @return \Ppb\Db\Table\Row\TaxType
  498. */
  499. public function getTaxType()
  500. {
  501. if (!$this->_taxType instanceof TaxType) {
  502. $settings = $this->getSettings();
  503. $this->setTaxType(
  504. new TaxType(array(
  505. 'table' => new \Ppb\Db\Table\TaxTypes(),
  506. 'data' => array()
  507. )));
  508. if ($settings['enable_tax_fees'] && $settings['tax_fees_type']) {
  509. $taxTypesService = new Service\Table\TaxTypes();
  510. $taxType = $taxTypesService->findBy('id', $settings['tax_fees_type']);
  511. if ($taxType instanceof TaxType) {
  512. $locationsIds = \Ppb\Utility::unserialize($taxType->getData('locations_ids'));
  513. $address = $this->getUser()->getAddress();
  514. if (isset($address['country']) && isset($address['state']) && is_array($locationsIds)) {
  515. if (in_array($address['country'], $locationsIds) || in_array($address['state'], $locationsIds)) {
  516. $this->setTaxType($taxType);
  517. }
  518. }
  519. }
  520. }
  521. }
  522. return $this->_taxType;
  523. }
  524. /**
  525. *
  526. * set voucher object
  527. *
  528. * @param string|\Ppb\Db\Table\Row\Voucher $voucher voucher code or voucher object
  529. *
  530. * @return $this
  531. */
  532. public function setVoucher($voucher)
  533. {
  534. if (!$voucher instanceof Voucher) {
  535. $vouchersService = new Service\Vouchers();
  536. $voucher = $vouchersService->findBy($voucher);
  537. }
  538. $this->_voucher = $voucher;
  539. return $this;
  540. }
  541. /**
  542. *
  543. * get voucher object
  544. *
  545. * @return \Ppb\Db\Table\Row\Voucher
  546. */
  547. public function getVoucher()
  548. {
  549. return $this->_voucher;
  550. }
  551. /**
  552. *
  553. * set redirect params
  554. *
  555. * @param array|string $redirect
  556. *
  557. * @return $this
  558. */
  559. public function setRedirect($redirect)
  560. {
  561. $this->_redirect = $redirect;
  562. return $this;
  563. }
  564. /**
  565. *
  566. * get redirect params
  567. *
  568. * @return array|string
  569. */
  570. public function getRedirect()
  571. {
  572. return $this->_redirect;
  573. }
  574. /**
  575. *
  576. * set listing type
  577. *
  578. * @param string $type
  579. *
  580. * @return $this
  581. */
  582. public function setType($type)
  583. {
  584. $this->_type = $type;
  585. return $this;
  586. }
  587. /**
  588. *
  589. * get listing type
  590. *
  591. * @return string
  592. */
  593. public function getType()
  594. {
  595. return $this->_type;
  596. }
  597. /**
  598. *
  599. * get transaction details
  600. *
  601. * @return mixed
  602. */
  603. public function getTransactionDetails()
  604. {
  605. return $this->_transactionDetails;
  606. }
  607. /**
  608. *
  609. * set transaction details
  610. *
  611. * @param mixed $transactionDetails
  612. *
  613. * @return $this
  614. */
  615. public function setTransactionDetails($transactionDetails)
  616. {
  617. $this->_transactionDetails = $transactionDetails;
  618. return $this;
  619. }
  620. /**
  621. *
  622. * get the amount of a certain fee
  623. * calculates based on preferred seller feature
  624. *
  625. * @param string $name
  626. * @param float $amount
  627. * @param int $categoryId
  628. * @param null $currency
  629. *
  630. * @return float|null return the fee amount or null if no fee applies for the selected action
  631. */
  632. public function getFeeAmount($name = null, $amount = null, $categoryId = null, $currency = null)
  633. {
  634. if ($this->isDisabledFees()) {
  635. return null;
  636. }
  637. if ($name === null) {
  638. $name = $this->getFeeName();
  639. }
  640. if ($amount === null) {
  641. $amount = $this->getAmount();
  642. }
  643. if ($categoryId !== null) {
  644. $this->setCategoryId($categoryId);
  645. }
  646. $categoryId = $this->getCategoryId();
  647. if ($currency !== null) {
  648. $this->setCurrency($currency);
  649. }
  650. $currency = $this->getCurrency();
  651. $select = $this->_table->select(array('amount', 'calculation_type'))
  652. ->where("name = ?", $name)
  653. ->where("type = ?", $this->getType());
  654. if (in_array($name, $this->_feesTiers) && $amount !== null) {
  655. $amountConverted = $this->getCurrencies()->convertAmount($amount, $currency);
  656. $select->where("tier_from < ?", $amountConverted)
  657. ->where("tier_to >= ?", $amountConverted);
  658. }
  659. if ($categoryId !== null) {
  660. $select->where("category_id = ?", $categoryId);
  661. }
  662. else {
  663. $select->where("category_id IS NULL");
  664. }
  665. $row = $this->_table->fetchRow($select);
  666. if ($row !== null) {
  667. if ($row['calculation_type'] == 'percent') {
  668. $amount = $row['amount'] * $amount / 100;
  669. $amount = $this->getCurrencies()->convertAmount($amount, $currency);
  670. }
  671. else {
  672. $amount = $row['amount'];
  673. }
  674. if (!in_array($name, $this->_additionalConstants)) {
  675. $amount = $this->_applyPreferredSellersReduction($amount);
  676. $amount = $this->_addTax($amount);
  677. }
  678. return $amount;
  679. // return $this->_applyVoucher($amount, $settings['currency']);
  680. }
  681. return null;
  682. }
  683. /**
  684. *
  685. * save data in the fees table
  686. *
  687. * @param array $data
  688. *
  689. * @return $this
  690. */
  691. public function save(array $data)
  692. {
  693. $categoryId = null;
  694. $calculationType = 'flat';
  695. $type = 'default';
  696. $feeName = $this->getFeeName();
  697. if (isset($data['category_id'])) {
  698. $categoryId = intval($data['category_id']);
  699. unset($data['category_id']);
  700. }
  701. if (isset($data['calculation_type'])) {
  702. if (!is_array($data['calculation_type'])) {
  703. $calculationType = $data['calculation_type'];
  704. unset($data['calculation_type']);
  705. }
  706. }
  707. if (isset($data['sale_fee_payer'])) {
  708. $settingsService = new Settings();
  709. $settingsService->save(array(
  710. 'sale_fee_payer' => $data['sale_fee_payer'],
  711. ));
  712. }
  713. if (isset($data['type'])) {
  714. $type = $data['type'];
  715. unset($data['type']);
  716. }
  717. $table = $this->getTable();
  718. if ($this->hasTiers()) {
  719. if (isset($data['tier_from'])) {
  720. foreach ($data['tier_from'] as $key => $tierFrom) {
  721. if (!empty($data['amount'][$key])) {
  722. $row = $where = null;
  723. if (!empty($data['id'][$key])) {
  724. $where = $table->getAdapter()->quoteInto('id = ?', intval($data['id'][$key]));
  725. $row = $this->getTable()->fetchRow($where);
  726. }
  727. $array = array(
  728. 'name' => $feeName,
  729. 'type' => $type,
  730. 'amount' => $data['amount'][$key],
  731. 'calculation_type' => $data['calculation_type'][$key],
  732. 'category_id' => (!empty($categoryId)) ? $categoryId : new Expr('null'),
  733. 'tier_from' => $data['tier_from'][$key],
  734. 'tier_to' => $data['tier_to'][$key],
  735. );
  736. if (count($row) > 0) {
  737. $table->update($array, $where);
  738. }
  739. else {
  740. $table->insert($array);
  741. }
  742. }
  743. }
  744. }
  745. }
  746. else {
  747. foreach ($data as $key => $value) {
  748. $where = $table->select()
  749. ->where('name = ?', $key)
  750. ->where('type = ?', $type);
  751. if ($categoryId) {
  752. $where->where('category_id = ?', $categoryId);
  753. }
  754. else {
  755. $where->where('category_id IS NULL');
  756. }
  757. $row = $table->fetchRow($where);
  758. $insert = array(
  759. 'amount' => $value,
  760. 'calculation_type' => $calculationType);
  761. if (count($row) > 0) {
  762. $table->update($insert, "id = '{$row['id']}'");
  763. }
  764. else {
  765. $insert['name'] = $key;
  766. if (isset($type)) {
  767. $insert['type'] = $type;
  768. }
  769. if ($categoryId) {
  770. $insert['category_id'] = $categoryId;
  771. }
  772. $table->insert($insert);
  773. }
  774. }
  775. }
  776. return $this;
  777. }
  778. /**
  779. *
  780. * get fees data for usage in admin setup forms
  781. *
  782. * @param string $name the name of the fee
  783. * @param integer $categoryId id of the category
  784. * @param string $type fee/listing type
  785. *
  786. * @return array
  787. */
  788. public function getData($name = null, $categoryId = null, $type = null)
  789. {
  790. if ($name === null) {
  791. $name = $this->getFeeName();
  792. }
  793. if ($type !== null) {
  794. $this->setType($type);
  795. }
  796. $type = $this->getType();
  797. $select = $this->_table->select()
  798. ->where('type = ?', $type);
  799. if ($name !== null) {
  800. $select->where("name = ?", $name);
  801. }
  802. if ($categoryId) {
  803. $select->where("category_id = ?", $categoryId);
  804. }
  805. else {
  806. $select->where("category_id IS NULL");
  807. }
  808. $data = $this->fetchAll($select)->toArray();
  809. // if data = 1 then get all non tiered fields plus a 'type' field
  810. if ($this->hasTiers() !== true) {
  811. $result['fee_type'] = (isset($data[0]['calculation_type'])) ? $data[0]['calculation_type'] : self::DEFAULT_CALCULATION_TYPE;
  812. $select = $this->_table->select()
  813. ->where('type = ?', $type);
  814. if ($categoryId) {
  815. $select->where("category_id = ?", $categoryId);
  816. }
  817. else {
  818. $select->where("category_id IS NULL");
  819. }
  820. $rows = $this->fetchAll($select);
  821. foreach ($rows as $row) {
  822. $result[$row['name']] = $row['amount'];
  823. }
  824. $data = $result;
  825. }
  826. $data['category_id'] = $categoryId;
  827. return $data;
  828. }
  829. /**
  830. *
  831. * delete table data by id - fees tiers only
  832. *
  833. * @param array $data
  834. *
  835. * @return int The number of affected rows.
  836. */
  837. public function delete(array $data)
  838. {
  839. $data = array_filter(
  840. array_values($data));
  841. if (count($data) > 0) {
  842. return $this->_table->delete("id IN (" . implode(',', $data) . ")");
  843. }
  844. return null;
  845. }
  846. /**
  847. *
  848. * add tax to a certain value, and return the rounded value
  849. *
  850. * @param float $value
  851. *
  852. * @return float
  853. */
  854. protected function _addTax($value)
  855. {
  856. $value += $value * $this->getTaxType()->getData('amount') / 100;
  857. return $this->_roundNumber($value);
  858. }
  859. /**
  860. *
  861. * apply voucher to a certain value and currency and return rounded value
  862. *
  863. * @param float $value
  864. * @param string $currency
  865. *
  866. * @return float
  867. */
  868. protected function _applyVoucher($value, $currency)
  869. {
  870. if (($voucher = $this->getVoucher()) instanceof Voucher) {
  871. $value = $voucher->apply($value, $currency);
  872. }
  873. return $this->_roundNumber($value);
  874. }
  875. /**
  876. *
  877. * apply preferred sellers reduction, and return rounded value
  878. *
  879. * @param $value
  880. *
  881. * @return float
  882. */
  883. protected function _applyPreferredSellersReduction($value)
  884. {
  885. $settings = $this->getSettings();
  886. if ($settings['preferred_sellers'] && $this->_user['preferred_seller']) {
  887. $value = ($value * (1 - $settings['preferred_sellers_reduction'] / 100));
  888. }
  889. return $this->_roundNumber($value);
  890. }
  891. /**
  892. *
  893. * requires an array of data and
  894. * makes the required modifications to the affected tables
  895. *
  896. * functionality defined in child classes
  897. *
  898. * @param bool $ipn true if payment is completed, false otherwise
  899. * @param array $post data needed by the method
  900. */
  901. public function callback($ipn, array $post)
  902. {
  903. }
  904. /**
  905. *
  906. * get the signup fee value (tax included)
  907. *
  908. * functionality defined in child classes
  909. *
  910. * @return void
  911. */
  912. public function getTotalAmount()
  913. {
  914. }
  915. }