1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magefix\Fixture\Builder\Helper; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Mage; |
7
|
|
|
use Mage_Sales_Model_Quote; |
8
|
|
|
use Magefix\Fixture\Builder\Helper; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ShippingMethod |
12
|
|
|
* |
13
|
|
|
* @package Magefix\Fixture\Builder\Helper |
14
|
|
|
* @author Carlo Tasca <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ShippingMethod implements Helper |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private $_shippingData = []; |
22
|
|
|
/** |
23
|
|
|
* @var Mage_Sales_Model_Quote |
24
|
|
|
*/ |
25
|
|
|
private $_quote; |
26
|
|
|
|
27
|
|
|
public function __construct(Mage_Sales_Model_Quote $quote, array $data) |
28
|
|
|
{ |
29
|
|
|
$this->_shippingData = $data; |
30
|
|
|
$this->_quote = $quote; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function addShippingDataToQuote() |
34
|
|
|
{ |
35
|
|
|
$shippingAddress = $this->_quote->getShippingAddress(); |
36
|
|
|
$shippingAddress->setShippingMethod($this->_shippingData['method']); |
37
|
|
|
$shippingAddress->setShippingDescription($this->_shippingData['description']); |
38
|
|
|
|
39
|
|
|
if ($this->_shippingData['collect_shipping_rates']) { |
40
|
|
|
$shippingAddress->setCollectShippingRates(true); |
41
|
|
|
$shippingAddress->collectShippingRates(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($this->_shippingData['collect_totals']) { |
45
|
|
|
$this->_quote->collectTotals(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($this->_shippingData['free_shipping']) { |
49
|
|
|
$this->_quote->setFreeShipping(true); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Enable specified carrier. e.g. flatrate |
55
|
|
|
* |
56
|
|
|
* @param string $carrier |
57
|
|
|
*/ |
58
|
|
|
public static function enable($carrier) |
59
|
|
|
{ |
60
|
|
|
self::_enableOrDisable($carrier, 1); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Disable specified carrier. e.g. flatrate |
65
|
|
|
* |
66
|
|
|
* @param string $carrier |
67
|
|
|
*/ |
68
|
|
|
public static function disable($carrier) |
69
|
|
|
{ |
70
|
|
|
self::_enableOrDisable($carrier, 0); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $carrier |
75
|
|
|
* |
76
|
|
|
* @return boolean |
77
|
|
|
* |
78
|
|
|
*/ |
79
|
|
|
public static function isEnabled($carrier) |
80
|
|
|
{ |
81
|
|
|
return Mage::getStoreConfig('carriers/' . $carrier . '/active'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $carrier |
86
|
|
|
* @param int $enable |
87
|
|
|
*/ |
88
|
|
|
protected static function _enableOrDisable($carrier, $enable) |
89
|
|
|
{ |
90
|
|
|
$carriers = Mage::getSingleton('shipping/config')->getActiveCarriers(); |
91
|
|
|
|
92
|
|
|
if (array_key_exists($carrier, $carriers)) { |
93
|
|
|
Mage::app()->getStore()->setConfig('carriers/' . $carrier . '/active', $enable); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|