1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Checkout
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Multishipping checkout choose item addresses block
29: *
30: * @category Mage
31: * @package Mage_Checkout
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Checkout_Block_Multishipping_Addresses extends Mage_Sales_Block_Items_Abstract
35: {
36: /**
37: * Retrieve multishipping checkout model
38: *
39: * @return Mage_Checkout_Model_Type_Multishipping
40: */
41: public function getCheckout()
42: {
43: return Mage::getSingleton('checkout/type_multishipping');
44: }
45:
46: protected function _prepareLayout()
47: {
48: if ($headBlock = $this->getLayout()->getBlock('head')) {
49: $headBlock->setTitle(Mage::helper('checkout')->__('Ship to Multiple Addresses') . ' - ' . $headBlock->getDefaultTitle());
50: }
51: return parent::_prepareLayout();
52: }
53:
54: public function getItems()
55: {
56: $items = $this->getCheckout()->getQuoteShippingAddressesItems();
57: $itemsFilter = new Varien_Filter_Object_Grid();
58: $itemsFilter->addFilter(new Varien_Filter_Sprintf('%d'), 'qty');
59: return $itemsFilter->filter($items);
60: }
61:
62: /**
63: * Retrieve HTML for addresses dropdown
64: *
65: * @param $item
66: * @return string
67: */
68: public function getAddressesHtmlSelect($item, $index)
69: {
70: $select = $this->getLayout()->createBlock('core/html_select')
71: ->setName('ship['.$index.']['.$item->getQuoteItemId().'][address]')
72: ->setId('ship_'.$index.'_'.$item->getQuoteItemId().'_address')
73: ->setValue($item->getCustomerAddressId())
74: ->setOptions($this->getAddressOptions());
75:
76: return $select->getHtml();
77: }
78:
79: /**
80: * Retrieve options for addresses dropdown
81: *
82: * @return array
83: */
84: public function getAddressOptions()
85: {
86: $options = $this->getData('address_options');
87: if (is_null($options)) {
88: $options = array();
89: foreach ($this->getCustomer()->getAddresses() as $address) {
90: $options[] = array(
91: 'value' => $address->getId(),
92: 'label' => $address->format('oneline')
93: );
94: }
95: $this->setData('address_options', $options);
96: }
97:
98: return $options;
99: }
100:
101: public function getCustomer()
102: {
103: return $this->getCheckout()->getCustomerSession()->getCustomer();
104: }
105:
106: public function getItemUrl($item)
107: {
108: return $this->getUrl('catalog/product/view/id/'.$item->getProductId());
109: }
110:
111: public function getItemDeleteUrl($item)
112: {
113: return $this->getUrl('*/*/removeItem', array('address'=>$item->getQuoteAddressId(), 'id'=>$item->getId()));
114: }
115:
116: public function getPostActionUrl()
117: {
118: return $this->getUrl('*/*/addressesPost');
119: }
120:
121: public function getNewAddressUrl()
122: {
123: return Mage::getUrl('*/multishipping_address/newShipping');
124: }
125:
126: public function getBackUrl()
127: {
128: return Mage::getUrl('*/cart/');
129: }
130:
131: public function isContinueDisabled()
132: {
133: return !$this->getCheckout()->validateMinimumAmount();
134: }
135: }
136: