0

enter code hereI have RMA grid on my website with RMA_ID, Order_increment_Id. An order can have multiple items, and the customer can return ordered item separately.

When Customer return ordered item separately then RMA_id increment_id but order_id repeated same. for example:

RMA_ID     Order_id
101        10000005
102        10000005
103        10000005

I want to change the order_id like this:

RMA_ID     Order_id
    101        10000005
    102        10000005-1
    103        10000005-2

If the items returned of the same order_id.

Below is my controller:

public static function save($request, $guestMode = false)
    {
        $_data = array();
        $_addNewEntityFlag = true;

        $_data['order_id'] = $request->getParam('order');
        $order = Mage::getModel('sales/order')->loadByIncrementId($_data['order_id']);

            if ($order->getId()) {
                $_data['order_id_duplicate'] = $request->getParam('order').'-1';
                //echo '<pre>'; print_r($order->getData());
                //$_data['order_id'] = $request->getParam('order');
            }
        //Checking OrderID
        //echo '<pre>'; print_r($_data['order_id']); die;

        if ($_data['order_id']) {
            //Trying to load order
            $_order = Mage::getModel('sales/order')->loadByIncrementId($_data['order_id']);
            if (!($_order->getData() == array())) {
                $customerSession = Mage::getSingleton('customer/session');
                if ($guestMode) {
                    $_guestOrderId = $customerSession->getData('awrma_guest_order');
                    $_orderIncrementId = Mage::getModel('sales/order')->load($_guestOrderId)->getIncrementId();
                    if (($_guestOrderId) && ($_orderIncrementId != $_order->getIncrementId())) {
                        $_addNewEntityFlag = false;
                        self::_getSession()->addError(
                            Mage::helper('awrma')->__('You are not authorized to request RMA for specified order')
                        );
                    }
                } else {
                    if ($_order->getCustomerId() != $customerSession->getId()) {
                        $_addNewEntityFlag = false;
                        self::_getSession()->addError(
                            Mage::helper('awrma')->__('Customer isn\'t owner of the given order')
                        );
                    }
                }
                if (!Mage::helper('awrma')->isAllowedForOrder($_order)) {
                    $_addNewEntityFlag = false;
                    self::_getSession()->addError(
                        Mage::helper('awrma')->__('You can\'t request RMA for the given order')
                    );
                }
                //Getting order items
                $_orderItems = array();
                $_orderItemsCount = $request->getParam('orderitemscount');
                foreach ($request->getParam('orderitems', array()) as $_orderItemId) {
                    if (isset($_orderItemsCount[$_orderItemId])) {
                        $_orderItems[$_orderItemId] = $_orderItemsCount[$_orderItemId];
                    }
                }

                if ($_addNewEntityFlag) {
                    if ((Mage::helper('awrma/config')->getAllowPerOrderRMA() && count($_orderItems))
                        || !Mage::helper('awrma/config')->getAllowPerOrderRMA()) {
                        //Gets order items from post if per-order item RMA is allowed
                        //and gets it directly from order otherwise
                        if (!Mage::helper('awrma/config')->getAllowPerOrderRMA()) {
                            $_hasItemsCount = false;
                            $_orderItems = array();
                            foreach ($_order->getItemsCollection() as $_item) {
                                $_itemsMaxCount = Mage::helper('awrma')->getItemMaxCount($_item);
                                if ($_itemsMaxCount > 0) {
                                    $_hasItemsCount = true;
                                }
                                $_orderItems[$_item->getId()] = $_itemsMaxCount;
                            }
                            if (!$_hasItemsCount) {
                                $_addNewEntityFlag = false;
                                self::_getSession()->addError(
                                    Mage::helper('awrma')->__('No items for request specified')
                                );
                            }
                        } else {
                            //Checking items count and order items
                            $_oifio = false;
                            foreach ($_order->getItemsCollection() as $_item) {
                                if (array_key_exists($_item->getId(), $_orderItems)) {
                                    $_count = $_orderItems[$_item->getId()];
                                    if (
                                        isset($_count)
                                        && ($_count < 1 || $_count > Mage::helper('awrma')->getItemMaxCount($_item))
                                    ) {
                                        $_addNewEntityFlag = false;
                                        self::_getSession()->addError(
                                            Mage::helper('awrma')->__('Wrong quantity for ' . $_item->getName())
                                        );
                                    }
                                }
                                if (!$_oifio && isset($_orderItems[$_item->getId()])) {
                                    $_oifio = true;
                                }
                            }
                            if (!$_oifio) {
                                $_addNewEntityFlag = false;
                                self::_getSession()->addError(
                                    Mage::helper('awrma')->__('No items for request specified')
                                );
                            }
                        }

                        if ($_addNewEntityFlag) {
                            $_data['order_items'] = $_orderItems;
                            //Checking package opened and request type values
                            $packageOpenedOption = Mage::getModel('awrma/source_packageopened')
                                ->getOption($request->getParam('packageopened'))
                            ;
                            if (!($packageOpenedOption === false)) {
                                $_data['rma_id'] = $request->getParam('rma_id');
                                $_data['package_opened'] = $request->getParam('packageopened');
                                $_data['request_type'] = $request->getParam('requesttype');
                                if (!$_data['request_type']) {
                                    $_data['request_type'] = null;
                                }

                                $_data['created_at'] = date(AW_Rma_Model_Mysql4_Entity::DATETIMEFORMAT, time());
                                $_data['status'] = Mage::helper('awrma/status')->getPendingApprovalStatusId();
                                $_data['external_link'] = Mage::helper('awrma')->getExtLink();
                                if ($guestMode) {
                                    $_data['customer_email'] = $_order->getCustomerEmail();
                                    $_data['customer_name'] = $_order->getBillingAddress()->getFirstname() . ' '
                                        . $_order->getBillingAddress()->getLastname()
                                    ;
                                } else {
                                    $_data['customer_name'] = self::_getSession()->getCustomer()->getFirstname() . ' '
                                        . self::_getSession()->getCustomer()->getLastname()
                                    ;
                                    $_data['customer_email'] = self::_getSession()->getCustomer()->getEmail();
                                    $_data['customer_id'] = self::_getSession()->getCustomer()->getId();
                                }

                                $_data['reason_id'] = $request->getParam('reason_id');
                                if ($_data['reason_id'] === '0') {
                                    $_data['reason_details'] = $request->getParam('reason_details'); 
                                }
                                if ($_data['reason_id'] === '1') {
                                    $_data['reason_detail1'] = $request->getParam('reason_detail1'); 
                                }
                                if ($_data['reason_id'] === '2') {
                                    $_data['reason_detail2'] = $request->getParam('reason_detail2'); 
                                }
                                if ($_data['reason_id'] === '5') {
                                    $_data['reason_detail3'] = $request->getParam('reason_detail3'); 
                                }
                                /* if (($_data['reason_id'] === '1') || ($_data['reason_id'] === '2') || ($_data['reason_id'] === '5')) {
                                    $_data['reason_detail1'] = $request->getParam('reason_detail1'); 
                                    foreach($_data['reason_detail1'] as $key => $val){ 
                                        if($val != ''){
                                            $_data['reason_detail1'] = $val;
                                        }
                                     }

                                } */
                                $_data['other_comment'] = $request->getParam('other_comment');

                                $rmaEntity = Mage::getModel('awrma/entity');

                                $rmaEntity->setData($_data);
                                $rmaEntity->save();

                                if ($request->getParam('additionalinfo')) {
                                    //save comment
                                    $_data['owner'] = AW_Rma_Model_Source_Owner::CUSTOMER;
                                    Mage::helper('awrma/comments')->postComment(
                                        $rmaEntity->getId(), $request->getParam('additionalinfo'), $_data, false
                                    );
                                }

                                Mage::getModel('awrma/notify')->notifyNew(
                                    $rmaEntity, $request->getParam('additionalinfo')
                                );

                                //Clear form data stored in session
                                self::_getSession()->getAWRMAFormData(true);
                                self::_getSession()->addSuccess(
                                    Mage::helper('awrma')->__('New RMA request has been successfully added')
                                );
                                self::_getSession()->addNotice(
                                    Mage::helper('awrma')->__('Your RMA is currently waiting for approval')
                                );
                                return $guestMode ? $rmaEntity->getExternalLink() : $rmaEntity->getId();
                            } else {
                                $_addNewEntityFlag = false;
                                self::_getSession()->addError(Mage::helper('awrma')->__('Wrong form data'));
                            }
                        }
                    } else {
                        $_addNewEntityFlag = false;
                        self::_getSession()->addError(Mage::helper('awrma')->__('No items for request specified'));
                    }
                }
            } else {
                $_addNewEntityFlag = false;
                self::_getSession()->addError(Mage::helper('awrma')->__('Wrong order ID'));
            }
        } else {
            $_addNewEntityFlag = false;
            self::_getSession()->addError(Mage::helper('awrma')->__('Wrong form data'));
        }

        self::_getSession()->setAWRMAFormData($request->getParams());

        return $_addNewEntityFlag;
    }

How can I achieve this?

1 Answer 1

0

Don't change the core functionality of the module.

You can hide the order_Id column and show the duplicate order_id column as you have code after the order collection.

if

($order->getId()) {
    $_data['order_id_duplicate'] = $request->getParam('order').'-1';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.