0

I am using below code to upload/attach images from product view page frontend, images uploading in directory but not save in quote item & order item table.

    <?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Etheme_Buyshopconfig_CartController extends Mage_Checkout_CartController
{
    public function addAction()
    {
        $data = $this->getRequest()->getPost();

        if (isset($_FILES['options_2_file']['name']) && $_FILES['options_2_file']['name'] != '') {

                foreach ($_FILES['options_2_file']['name'] as $key => $image) {
                    Mage::log('looping');
                    if (empty($image)) {
                        Mage::log('continue');
                        continue;
                    }
                    try {
                        Mage::log('uploading');
                        $uploader = new Varien_File_Uploader(
                                    array(
                                    'name' => $_FILES['options_2_file']['name'][$key],
                                    'type' => $_FILES['options_2_file']['type'][$key],
                                    'tmp_name' => $_FILES['options_2_file']['tmp_name'][$key],
                                    'error' => $_FILES['options_2_file']['error'][$key],
                                    'size' => $_FILES['options_2_file']['size'][$key]
                                        )
                                );

                        // Any extention would work
                        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                        $uploader->setAllowRenameFiles(true);

                        $uploader->setFilesDispersion(false);

                        $path = Mage::getBaseDir('media') . DS . 'custom_options' . DS. 'quote' . DS;
                        $img = $uploader->save($path, $_FILES['options_2_file']['name'][$key]);
                        //var_dump($img);exit;
                        //$imagepath = $img['file'];

                        //$saveData['options_2_file'] = $imagepath;

                        Mage::log($img['file']);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                        Mage::log($e->getMessage());
                    }

                }
            }

        parent::addAction();

    }
}

Image name/path not saved in info_buyRequest "sales_flat_quote_item_option" table and "sales_flat_order_item".

Any help?

1 Answer 1

1

The ID of the product must be in $data.

So you get the model of the desired product :

$product = Mage::getModel('catalog/product')->load($id);

...//And you need to rewrite the path of the picture.

$product->save();

I hope that my answer will bring you closer to the solution.

4
  • @shoaib Saleem try this code Commented May 17, 2018 at 6:29
  • Did you succeed? Commented May 17, 2018 at 9:12
  • What is $id?Add complete code. Commented May 18, 2018 at 4:33
  • $data = $this->getRequest(); and var_dump($data) ; $data have id products. Commented May 19, 2018 at 8:59

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.