00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Checkout_Block_Cart_Item_Renderer extends Mage_Core_Block_Template
00035 {
00036 protected $_item;
00037 protected $_productUrl = null;
00038 protected $_productThumbnail = null;
00039
00040
00041
00042
00043
00044
00045
00046 public function setItem(Mage_Sales_Model_Quote_Item_Abstract $item)
00047 {
00048 $this->_item = $item;
00049 return $this;
00050 }
00051
00052
00053
00054
00055
00056
00057 public function getItem()
00058 {
00059 return $this->_item;
00060 }
00061
00062
00063
00064
00065
00066
00067 public function getProduct()
00068 {
00069 return $this->getItem()->getProduct();
00070 }
00071
00072 public function overrideProductThumbnail($productThumbnail)
00073 {
00074 $this->_productThumbnail = $productThumbnail;
00075 return $this;
00076 }
00077
00078
00079
00080
00081
00082
00083 public function getProductThumbnail()
00084 {
00085 if (!is_null($this->_productThumbnail)) {
00086 return $this->_productThumbnail;
00087 }
00088 return $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail');
00089 }
00090
00091 public function overrideProductUrl($productUrl)
00092 {
00093 $this->_productUrl = $productUrl;
00094 return $this;
00095 }
00096
00097
00098
00099
00100
00101
00102 public function getProductUrl()
00103 {
00104 if (!is_null($this->_productUrl)) {
00105 return $this->_productUrl;
00106 }
00107 return $this->getProduct()->getProductUrl();
00108 }
00109
00110
00111
00112
00113
00114
00115 public function getProductName()
00116 {
00117 return $this->getProduct()->getName();
00118 }
00119
00120
00121
00122
00123
00124
00125 public function getProductOptions()
00126 {
00127 $options = array();
00128 if ($optionIds = $this->getItem()->getOptionByCode('option_ids')) {
00129 $options = array();
00130 foreach (explode(',', $optionIds->getValue()) as $optionId) {
00131 if ($option = $this->getProduct()->getOptionById($optionId)) {
00132
00133 $quoteItemOption = $this->getItem()->getOptionByCode('option_' . $option->getId());
00134
00135 $group = $option->groupFactory($option->getType())
00136 ->setOption($option)
00137 ->setQuoteItemOption($quoteItemOption);
00138
00139 $options[] = array(
00140 'label' => $option->getTitle(),
00141 'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
00142 'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
00143 'option_id' => $option->getId(),
00144 'option_type' => $option->getType(),
00145 'custom_view' => $group->isCustomizedView()
00146 );
00147 }
00148 }
00149 }
00150 if ($addOptions = $this->getItem()->getOptionByCode('additional_options')) {
00151 $options = array_merge($options, unserialize($addOptions->getValue()));
00152 }
00153 return $options;
00154 }
00155
00156
00157
00158
00159
00160
00161 public function getOptionList()
00162 {
00163 return $this->getProductOptions();
00164 }
00165
00166
00167
00168
00169
00170
00171 public function getDeleteUrl()
00172 {
00173 return $this->getUrl(
00174 'checkout/cart/delete',
00175 array(
00176 'id'=>$this->getItem()->getId(),
00177 Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl()
00178 )
00179 );
00180 }
00181
00182
00183
00184
00185
00186
00187 public function getQty()
00188 {
00189 return $this->getItem()->getQty()*1;
00190 }
00191
00192
00193
00194
00195
00196
00197 public function getIsInStock()
00198 {
00199 if ($this->getItem()->getProduct()->isSaleable()) {
00200 if ($this->getItem()->getProduct()->getQty()>=$this->getItem()->getQty()) {
00201 return true;
00202 }
00203 }
00204 return false;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 public function getMessages()
00217 {
00218 $messages = array();
00219 if ($this->getItem()->getMessage(false)) {
00220 foreach ($this->getItem()->getMessage(false) as $message) {
00221 $messages[] = array(
00222 'text' => $message,
00223 'type' => $this->getItem()->getHasError() ? 'error' : 'notice'
00224 );
00225 }
00226 }
00227 return array_unique($messages);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 public function getFormatedOptionValue($optionValue)
00251 {
00252 $optionInfo = array();
00253
00254
00255 if (is_array($optionValue)) {
00256 if (isset($optionValue['option_id'])) {
00257 $optionInfo = $optionValue;
00258 if (isset($optionInfo['value'])) {
00259 $optionValue = $optionInfo['value'];
00260 }
00261 } elseif (isset($optionValue['value'])) {
00262 $optionValue = $optionValue['value'];
00263 }
00264 }
00265
00266
00267 if (isset($optionInfo['custom_view']) && $optionInfo['custom_view']) {
00268 $_default = array('value' => $optionValue);
00269 if (isset($optionInfo['option_type'])) {
00270 try {
00271 $group = Mage::getModel('catalog/product_option')->groupFactory($optionInfo['option_type']);
00272 return array('value' => $group->getCustomizedView($optionInfo));
00273 } catch (Exception $e) {
00274 return $_default;
00275 }
00276 }
00277 return $_default;
00278 }
00279
00280
00281 $result = array();
00282 if (is_array($optionValue)) {
00283 $_truncatedValue = implode("\n", $optionValue);
00284 $_truncatedValue = nl2br($_truncatedValue);
00285 return array('value' => $_truncatedValue);
00286 } else {
00287 $_truncatedValue = Mage::helper('core/string')->truncate($optionValue, 55, '');
00288 $_truncatedValue = nl2br($_truncatedValue);
00289 }
00290
00291 $result = array('value' => $_truncatedValue);
00292
00293 if (Mage::helper('core/string')->strlen($optionValue) > 55) {
00294 $result['value'] = $result['value'] . ' <a href="#" class="dots" onclick="return false">...</a>';
00295 $optionValue = nl2br($optionValue);
00296 $result = array_merge($result, array('full_view' => $optionValue));
00297 }
00298
00299 return $result;
00300 }
00301 }