/** * Assemble recalculate item event * * @param \XLite\Model\OrderItem $item Order item * * @return array */ protected function assembleRecalculateItemEvent(\XLite\Model\OrderItem $item) { $data = parent::assembleRecalculateItemEvent($item); if ($item->getVariant()) { $data['sku'] = $item->getVariant()->getSku() ? $item->getVariant()->getSku() : null; } return $data; }
/** * Get pages templates * * @return array */ protected function getPageTemplates() { $list = parent::getPageTemplates(); if ($this->getOrder()->getShippingProcessor() instanceof \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes) { $list['parcels'] = 'modules/XC/PitneyBowes/asn/body.tpl'; } return $list; }
/** * Get pages templates * * @return array */ protected function getPageTemplates() { $list = parent::getPageTemplates(); if ($this->getAuctionIncPackage()) { $list += array('auctionIncPackage' => 'modules/XC/AuctionInc/order/package.tpl'); } return $list; }
/** * Remove temporary order * * @param \XLite\Model\Order $order Order * * @return void */ protected function removeTemporaryOrder(\XLite\Model\Order $order) { foreach ($order->getItems() as $item) { foreach ($item->getPinCodes() as $pin) { \XLite\Core\Database::getEM()->remove($pin); } } parent::removeTemporaryOrder($order); }
/** * Postprocess inserted entity * * @param \XLite\Model\OrderItem $entity OrderItem entity * @param array $line Array of entity data from request * * @return boolean */ protected function postprocessInsertedEntity(\XLite\Model\AEntity $entity, array $line) { $result = parent::postprocessInsertedEntity($entity, $line); if ($result && \XLite\Controller\Admin\Order::isNeedProcessStock()) { // Process PIN codes on order save $order = $this->getOrder(); if ($order->isProcessed()) { $order->processPINCodes(); } } return $result; }
/** * Postprocess inserted entity * * @param \XLite\Model\OrderItem $entity OrderItem entity * @param array $line Array of entity data from request * * @return boolean */ protected function postprocessInsertedEntity(\XLite\Model\AEntity $entity, array $line) { $result = parent::postprocessInsertedEntity($entity, $line); if ($result && \XLite\Controller\Admin\Order::isNeedProcessStock()) { // Create private attachments $entity->createPrivateAttachments(); // Renew private attachments foreach ($entity->getPrivateAttachments() as $attachment) { $attachment->renew(); } } return $result; }
/** * Save widget value in entity * * @param array $field Field data * * @return void */ public function saveValueShippingId($field) { $shippingId = $field['widget']->getValue(); if ($shippingId !== \XLite\View\FormField\Select\ShipMethod::KEY_DELETED && $shippingId !== \XLite\View\FormField\Select\ShipMethod::KEY_UNAVAILABLE) { $shippingId = (int) $shippingId; $shippingMethod = $shippingId ? \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->find($shippingId) : null; if ((int) $this->getEntity()->getShippingId() !== $shippingId) { $newName = $shippingMethod ? $shippingMethod->getName() : 'None'; $oldName = $this->getEntity()->getShippingMethodName(); \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME), sprintf('%s (id: %d)', $newName, $shippingId), sprintf('%s (id: %d)', $oldName, $this->getEntity()->getShippingId())); } $this->getEntity()->setShippingId($shippingId); $this->getEntity()->setShippingMethodName($shippingMethod ? $shippingMethod->getName() : null); } }
/** * Save widget value in entity * * @param array $field Field data * * @return void */ public function saveValuePaymentMethod($field) { $paymentId = $field['widget']->getValue(); $serviceCodes = array(\XLite\View\FormField\Select\PaymentMethod::KEY_DELETED, \XLite\View\FormField\Select\PaymentMethod::KEY_NONE); if (!in_array($paymentId, $serviceCodes)) { $entity = $this->getEntity(); $oldMethodId = $entity->getPaymentMethod() ? $entity->getPaymentMethod()->getMethodId() : null; $oldValue = sprintf('%s (id: %d)', $entity->getPaymentMethod() ? $entity->getPaymentMethod()->getName() : static::t('None'), $entity->getPaymentMethod() ? $oldMethodId : 'n/a'); if (!$entity->isPersistent()) { $entity->setOrder($this->getOrder()); $this->getOrder()->addPaymentTransactions($entity); } $paymentMethod = $this->preprocessValueBeforeSave($paymentId); $entity->setPaymentMethod($paymentMethod); if ($entity->getPaymentMethod() && $entity->getPaymentMethod()->getMethodId() != $oldMethodId) { \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME), sprintf('%s (id: %d)', $entity->getPaymentMethod() ? $entity->getPaymentMethod()->getName() : 'n/a', $entity->getPaymentMethod() ? $entity->getPaymentMethod()->getMethodId() : 'n/a'), $oldValue); } } }
/** * Get current order entity * * @return \XLite\Model\Order */ protected function getOrderEntity() { $order = $this->getOrder(); return \XLite\Controller\Admin\Order::getTemporaryOrder($order->getOrderId(), false) ?: $order; }
/** * Remove entity * * @param \XLite\Model\AEntity $entity Entity * * @return boolean */ protected function removeEntity(\XLite\Model\AEntity $entity) { $product = $entity->getProduct(); if ($this->isNeedUpdateStock() && !$entity->isDeleted()) { // Return items to stock $entity->changeAmount($entity->getAmount()); } $attributes = $this->getAttributeValuesAsString($entity); \XLite\Controller\Admin\Order::setOrderChanges('Removed items:' . $entity->getItemId(), sprintf('[%s] %s (%s x %d%s)', $product->getSku(), $product->getName(), static::formatPrice($entity->getPrice(), $entity->getOrder()->getCurrency(), true), $entity->getAmount(), $attributes ? ', ' . $attributes : '')); return parent::removeEntity($entity); }
/** * Get pages templates * * @return array */ protected function getPageTemplates() { $list = parent::getPageTemplates(); if ($this->getOrder() && $this->getOrder()->isCapostShippingMethod()) { $list[static::PAGE_CAPOST_SHIPMENTS] = 'modules/XC/CanadaPost/shipments/page.tpl'; } return $list; }
/** * Return model object to use: temporary * * @return \XLite\Model\Order */ public function getModelObject() { $object = parent::getModelObject(); if ('recalculate' === $this->currentAction) { // Get temporary order (force to create this) $object = \XLite\Controller\Admin\Order::getTemporaryOrder($object->getOrderId(), true); } else { // Get temporary order if exists otherwise get current object $object = \XLite\Controller\Admin\Order::getTemporaryOrder($object->getOrderId(), false) ?: $object; } return $object; }
/** * Save field value to entity * * @param array $field Field * @param mixed $value Value * * @return void */ protected function saveFieldEntityValue(array $field, $value) { $data = \XLite\Core\Request::getInstance()->getPostData(); $currency = $this->getEntity()->getOrder()->getCurrency(); $isPersistent = $this->getEntity()->isPersistent(); if ($this->getEntity()->getModifier() && !empty($data['auto']['surcharges'][$this->getEntity()->getCode()]['value'])) { if (\XLite\Logic\Order\Modifier\Shipping::MODIFIER_CODE === $this->getEntity()->getCode()) { // Reset selected rate to avoid cache $this->getEntity()->getModifier()->resetSelectedRate(); } // Calculate surcharge and get new surcharge object or array of surcharge objects $surcharges = $this->getEntity()->getModifier()->canApply() ? $this->getEntity()->getModifier()->calculate() : array(); if (!is_array($surcharges)) { $surcharges = $surcharges ? array($surcharges) : array(); } $value = 0; foreach ($surcharges as $surcharge) { if (is_object($surcharge)) { if ($surcharge->getCode() === $this->getEntity()->getCode()) { $value += $surcharge->getValue(); } // Remove added surcharges if current entity exists in DB to avoid duplicates if ($isPersistent) { \XLite\Core\Database::getEM()->remove($surcharge); $surcharge->getOrder()->removeSurcharge($surcharge); } } } } elseif (0 != $value && !$isPersistent) { $this->addOrderSurcharge($this->getEntity(), $value); } if (0 < $value && $this->getEntity()->getType() === \XLite\Model\Base\Surcharge::TYPE_DISCOUNT) { $value = $value * -1; } $oldValue = $currency->roundValue($this->getEntity()->getValue()); $newValue = $currency->roundValue($value); if ($oldValue !== $newValue) { \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME), static::formatPrice(abs($value), $currency, true), static::formatPrice(abs($this->getEntity()->getValue()), $currency, true)); } $this->getEntity()->setValue($value); }
/** * Add human readable name for CDEV.STAX modifier code * * @return array */ protected static function getFieldHumanReadableNames() { $result = parent::getFieldHumanReadableNames(); $code = \XLite\Module\CDev\SalesTax\Logic\Order\Modifier\Tax::getSurchargeCode(); if ($code) { $result = array_merge($result, array($code => 'Sales tax')); } return $result; }
public function handleRequest() { if (!\XLite\Core\Request::getInstance()->isPost()) { // get request return parent::handleRequest(); } $orderid = \XLite\Core\Request::getInstance()->order_id; $order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderid); if ($order) { // \XLite\Model\Cart::setObject($order); // need this? } else { \XLite\Core\TopMessage::addError("Can not find order \"{$orderid}\" in database."); return parent::handleRequest(); } $extra = array(); $_details = $order->getDetails(); if ($_details) { foreach ($_details as $_detail) { $extra[$_detail->getName()] = $_detail->getValue(); } } $errMsg = ''; $orderStatus = ''; $advinfo = array(); // post switch (\XLite\Core\Request::getInstance()->action) { case 'amz_capture': $amz_captured = false; $res = AMZ::func_amazon_pa_request('Capture', array('AmazonAuthorizationId' => $extra['amazon_pa_auth_id'], 'CaptureAmount.Amount' => $order->getTotal(), 'CaptureAmount.CurrencyCode' => \XLite\Core\Config::getInstance()->Amazon->PayWithAmazon->amazon_pa_currency, 'CaptureReferenceId' => 'capture_' . $orderid, 'SellerCaptureNote' => '')); if ($res) { $_capt_details = AMZ::func_array_path($res, 'CaptureResponse/CaptureResult/CaptureDetails/0/#'); if ($_capt_details) { $amz_capture_id = $_capt_details['AmazonCaptureId'][0]['#']; $_reply_status = $_capt_details['CaptureStatus'][0]['#']['State'][0]['#']; $amz_captured = $_reply_status == 'Completed'; $captured_total = $_capt_details['CaptureAmount'][0]['#']['Amount'][0]['#']; $advinfo[] = "AmazonCaptureId: {$amz_capture_id}"; $advinfo[] = "CaptureStatus: {$_reply_status}"; AMZ::func_amazon_pa_save_order_extra($orderid, 'amazon_pa_capture_id', $amz_capture_id); AMZ::func_amazon_pa_save_order_extra($orderid, 'amazon_pa_capture_status', $_reply_status); if ($_reply_status == 'Declined') { $orderStatus = \XLite\Model\Order\Status\Payment::STATUS_DECLINED; } $errMsg = "Status={$_reply_status}"; } else { // log error $errMsg = 'Unexpected Capture reply'; AMZ::func_amazon_pa_error('Unexpected Capture reply: ' . AMZ::func_xml_format($res)); } } if ($amz_captured) { // captured $orderStatus = \XLite\Model\Order\Status\Payment::STATUS_PAID; } if (!empty($orderStatus)) { AMZ::func_change_order_status($orderid, $orderStatus, join("\n", $advinfo)); } if ($amz_captured) { \XLite\Core\TopMessage::addInfo('Payment was captured successfully.'); } else { \XLite\Core\TopMessage::addError('Payment capture error: ' . $errMsg); } break; case 'amz_void': $amz_voided = false; $res = AMZ::func_amazon_pa_request('CloseAuthorization', array('AmazonAuthorizationId' => $extra['amazon_pa_auth_id'], 'ClosureReason' => '')); if ($res) { $amz_voided = true; } else { $errMsg = 'Void error'; } if ($amz_voided) { AMZ::func_change_order_status($orderid, \XLite\Model\Order\Status\Payment::STATUS_CANCELED); \XLite\Core\TopMessage::addInfo('Payment voided successfully'); } else { \XLite\Core\TopMessage::addError('Void error:' . $errMsg); } break; case 'amz_refund': $amz_refunded = false; $res = AMZ::func_amazon_pa_request('Refund', array('AmazonCaptureId' => $extra['amazon_pa_capture_id'], 'RefundAmount.Amount' => $order->getTotal(), 'RefundAmount.CurrencyCode' => \XLite\Core\Config::getInstance()->Amazon->PayWithAmazon->amazon_pa_currency, 'RefundReferenceId' => 'refund_' . $orderid, 'SellerRefundNote' => '')); if ($res) { $_ref_details = AMZ::func_array_path($res, 'RefundResponse/RefundResult/RefundDetails/0/#'); if ($_ref_details) { $amz_ref_id = $_ref_details['AmazonRefundId'][0]['#']; $_reply_status = $_ref_details['RefundStatus'][0]['#']['State'][0]['#']; $amz_refunded = $_reply_status == 'Completed'; $refunded_total = $_ref_details['RefundAmount'][0]['#']['Amount'][0]['#']; $advinfo[] = "AmazonRefundId: {$amz_ref_id}"; $advinfo[] = "RefundStatus: {$_reply_status}"; AMZ::func_amazon_pa_save_order_extra($orderid, 'amazon_pa_refund_id', $amz_ref_id); AMZ::func_amazon_pa_save_order_extra($orderid, 'amazon_pa_refund_status', $_reply_status); $errMsg = "Status={$_reply_status}"; } else { // log error $errMsg = 'Unexpected Refund reply'; AMZ::func_amazon_pa_error('Unexpected Refund reply: ' . AMZ::func_xml_format($res)); } } if ($amz_refunded) { // status refunded AMZ::func_change_order_status($orderid, \XLite\Model\Order\Status\Payment::STATUS_REFUNDED, join("\n", $advinfo)); \XLite\Core\TopMessage::addInfo('Payment refunded successfully'); } else { if ($_reply_status == 'Pending') { \XLite\Core\TopMessage::addInfo('Refund in progress...'); } else { \XLite\Core\TopMessage::addError('Refund error:' . $errMsg); } } break; case 'amz_refresh': $res = AMZ::func_amazon_pa_request('GetAuthorizationDetails', array('AmazonAuthorizationId' => $extra['amazon_pa_auth_id'])); $_auth_details = AMZ::func_array_path($res, 'GetAuthorizationDetailsResponse/GetAuthorizationDetailsResult/AuthorizationDetails/0/#'); if ($_auth_details) { $_reply_status = $_auth_details['AuthorizationStatus'][0]['#']['State'][0]['#']; $_reply_reason = $_auth_details['AuthorizationStatus'][0]['#']['ReasonCode'][0]['#']; $_oid = str_replace('auth_', '', $_auth_details['AuthorizationReferenceId'][0]['#']); AMZ::func_amazon_pa_save_order_extra($_oid, 'amazon_pa_auth_status', $_reply_status); $advinfo[] = "AuthorizationStatus: {$_reply_status}"; if (!empty($_reply_reason)) { $advinfo[] = "AuthorizationReason: {$_reply_reason}"; } if ($_reply_status == 'Open') { if (\XLite\Core\Config::getInstance()->Amazon->PayWithAmazon->amazon_pa_capture_mode == 'A') { // pre-authorized AMZ::func_change_order_status($_oid, \XLite\Model\Order\Status\Payment::STATUS_AUTHORIZED, join("\n", $advinfo)); } } if ($_reply_status == 'Closed') { $_a_amnt = $_auth_details['AuthorizationAmount'][0]['#']['Amount'][0]['#']; $_c_amnt = $_auth_details['CapturedAmount'][0]['#']['Amount'][0]['#']; if ($_c_amnt > 0 && $_c_amnt == $_a_amnt) { // capture now mode, funds were captured successfully, save captureID $_capt_id = $_auth_details['IdList'][0]['#']['member'][0]['#']; AMZ::func_amazon_pa_save_order_extra($_oid, 'amazon_pa_capture_id', $_capt_id); $advinfo[] = "AmazonCaptureId: {$_capt_id}"; AMZ::func_change_order_status($_oid, \XLite\Model\Order\Status\Payment::STATUS_PAID, join("\n", $advinfo)); } } if ($_reply_status == 'Declined') { // declined AMZ::func_change_order_status($_oid, \XLite\Model\Order\Status\Payment::STATUS_DECLINED, join("\n", $advinfo)); } } break; case 'amz_refresh_refund_status': $res = AMZ::func_amazon_pa_request('GetRefundDetails', array('AmazonRefundId' => $extra['amazon_pa_refund_id'])); $_ref_details = AMZ::func_array_path($res, 'GetRefundDetailsResponse/GetRefundDetailsResult/RefundDetails/0/#'); if ($_ref_details) { $amz_ref_id = $_ref_details['AmazonRefundId'][0]['#']; $_reply_status = $_ref_details['RefundStatus'][0]['#']['State'][0]['#']; $_reply_reason = $_ref_details['RefundStatus'][0]['#']['ReasonCode'][0]['#']; $_oid = str_replace('refund_', '', $_ref_details['RefundReferenceId'][0]['#']); $advinfo[] = "AmazonRefundId: {$amz_ref_id}"; $advinfo[] = "RefundStatus: {$_reply_status}"; if (!empty($_reply_reason)) { $advinfo[] = "RefundReason: {$_reply_reason}"; } AMZ::func_amazon_pa_save_order_extra($_oid, 'amazon_pa_refund_status', $_reply_status); if ($_reply_status == 'Completed') { // refunded \XLite\Core\TopMessage::addInfo('Payment refunded successfully'); AMZ::func_change_order_status($_oid, \XLite\Model\Order\Status\Payment::STATUS_REFUNDED, join("\n", $advinfo)); } } break; case 'amz_refresh_capture_status': // not used break; } // switch return parent::handleRequest(); }
/** * Get pages templates * * @return array */ protected function getPageTemplates() { $list = parent::getPageTemplates(); $list['egoods'] = 'modules/CDev/Egoods/order.tpl'; return $list; }
/** * Add human readable name for DISCOUNT modifier code * * @return array */ protected static function getFieldHumanReadableNames() { return array_merge(parent::getFieldHumanReadableNames(), array(\XLite\Module\CDev\VolumeDiscounts\Logic\Order\Modifier\Discount::MODIFIER_CODE => 'Discount')); }
/** * Save field value to entity * * @param array $field Field * @param mixed $value Value * * @return void */ protected function saveFieldEntityValue(array $field, $value) { if ($this->getEntityValue() != $value) { \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME), $value, $this->getEntityValue()); } parent::saveFieldEntityValue($field, $value); }
/** * Assemble recalculate order event: Add coupons data * * @param \XLite\Model\Order $order Order * * @return array */ protected function assembleRecalculateOrderEvent(\XLite\Model\Order $order) { $result = parent::assembleRecalculateOrderEvent($order); $coupons = array(); foreach ($order->getUsedCoupons() as $coupon) { $coupons[$coupon->getCode()] = abs($coupon->getValue()); } if ($coupons) { $result['coupons'] = $coupons; } return $result; }
/** * Save field value to entity * * @param array $field Field * @param mixed $value Value * * @return void */ protected function saveFieldEntityValue(array $field, $value) { $isPersistent = $this->getEntity()->isPersistent(); if ($this->getEntity()->getModifier()) { $surcharges = $this->getEntity()->getModifier()->calculate(); if (!is_array($surcharges)) { $surcharges = array($surcharges); } $value = 0; foreach ($surcharges as $surcharge) { if (is_object($surcharge)) { $value += $surcharge->getValue(); if ($isPersistent) { \XLite\Core\Database::getEM()->remove($surcharge); $surcharge->getOrder()->removeSurcharge($surcharge); } } } } if (0 < $value && $this->getEntity()->getType() === \XLite\Model\Base\Surcharge::TYPE_DISCOUNT) { $value = $value * -1; } $oldValue = $this->getEntity()->getOrder()->getCurrency()->roundValue($this->getEntity()->getValue()); $newValue = $this->getEntity()->getOrder()->getCurrency()->roundValue($value); if ($oldValue !== $newValue) { \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME), static::formatPrice(abs($value), $this->getEntity()->getOrder()->getCurrency(), true), static::formatPrice(abs($this->getEntity()->getValue()), $this->getEntity()->getOrder()->getCurrency(), true)); } $this->getEntity()->setValue($value); }
/** * Save field value to entity * * @param array $field Field * @param mixed $value Value * * @return void */ protected function saveFieldEntityValue(array $field, $value) { $address = $this->getAddressModel(); if ($address) { // Get property old value $getterMethod = 'get' . \XLite\Core\Converter::convertToCamelCase($field['field'][static::FIELD_NAME]); if (method_exists($address, $getterMethod)) { // Set address property via specific method $oldValue = $address->{$getterMethod}(); } else { // Set address property via common setterProperty() method $oldValue = $address->getterProperty($field['field'][static::FIELD_NAME], $value); } // Set address property $setterMethod = $this->getAddressFieldMethodName($field); if (method_exists($address, $setterMethod)) { // Set address property via specific method $address->{$setterMethod}($value); } else { // Set address property via common setterProperty() method $address->setterProperty($field['field'][static::FIELD_NAME], $value); } if ($value != $oldValue) { // Prepare data to register as an order changes $ignoreChange = false; $fieldName = $field['field'][static::FIELD_NAME]; switch ($fieldName) { case 'country_code': $fieldName = 'Country'; $oldCountry = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->findOneBy(array('code' => $oldValue)); $oldValue = $oldCountry ? $oldCountry->getCountry() : $oldValue; $newCountry = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->findOneBy(array('code' => $value)); $value = $newCountry ? $newCountry->getCountry() : $value; break; case 'state_id': if ($address->getCountry() && $address->getCountry()->hasStates()) { $fieldName = 'State'; $oldState = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($oldValue); $oldValue = $oldState ? $oldState->getState() : $oldValue; $newState = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($value); $value = $newState ? $newState->getState() : $value; } else { $ignoreChange = true; } break; case 'custom_state': if ($address->getCountry() && $address->getCountry()->hasStates()) { $ignoreChange = true; } else { $fieldName = 'State'; } break; } if (!$ignoreChange) { \XLite\Controller\Admin\Order::setOrderChanges($this->getParam(static::PARAM_FIELD_NAME) . ':' . $fieldName, $value, $oldValue); } } } }