Definition at line 35 of file Address.php.
__clone | ( | ) |
Rewrite clone method
Definition at line 718 of file Address.php.
00719 { 00720 $this->setId(null); 00721 }
_afterSave | ( | ) | [protected] |
Save child collections
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 110 of file Address.php.
00111 { 00112 parent::_afterSave(); 00113 if (null !== $this->_items) { 00114 $this->getItemsCollection()->save(); 00115 } 00116 if (null !== $this->_rates) { 00117 $this->getShippingRatesCollection()->save(); 00118 } 00119 return $this; 00120 }
_beforeSave | ( | ) | [protected] |
Initialize quote identifier before save
Reimplemented from Mage_Customer_Model_Address_Abstract.
Definition at line 90 of file Address.php.
00091 { 00092 parent::_beforeSave(); 00093 if ($this->getQuote()) { 00094 $quoteId = $this->getQuote()->getId(); 00095 if ($quoteId) { 00096 $this->setQuoteId($quoteId); 00097 } 00098 else { 00099 $this->_dataSaveAllowed = false; 00100 } 00101 } 00102 return $this; 00103 }
_construct | ( | ) | [protected] |
Initialize resource
Reimplemented from Varien_Object.
Definition at line 80 of file Address.php.
00081 { 00082 $this->_init('sales/quote_address'); 00083 }
_sortRates | ( | $ | a, | |
$ | b | |||
) | [protected] |
Sort rates recursive callback
array | $a | |
array | $b |
Definition at line 484 of file Address.php.
00485 { 00486 if ((int)$a[0]->carrier_sort_order < (int)$b[0]->carrier_sort_order) { 00487 return -1; 00488 } 00489 elseif ((int)$a[0]->carrier_sort_order > (int)$b[0]->carrier_sort_order) { 00490 return 1; 00491 } 00492 else { 00493 return 0; 00494 } 00495 }
addItem | ( | Mage_Sales_Model_Quote_Item_Abstract $ | item, | |
$ | qty = null | |||
) |
Add item to address
Mage_Sales_Model_Quote_Item_Abstract | $item | |
int | $qty |
Definition at line 385 of file Address.php.
00386 { 00387 if ($item instanceof Mage_Sales_Model_Quote_Item) { 00388 if ($item->getParentItemId()) { 00389 return $this; 00390 } 00391 $addressItem = Mage::getModel('sales/quote_address_item') 00392 ->setAddress($this) 00393 ->importQuoteItem($item); 00394 $this->getItemsCollection()->addItem($addressItem); 00395 00396 if ($item->getHasChildren()) { 00397 foreach ($item->getChildren() as $child) { 00398 $addressChildItem = Mage::getModel('sales/quote_address_item') 00399 ->setAddress($this) 00400 ->importQuoteItem($child) 00401 ->setParentItem($addressItem); 00402 $this->getItemsCollection()->addItem($addressChildItem); 00403 } 00404 } 00405 } 00406 else { 00407 $addressItem = $item; 00408 $addressItem->setAddress($this); 00409 if (!$addressItem->getId()) { 00410 $this->getItemsCollection()->addItem($addressItem); 00411 } 00412 } 00413 00414 if ($qty) { 00415 $addressItem->setQty($qty); 00416 } 00417 return $this; 00418 }
addShippingRate | ( | Mage_Sales_Model_Quote_Address_Rate $ | rate | ) |
Add shipping rate
Mage_Sales_Model_Quote_Address_Rate | $rate |
Definition at line 548 of file Address.php.
00549 { 00550 $rate->setAddress($this); 00551 $this->getShippingRatesCollection()->addItem($rate); 00552 return $this; 00553 }
addTotal | ( | $ | total | ) |
Add total data or model
Mage_Sales_Model_Quote_Total|array | $total |
Definition at line 701 of file Address.php.
00702 { 00703 if (is_array($total)) { 00704 $totalInstance = Mage::getModel('sales/quote_address_total') 00705 ->setData($total); 00706 } elseif ($total instanceof Mage_Sales_Model_Quote_Total) { 00707 $totalInstance = $total; 00708 } 00709 $this->_totals[$totalInstance->getCode()] = $totalInstance; 00710 return $this; 00711 }
collectShippingRates | ( | ) |
Collecting shipping rates by address
need to call getStreet with -1 to get data in string instead of array
Store and website identifiers need specify from quote
Currencies need to convert in free shipping
Definition at line 560 of file Address.php.
00561 { 00562 if (!$this->getCollectShippingRates()) { 00563 return $this; 00564 } 00565 00566 $this->setCollectShippingRates(false); 00567 00568 $this->removeAllShippingRates(); 00569 00570 if (!$this->getCountryId() && !$this->getPostcode()) { 00571 return $this; 00572 } 00573 00574 $request = Mage::getModel('shipping/rate_request'); 00575 $request->setAllItems($this->getAllItems()); 00576 $request->setDestCountryId($this->getCountryId()); 00577 $request->setDestRegionId($this->getRegionId()); 00578 $request->setDestRegionCode($this->getRegionCode()); 00579 /** 00580 * need to call getStreet with -1 00581 * to get data in string instead of array 00582 */ 00583 $request->setDestStreet($this->getStreet(-1)); 00584 $request->setDestCity($this->getCity()); 00585 $request->setDestPostcode($this->getPostcode()); 00586 $request->setPackageValue($this->getBaseSubtotal()); 00587 $request->setPackageValueWithDiscount($this->getBaseSubtotalWithDiscount()); 00588 $request->setPackageWeight($this->getWeight()); 00589 $request->setPackageQty($this->getItemQty()); 00590 00591 $request->setFreeMethodWeight($this->getFreeMethodWeight()); 00592 00593 /** 00594 * Store and website identifiers need specify from quote 00595 */ 00596 /*$request->setStoreId(Mage::app()->getStore()->getId()); 00597 $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ 00598 00599 $request->setStoreId($this->getQuote()->getStore()->getId()); 00600 $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); 00601 $request->setFreeShipping($this->getFreeShipping()); 00602 /** 00603 * Currencies need to convert in free shipping 00604 */ 00605 $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); 00606 $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); 00607 $request->setLimitCarrier($this->getLimitCarrier()); 00608 00609 $result = Mage::getModel('shipping/shipping') 00610 ->collectRates($request) 00611 ->getResult(); 00612 00613 $found = false; 00614 if ($result) { 00615 $shippingRates = $result->getAllRates(); 00616 00617 foreach ($shippingRates as $shippingRate) { 00618 $rate = Mage::getModel('sales/quote_address_rate') 00619 ->importShippingRate($shippingRate); 00620 $this->addShippingRate($rate); 00621 00622 if ($this->getShippingMethod()==$rate->getCode()) { 00623 $this->setShippingAmount($rate->getPrice()); 00624 $found = true; 00625 } 00626 } 00627 } 00628 00629 if (!$found) { 00630 $this->setShippingAmount(0) 00631 ->setBaseShippingAmount(0) 00632 ->setShippingMethod('') 00633 ->setShippingDescription(''); 00634 } 00635 00636 return $this; 00637 }
collectTotals | ( | ) |
Collect address totals
Definition at line 670 of file Address.php.
00671 { 00672 foreach ($this->getTotalModels() as $model) { 00673 if (is_callable(array($model, 'collect'))) { 00674 $model->collect($this); 00675 } 00676 } 00677 return $this; 00678 }
exportCustomerAddress | ( | ) |
Export data to customer address object
Definition at line 163 of file Address.php.
00164 { 00165 $address = Mage::getModel('customer/address'); 00166 Mage::helper('core')->copyFieldset('sales_convert_quote_address', 'to_customer_address', $this, $address); 00167 return $address; 00168 }
getAllItems | ( | ) |
Get all available address items
For virtual quote we assign all items to billing address
Definition at line 230 of file Address.php.
00231 { 00232 $quoteItems = $this->getQuote()->getItemsCollection(); 00233 $addressItems = $this->getItemsCollection(); 00234 00235 $items = array(); 00236 if ($this->getQuote()->getIsMultiShipping() && $addressItems->count() > 0) { 00237 foreach ($addressItems as $aItem) { 00238 if ($aItem->isDeleted()) { 00239 continue; 00240 } 00241 00242 if (!$aItem->getQuoteItemImported()) { 00243 if ($qItem = $this->getQuote()->getItemById($aItem->getQuoteItemId())) { 00244 $this->addItem($aItem); 00245 $aItem->importQuoteItem($qItem); 00246 } 00247 } 00248 $items[] = $aItem; 00249 } 00250 } else { 00251 $isQuoteVirtual = $this->getQuote()->isVirtual(); 00252 foreach ($quoteItems as $qItem) { 00253 if ($qItem->isDeleted()) { 00254 continue; 00255 } 00256 // if ($this->getAddressType() == self::TYPE_BILLING && $qItem->getProduct()->getIsVirtual()) { 00257 // $items[] = $qItem; 00258 // } 00259 // elseif ($this->getAddressType() == self::TYPE_SHIPPING && !$qItem->getProduct()->getIsVirtual()) { 00260 // $items[] = $qItem; 00261 // } 00262 /** 00263 * For virtual quote we assign all items to billing address 00264 */ 00265 if ($isQuoteVirtual) { 00266 if ($this->getAddressType() == self::TYPE_BILLING) { 00267 $items[] = $qItem; 00268 } 00269 } 00270 else { 00271 if ($this->getAddressType() == self::TYPE_SHIPPING) { 00272 $items[] = $qItem; 00273 } 00274 } 00275 } 00276 } 00277 00278 return $items; 00279 }
getAllShippingRates | ( | ) |
Retrieve all address shipping rates
Definition at line 444 of file Address.php.
00445 { 00446 $rates = array(); 00447 foreach ($this->getShippingRatesCollection() as $rate) { 00448 if (!$rate->isDeleted()) { 00449 $rates[] = $rate; 00450 } 00451 } 00452 return $rates; 00453 }
getAllVisibleItems | ( | ) |
Retrieve all visible items
Definition at line 286 of file Address.php.
00287 { 00288 $items = array(); 00289 foreach ($this->getAllItems() as $item) { 00290 if (!$item->getParentItemId()) { 00291 $items[] = $item; 00292 } 00293 } 00294 return $items; 00295 }
getAppliedTaxes | ( | ) |
Retrieve applied taxes
Definition at line 754 of file Address.php.
00755 { 00756 return unserialize($this->getData('applied_taxes')); 00757 }
getGroupedAllShippingRates | ( | ) |
Retrieve all grouped shipping rates
Definition at line 460 of file Address.php.
00461 { 00462 $rates = array(); 00463 foreach ($this->getShippingRatesCollection() as $rate) { 00464 if (!$rate->isDeleted() && $rate->getCarrierInstance()) { 00465 if (!isset($rates[$rate->getCarrier()])) { 00466 $rates[$rate->getCarrier()] = array(); 00467 } 00468 00469 $rates[$rate->getCarrier()][] = $rate; 00470 $rates[$rate->getCarrier()][0]->carrier_sort_order = $rate->getCarrierInstance()->getSortOrder(); 00471 } 00472 } 00473 uasort($rates, array($this, '_sortRates')); 00474 return $rates; 00475 }
getItemById | ( | $ | itemId | ) |
Retrieve Item object by id
int | $itemId |
Definition at line 338 of file Address.php.
00339 { 00340 foreach ($this->getItemsCollection() as $item) { 00341 if ($item->getId()==$itemId) { 00342 return $item; 00343 } 00344 } 00345 return false; 00346 }
getItemByQuoteItemId | ( | $ | itemId | ) |
Retrieve item object by quote item Id
int | $itemId |
Definition at line 354 of file Address.php.
00355 { 00356 foreach ($this->getItemsCollection() as $item) { 00357 if ($item->getQuoteItemId()==$itemId) { 00358 return $item; 00359 } 00360 } 00361 return false; 00362 }
getItemQty | ( | $ | itemId = 0 |
) |
Retrieve item quantity by id
int | $itemId |
Definition at line 303 of file Address.php.
00304 { 00305 if ($this->hasData('item_qty')) { 00306 return $this->getData('item_qty'); 00307 } 00308 00309 $qty = 0; 00310 if ($itemId == 0) { 00311 foreach ($this->getAllItems() as $item) { 00312 $qty += $item->getQty(); 00313 } 00314 } else { 00315 if ($item = $this->getItemById($itemId)) { 00316 $qty = $item->getQty(); 00317 } 00318 } 00319 return $qty; 00320 }
getItemsCollection | ( | ) |
Retrieve address items collection
Definition at line 210 of file Address.php.
00211 { 00212 if (is_null($this->_items)) { 00213 $this->_items = Mage::getModel('sales/quote_address_item')->getCollection() 00214 ->setAddressFilter($this->getId()); 00215 00216 if ($this->getId()) { 00217 foreach ($this->_items as $item) { 00218 $item->setAddress($this); 00219 } 00220 } 00221 } 00222 return $this->_items; 00223 }
getQuote | ( | ) |
getShippingRateByCode | ( | $ | code | ) |
Retrieve shipping rate by code
string | $code |
Definition at line 519 of file Address.php.
00520 { 00521 foreach ($this->getShippingRatesCollection() as $rate) { 00522 if ($rate->getCode()==$code) { 00523 return $rate; 00524 } 00525 } 00526 return false; 00527 }
getShippingRateById | ( | $ | rateId | ) |
Retrieve shipping rate by identifier
int | $rateId |
Definition at line 503 of file Address.php.
00504 { 00505 foreach ($this->getShippingRatesCollection() as $rate) { 00506 if ($rate->getId()==$rateId) { 00507 return $rate; 00508 } 00509 } 00510 return false; 00511 }
getShippingRatesCollection | ( | ) |
Retrieve collection of quote shipping rates
Definition at line 425 of file Address.php.
00426 { 00427 if (is_null($this->_rates)) { 00428 $this->_rates = Mage::getModel('sales/quote_address_rate')->getCollection() 00429 ->setAddressFilter($this->getId()); 00430 if ($this->getId()) { 00431 foreach ($this->_rates as $rate) { 00432 $rate->setAddress($this); 00433 } 00434 } 00435 } 00436 return $this->_rates; 00437 }
getTotalModels | ( | ) |
Retrieve total models
Definition at line 644 of file Address.php.
00645 { 00646 if (!$this->_totalModels) { 00647 $totalsConfig = Mage::getConfig()->getNode('global/sales/quote/totals'); 00648 $models = array(); 00649 foreach ($totalsConfig->children() as $totalCode=>$totalConfig) { 00650 $sort = Mage::getStoreConfig('sales/totals_sort/'.$totalCode); 00651 while (isset($models[$sort])) { 00652 $sort++; 00653 } 00654 $class = $totalConfig->getClassName(); 00655 if ($class && ($model = Mage::getModel($class))) { 00656 $models[$sort] = $model->setCode($totalCode); 00657 } 00658 } 00659 ksort($models); 00660 $this->_totalModels = $models; 00661 } 00662 return $this->_totalModels; 00663 }
getTotals | ( | ) |
Retrieve totals as array
Definition at line 685 of file Address.php.
00686 { 00687 foreach ($this->getTotalModels() as $model) { 00688 if (is_callable(array($model, 'fetch'))) { 00689 $model->fetch($this); 00690 } 00691 } 00692 return $this->_totals; 00693 }
hasItems | ( | ) |
Check Quote address has Items
Definition at line 327 of file Address.php.
00328 { 00329 return sizeof($this->getAllItems())>0; 00330 }
importCustomerAddress | ( | Mage_Customer_Model_Address $ | address | ) |
Import quote address data from customer address object
Mage_Customer_Model_Address | $address |
Definition at line 151 of file Address.php.
00152 { 00153 Mage::helper('core')->copyFieldset('customer_address', 'to_quote_address', $address, $this); 00154 $this->setEmail($address->hasEmail() ? $address->getEmail() : $address->getCustomer()->getEmail()); 00155 return $this; 00156 }
importOrderAddress | ( | Mage_Sales_Model_Order_Address $ | address | ) |
Import address data from order address
Mage_Sales_Model_Order_Address | $address |
Definition at line 176 of file Address.php.
00177 { 00178 $this->setAddressType($address->getAddressType()) 00179 ->setCustomerId($address->getCustomerId()) 00180 ->setCustomerAddressId($address->getCustomerAddressId()) 00181 ->setEmail($address->getEmail()); 00182 00183 Mage::helper('core')->copyFieldset('sales_convert_order_address', 'to_quote_address', $address, $this); 00184 00185 return $this; 00186 }
removeAllShippingRates | ( | ) |
Mark all shipping rates as deleted
Definition at line 534 of file Address.php.
00535 { 00536 foreach ($this->getShippingRatesCollection() as $rate) { 00537 $rate->isDeleted(true); 00538 } 00539 return $this; 00540 }
removeItem | ( | $ | itemId | ) |
Remove item from collection
int | $itemId |
Definition at line 370 of file Address.php.
00371 { 00372 if ($item = $this->getItemById($itemId)) { 00373 $item->isDeleted(true); 00374 } 00375 return $this; 00376 }
setAppliedTaxes | ( | $ | data | ) |
Set applied taxes
array | $data |
Definition at line 765 of file Address.php.
setBaseShippingAmount | ( | $ | value, | |
$ | alreadyExclTax = false | |||
) |
Set base shipping amount
float | $value | |
bool | $alreadyExclTax |
Definition at line 796 of file Address.php.
00797 { 00798 if (Mage::helper('tax')->shippingPriceIncludesTax()) { 00799 $includingTax = Mage::helper('tax')->getShippingPrice($value, true, $this, $this->getQuote()->getCustomerTaxClassId()); 00800 if (!$alreadyExclTax) { 00801 $value = Mage::helper('tax')->getShippingPrice($value, false, $this, $this->getQuote()->getCustomerTaxClassId()); 00802 } 00803 $this->setBaseShippingTaxAmount($includingTax - $value); 00804 } 00805 return $this->setData('base_shipping_amount', $value); 00806 }
setQuote | ( | Mage_Sales_Model_Quote $ | quote | ) |
Declare adress quote model object
Mage_Sales_Model_Quote | $quote |
Definition at line 128 of file Address.php.
00129 { 00130 $this->_quote = $quote; 00131 $this->setQuoteId($quote->getId()); 00132 return $this; 00133 }
setShippingAmount | ( | $ | value, | |
$ | alreadyExclTax = false | |||
) |
Set shipping amount
float | $value | |
bool | $alreadyExclTax |
Definition at line 777 of file Address.php.
00778 { 00779 if (Mage::helper('tax')->shippingPriceIncludesTax()) { 00780 $includingTax = Mage::helper('tax')->getShippingPrice($value, true, $this, $this->getQuote()->getCustomerTaxClassId()); 00781 if (!$alreadyExclTax) { 00782 $value = Mage::helper('tax')->getShippingPrice($value, false, $this, $this->getQuote()->getCustomerTaxClassId()); 00783 } 00784 $this->setShippingTaxAmount($includingTax - $value); 00785 } 00786 return $this->setData('shipping_amount', $value); 00787 }
Convert object to array
array | $arrAttributes |
Reimplemented from Varien_Object.
Definition at line 194 of file Address.php.
00195 { 00196 $arr = parent::toArray(); 00197 $arr['rates'] = $this->getShippingRatesCollection()->toArray($arrAttributes); 00198 $arr['items'] = $this->getItemsCollection()->toArray($arrAttributes); 00199 foreach ($this->getTotals() as $k=>$total) { 00200 $arr['totals'][$k] = $total->toArray(); 00201 } 00202 return $arr; 00203 }
validateMinimumAmount | ( | ) |
Validate minimum amount
Definition at line 728 of file Address.php.
00729 { 00730 $storeId = $this->getQuote()->getStoreId(); 00731 if (!Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId)) { 00732 return true; 00733 } 00734 00735 if ($this->getQuote()->getIsVirtual() && $this->getAddressType() == self::TYPE_SHIPPING) { 00736 return true; 00737 } 00738 elseif (!$this->getQuote()->getIsVirtual() && $this->getAddressType() != self::TYPE_SHIPPING) { 00739 return true; 00740 } 00741 00742 $amount = Mage::getStoreConfig('sales/minimum_order/amount', $storeId); 00743 if ($this->getBaseSubtotalWithDiscount() < $amount) { 00744 return false; 00745 } 00746 return true; 00747 }
$_items = null [protected] |
Definition at line 47 of file Address.php.
$_quote = null [protected] |
Definition at line 54 of file Address.php.
$_rates = null [protected] |
Definition at line 61 of file Address.php.
$_totalModels [protected] |
Definition at line 68 of file Address.php.
$_totals = array() [protected] |
Definition at line 75 of file Address.php.
const RATES_FETCH = 1 |
Definition at line 39 of file Address.php.
const RATES_RECALCULATE = 2 |
Definition at line 40 of file Address.php.
const TYPE_BILLING = 'billing' |
Definition at line 37 of file Address.php.
const TYPE_SHIPPING = 'shipping' |
Definition at line 38 of file Address.php.