public function invalidateCachedTotals($removeShippingMethod = true) { if ($removeShippingMethod && $this->shippingMethod !== null) { if (empty($this->shippingMethod['isCustom'])) { $this->shippingMethod = null; } $this->removeCachedShippingMethods(); } parent::invalidateCachedTotals(); }
/** * This was inside addOrder, moved out for use by editing and for split-shipping allocation * * @param int $formId one of FORMFIELD_ form-type constants * @param ISC_QUOTE_ADDRESS $quoteAddress * @return array of field=>value variables suitable for setting as template data */ public function populateQuoteAddressFormFields($formId, ISC_QUOTE_ADDRESS $quoteAddress = null) { require_once ISC_BASE_PATH . '/lib/addressvalidation.php'; if ($quoteAddress) { $quoteAddressFields = convertAddressArrayToFieldArray($quoteAddress->getAsArray()); } $countryFieldId = 0; $stateFieldId = 0; $zipFieldId = 0; $formFields = $GLOBALS['ISC_CLASS_FORM']->getFormFields($formId); foreach($formFields as $fieldId => /** @var ISC_FORMFIELD_BASE */$field) { $field->setRequired(false); $formFieldPrivateId = $field->record['formfieldprivateid']; if($formFieldPrivateId && !gzte11(ISC_MEDIUMPRINT)) { unset($fieldId); } // for display purposes, pre-populate the form field with existing quote address info if ($quoteAddress && $quoteAddressFields) { if (!$formFieldPrivateId) { $customField = $quoteAddress->getCustomField($field->record['formfieldid']); if ($customField) { $field->setValue($customField['value']); } } else if (isset($quoteAddressFields[$formFieldPrivateId])) { $field->setValue($quoteAddressFields[$formFieldPrivateId], true); } } if($formFieldPrivateId == 'Country') { $field->setRequired(true); $countryFieldId = $fieldId; } else if($formFieldPrivateId == 'State') { $stateFieldId = $fieldId; } else if ($formFieldPrivateId == 'Zip') { $zipFieldId = $fieldId; $field->setRequired(true); } $GLOBALS['ISC_CLASS_FORM']->addFormFieldUsed($field); } // This is a massive hack, and a poorly designed feature. Seriously. if($countryFieldId) { $formFields[$countryFieldId]->setOptions(array_values(GetCountryListAsIdValuePairs())); if ($formFields[$countryFieldId]->getValue() == '') { $formFields[$countryFieldId]->setValue(GetConfig('CompanyCountry')); } if ($stateFieldId) { $formFields[$countryFieldId]->addEventHandler('change', 'FormFieldEvent.SingleSelectPopulateStates', array('countryId' => $countryFieldId, 'stateId' => $stateFieldId)); $countryId = GetCountryByName($formFields[$countryFieldId]->getValue()); $stateOptions = GetStateListAsIdValuePairs($countryId); if (is_array($stateOptions) && !empty($stateOptions)) { $formFields[$stateFieldId]->setOptions($stateOptions); } else { // no states for our country, we need to mark this as not required $formFields[$stateFieldId]->setRequired(false); } if ($formFields[$stateFieldId]->getValue() == '') { $formFields[$stateFieldId]->setValue(getConfig('CompanyState')); } } } if ($zipFieldId && getConfig('CompanyZip') && $formFields[$zipFieldId]->getValue() == '') { $formFields[$zipFieldId]->setValue(getConfig('CompanyZip')); } return $formFields; }
/** * Array sorting callback method to place the 'unallocated' ISC_QUOTE_ADDRESS first as sometimes it may be created after the other addresses (e.g. when editing an order) * * @param ISC_QUOTE_ADDRESS $a * @param ISC_QUOTE_ADDRESS $b * @return int */ public static function sortUnallocatedAddressFirst(ISC_QUOTE_ADDRESS $a, ISC_QUOTE_ADDRESS $b) { if ($a->getIsUnallocated()) { return -1; } if ($b->getIsUnallocated()) { return 1; } return 0; }
/** * Moves the specified quantity of this item from it's current address to another address. * * @param ISC_QUOTE_ADDRESS $address * @param mixed $quantity * @return ISC_QUOTE_ITEM returns the instance of the item at it's new location (meaning, if the item is cloned the NEW instance is returned) */ public function moveToAddress(ISC_QUOTE_ADDRESS $address, $quantity = null) { // note: no stock levels should be checked here since we're just re-allocating quantity within the same order /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; // does the item already exists at the destination? $item = $address->getItemByHash($this->getHash()); $log->LogSystemDebug('general', 'request to move ' . $quantity . ' x item ' . $this->getName() . ' (' . $this->getId() . ') to address ' . $address->getId()); if ($address->getId() === $this->getAddressId(false)) { // item is already at destination: ignore return $this; } if ($quantity !== null) { $quantity = (int)$quantity; } if ($quantity === null || $quantity >= $this->getQuantity()) { // moving all of this item if ($item) { // already exists at destination so increment qty and remove current item $log->LogSystemDebug('general', 'adding all of item to existing item at destination'); $item->setQuantity($this->getQuantity() + $item->getQuantity(), false); $this->quote->removeItem($this->getId()); return $item; } // does not exist at destination so just move the current item there $log->LogSystemDebug('general', 'moving item to destination'); $this->setAddressId($address); return $this; } if ($quantity < 1) { // nothing to do return $this; } // moving partial qty: remove qty from current item now $this->setQuantity($this->getQuantity() - $quantity, false); // is the quantity of the the product now less than what was originally ordered? move the excess to the new item $originalOrderQuantityToMove = 0; if ($this->getQuantity() < $this->getOriginalOrderQuantity()) { $originalOrderQuantityToMove = $this->getOriginalOrderQuantity() - $this->getQuantity(); $this->setOriginalOrderQuantity($this->getQuantity()); } if ($item) { // already exists at destination so just increment that qty $log->LogSystemDebug('general', 'moving partial qty to existing item at destination'); $item->setQuantity($item->getQuantity() + $quantity, false); $item->setOriginalOrderQuantity($originalOrderQuantityToMove); return $item; } $log->LogSystemDebug('general', 'moving partial qty to new item at destination'); // does not exist at destination so create a new instance and put it there with the right qty /** @var ISC_QUOTE_ITEM */ $item = clone $this; $this->getQuote()->addItem($item, false); $item ->setAddressId($address) ->setQuantity($quantity, false) ->setOriginalOrderQuantity($originalOrderQuantityToMove); return $item; }
public function getCheckoutAddressPreview(ISC_QUOTE_ADDRESS $address) { $addressPieces = array( $address->getFirstName().' '.$address->getLastName(), $address->getCompany(), $address->getAddress1(), $address->getAddress2(), $address->getCity(), $address->getStateName(), $address->getCountryName(), $address->getZip() ); foreach($addressPieces as $k => $piece) { if(!trim($piece)) { unset($addressPieces[$k]); } } $addressString = implode(', ', $addressPieces); if(isc_strlen($addressString) > 60) { $addressString = substr($addressString, 0, 57).'...'; } return $addressString; }