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_Adminhtml_Block_Sales_Order_Create_Items_Grid extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
00035 {
00036
00037
00038
00039
00040
00041 protected $_moveToCustomerStorage = true;
00042
00043 public function __construct()
00044 {
00045 parent::__construct();
00046 $this->setId('sales_order_create_search_grid');
00047 }
00048
00049 public function getItems()
00050 {
00051 $items = $this->getParentBlock()->getItems();
00052 foreach ($items as $item) {
00053 $stockItem = $item->getProduct()->getStockItem();
00054 $check = $stockItem->checkQuoteItemQty($item->getQty(), $item->getQty(), $item->getQty());
00055 $item->setMessage($check->getMessage());
00056 $item->setHasError($check->getHasError());
00057 if ($item->getProduct()->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
00058 $item->setMessage(Mage::helper('adminhtml')->__('This product is currently disabled'));
00059 $item->setHasError(true);
00060 }
00061 }
00062 return $items;
00063 }
00064
00065 public function getSession()
00066 {
00067 return $this->getParentBlock()->getSession();
00068 }
00069
00070 public function getItemEditablePrice($item)
00071 {
00072 return $item->getCalculationPrice()*1;
00073 }
00074
00075 public function getOriginalEditablePrice($item)
00076 {
00077 if ($item->hasOriginalCustomPrice()) {
00078 return $item->getOriginalCustomPrice()*1;
00079 } else {
00080 $result = $item->getCalculationPrice()*1;
00081 if (Mage::helper('tax')->priceIncludesTax($this->getStore()) && $item->getTaxPercent()) {
00082 $result = $result + ($result*($item->getTaxPercent()/100));
00083 }
00084 return $result;
00085 }
00086 }
00087
00088 public function getItemOrigPrice($item)
00089 {
00090
00091 return $this->convertPrice($item->getPrice());
00092 }
00093
00094 public function isGiftMessagesAvailable($item=null)
00095 {
00096 if(is_null($item)) {
00097 return $this->helper('giftmessage/message')->getIsMessagesAvailable(
00098 'items', $this->getQuote(), $this->getStore()
00099 );
00100 }
00101
00102 return $this->helper('giftmessage/message')->getIsMessagesAvailable(
00103 'item', $item, $this->getStore()
00104 );
00105 }
00106
00107 public function isAllowedForGiftMessage($item)
00108 {
00109 return Mage::getSingleton('adminhtml/giftmessage_save')->getIsAllowedQuoteItem($item);
00110 }
00111
00112 public function getSubtotal()
00113 {
00114 $totals = $this->getQuote()->getTotals();
00115 if (isset($totals['subtotal'])) {
00116 return $totals['subtotal']->getValue();
00117 }
00118 return false;
00119 }
00120
00121 public function getSubtotalWithDiscount()
00122 {
00123 return $this->getQuote()->getShippingAddress()->getSubtotalWithDiscount();
00124 }
00125
00126 public function getDiscountAmount()
00127 {
00128 return $this->getQuote()->getShippingAddress()->getDiscountAmount();
00129 }
00130
00131 public function usedCustomPriceForItem($item)
00132 {
00133 return $item->hasCustomPrice();
00134 }
00135
00136 public function getQtyTitle($item)
00137 {
00138 if ($prices = $item->getProduct()->getTierPrice()) {
00139 $info = array();
00140 foreach ($prices as $data) {
00141 $qty = $data['price_qty']*1;
00142 $price = $this->convertPrice($data['price']);
00143 $info[] = $this->helper('sales')->__('Buy %s for price %s', $qty, $price);
00144 }
00145 return implode(', ', $info);
00146 }
00147 else {
00148 return $this->helper('sales')->__('Item ordered qty');
00149 }
00150 }
00151
00152 public function getTierHtml($item)
00153 {
00154 $html = '';
00155 if ($prices = $item->getProduct()->getTierPrice()) {
00156 foreach ($prices as $data) {
00157 $qty = $data['price_qty']*1;
00158 $price = $this->convertPrice($data['price']);
00159 $info[] = $this->helper('sales')->__('%s for %s', $qty, $price);
00160 }
00161 $html = implode('<br/>', $info);
00162 }
00163 return $html;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172 public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
00173 {
00174 $optionStr = '';
00175 $this->_moveToCustomerStorage = true;
00176 if ($optionIds = $item->getOptionByCode('option_ids')) {
00177 foreach (explode(',', $optionIds->getValue()) as $optionId) {
00178 if ($option = $item->getProduct()->getOptionById($optionId)) {
00179 $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
00180
00181 $optionStr .= $option->getTitle() . ':';
00182
00183 $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
00184 $group = $option->groupFactory($option->getType())
00185 ->setOption($option)
00186 ->setQuoteItemOption($quoteItemOption);
00187
00188 $optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
00189 $optionStr .= "\n";
00190 }
00191 }
00192 }
00193 return $optionStr;
00194 }
00195
00196
00197
00198
00199
00200
00201 public function getMoveToCustomerStorage()
00202 {
00203 return $this->_moveToCustomerStorage;
00204 }
00205
00206 public function displaySubtotalInclTax($item)
00207 {
00208 $tax = ($item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0));
00209 return $this->formatPrice($item->getRowTotal()+$tax);
00210 }
00211
00212 public function displayOriginalPriceInclTax($item)
00213 {
00214 $tax = 0;
00215 if ($item->getTaxPercent()) {
00216 $tax = $item->getPrice()*($item->getTaxPercent()/100);
00217 }
00218 return $this->convertPrice($item->getPrice()+($tax/$item->getQty()));
00219 }
00220
00221 public function displayRowTotalWithDiscountInclTax($item)
00222 {
00223 $tax = ($item->getTaxAmount() ? $item->getTaxAmount() : 0);
00224 return $this->formatPrice($item->getRowTotalWithDiscount()+$tax);
00225 }
00226
00227 public function getInclExclTaxMessage()
00228 {
00229 if (Mage::helper('tax')->priceIncludesTax($this->getStore())) {
00230 return Mage::helper('sales')->__('* - Enter custom price including tax');
00231 } else {
00232 return Mage::helper('sales')->__('* - Enter custom price excluding tax');
00233 }
00234 }
00235
00236 public function getStore()
00237 {
00238 return $this->getQuote()->getStore();
00239 }
00240 }