/
OrderItem.php
71 lines (52 loc) · 1.71 KB
/
OrderItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* @copyright Copyright (c) 2011 by ESS-UA.
*/
class Ess_M2ePro_Model_Orders_OrderItem extends Mage_Core_Model_Abstract
{
protected $_order = NULL;
// ########################################
public function _construct()
{
parent::_construct();
$this->_init('M2ePro/Orders_OrderItem');
}
// ########################################
public function setOrder(Ess_M2ePro_Model_Orders_Order $order)
{
if (is_null($order->getId())) {
throw new Exception('Order does not exist.');
}
$this->_order = $order;
return $this;
}
/**
* @return Ess_M2ePro_Model_Orders_Order
*/
public function getOrder()
{
return $this->_order;
}
// ########################################
public function getItemsTotalPrice()
{
$connRead = $this->getResource()->getReadConnection();
$dbSelect = $connRead->select()
->from($this->getResource()->getTable('M2ePro/Orders_OrderItem'),new Zend_Db_Expr('SUM(`price`*`qty_purchased`)'))
->where('`ebay_order_id` = ?',(int)$this->getOrder()->getId());
return round($connRead->fetchOne($dbSelect), 2);
}
// ########################################
public function getOptions($asArray = false)
{
if (is_null($this->getId())) {
throw new Exception('Order item does not exist.');
}
$options = $this->getData('variations');
if (is_null($options)) {
return $asArray ? array() : $options;
}
return $asArray ? unserialize($options) : $options;
}
// ########################################
}