0

The company I work for sales custom made signs so a large majority of our Magento orders are custom items.

Before an order is created, there is a mockup design of the sign made and that image is saved to the order. Now I have been tasked with creating a way for the Finished product image to be added to the order.

So if an order is made and then 2 weeks later the sign is built, we need to then be able to attach some product images to that order. Si when we look up an order in Magento, we would be able to see the images alongside any existing images for that order.

What is nice is I have the freedom to do this outside of an Extension if needed.

I would appreciate any help in the right direction on how to attach an image to an existing order? (Not a product)

1

With this answer, I am assuming that you are fairly familiar with creating a module. If a project is not overly complex, I like to write it myself, as I know it will get done right.

Backend Model

Create a SQL script for your images table:

<?php 

$installer = $this;

$installer->startSetup();
$installer->run("
    DROP TABLE IF EXISTS `{$this->getTable('Module_OrderImage/OrderImage')}`;
    CREATE TABLE  `{$this->getTable('Module_OrderImage/OrderImage')}` (
        `entity_id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        `order_id` INT NOT NULL UNSIGNED,
        `image` BLOB,
        `comments` TEXT,
        KEY `SALES_ORDER_ID` (`order_id`),
        CONSTRAINT `FK_SALES_ORDER_ID` FOREIGN KEY (`order_id`)
        REFERENCES `{$this->getTable('sales/order')}` (`entity_id`)
            ON DELETE CASCADE
            ON UPDATE CASCADE
    )ENGINE=InnoDB DEFAULT CHARSET=utf8;
");


$installer->endSetup();

Based on what you said, it sounds as if you are currently saving an image in the sales_flat_order table. You may have to run a script to copy that value into the new table mentioned above.

Then, create your model, resource model, and collection for the OrderImage model.

Admin display

There are a number of ways to allow those in the admin area to attach images to the order. If you are comfortable working with the order grid (which can be somewhat tricky), you could add a section for managing the images. My favorite technique is to include Javascript that renders the section. This makes it so that no overrides are necessary to insert content into the order view.

Otherwise, you could add a button to the top of the page, and go to a grid with the images.

In addition, if you want to display the images in the order grid, you will need to override the Mage_Adminhtml_Block_Sales_Order_Grid class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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