programmatically save shipping/billing address

  • Posts: 73
  • Thank you received: 1
11 years 4 months ago #117741

I'm using the built in save() method located in the order.php file to save my custom order.
However I also want to include the address too. How would I go about doing that?

If I were to create an object containing all properties such as street, country etc, how would I save that and link it to the order?
This is what I'm doing now. Can I just append an address object to the order object and save it all together?

include JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/helper.php';
        include JPATH_ADMINISTRATOR . '/components/com_hikashop/classes/order.php';
        include JPATH_ADMINISTRATOR . '/components/com_hikashop/classes/user.php';
        $hikaUser = new hikashopUserClass;
        $hikaOrder = new hikashopOrderClass;
        // Update hikashop order table with this new value
        $object->order_id = $validData['orderID'];
        $object->order_user_id = $hikaUser->getID($validData['user']);
        $object->order_status = 'confirmed';
        $object->order_number = "OR" . date('y') . "-" . sprintf('%04d', $validData['orderID']);
        $object->order_type = "Custom";
        $object->order_currency_id = "1";
        $object->order_created = time();
        //jexit();
        try {
            $result = JFactory::getDbo()->insertObject('#__hikashop_order', $object);
        } catch (Exception $e) {
            // catch any errors.
        }

        // Left Exo-L
        $exo_left->order_product_name = 'Exo-L Links';
        $exo_left->order_product_code = 'exo-l_links_' . $validData['color_shell_left'] . '_' . $validData['color_padding_left'];
        $exo_left->product_id = 1;
        $exo_left->product_quantity = 1;
        $exo_left->order_product_price = 199;
        $exo_left->order_id = $validData['orderID'];

        // Right Exo-L
        $exo_right->order_product_name = 'Exo-L Right';
        $exo_right->order_product_code = 'exo-l_right_' . $validData['color_shell_right'] . '_' . $validData['color_padding_right'];
        $exo_right->product_id = 12;
        $exo_right->product_quantity = 1;
        $exo_right->order_product_price = 199;
        $exo_right->order_id = $validData['orderID'];

        if ($validData['scan_side'] == 'both') {
            $object->product[0] = $exo_left;
            $object->product[1] = $exo_right;
        } elseif ($validData['scan_side'] == 'left') {
            $object->product[0] = $exo_left;
        } elseif ($validData['scan_side'] == 'right') {
            $object->product[0] = $exo_right;
        } else {
            return false;
        }
        $order_id = $hikaOrder->save($object);
        return $order_id;

Last edit: 11 years 4 months ago by Ortix.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
11 years 4 months ago #117761

You need to use the save function of the hikashopAddressClass and give it an address object. Once that's done and that you got the id of the address you just added, you can add the id in the order_billing_address_id and order_shipping_address_id attributes of your order object.

Please Log in or Create an account to join the conversation.

Time to create page: 0.055 seconds
Powered by Kunena Forum