Magento - type of custom attribute, file upload

You do not know where to start with this and what is the best solution. I need to have a product attribute that supports file uploads in order to create an image.

I'm not looking for code, just advice on the best way to achieve this

+3
source share
4 answers

I think you need to create your own tab on the "Management → Products" page in the admin application, and then inside it you will want to use a technique such as the link here for the bootloader:

http://www.magentocommerce.com/boards/viewthread/11667/P0/

, , egt/set , , , .

" → ", :

http://fishpig.co.uk/custom-tabs-magento-product-admin/

+2

,

+1

.

:

, Magento, . Magento Forum, .

Magento , . - , , , , , , .

Frontend html :

/// / ///////file.phtml

:

app/design/frontend/default/default/template/catalog/product/view/options.phtml
(optionFileUpload js object = iframe)

, :

<file translate="label" module="adminhtml">
    <label>File</label>
    <render>adminhtml/catalog_product_edit_tab_options_type_file</render>
    <types>
        <file translate="label" module="adminhtml">
            <label>File Upload</label>
        </file>
    </types>
</file>

node:

config- > > - > - > Options- → -

//​​ ​​/Mage// .. /config.xml

, !

, , , Magento!

0

if you want to add file upload for client / product. just create a related attribute for this, and in the admin panel you will find an option and work correctly, and for the interface just create an input file. upload it through the magento file downloader to any directory and just save the file path in the attribute. My code for the client file attribute for reference:

<label for="certificate"><?php echo $this->__('Re-Sale Certificate') ?></label>
                    <div class="input-box">
                        <input type="file" name="designer_certificate" title="<?php echo $this->__('certificate') ?>" id="designer_certificate" />
                    </div>  

installer for file attribute

$installer = $this;
$installer->startSetup();

//$installer->getConnection()->addColumn($installer->getTable('customer/entity'), 'certificate', 'varchar(100)');
$installer->removeAttribute('customer', 'designer_certificate');
$installer->addAttribute("customer", "designer_certificate",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Designer Certificate",
    "input"    => "file",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""
    ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "designer_certificate");


$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
        ;
        $attribute->save();

$installer->endSetup();

configurations:

<global>
....
<resources>
      <designercertificate_setup>
        <setup>
          <module>Renegade_Account</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </designercertificate_setup>
      <designercertificate_write>
        <connection>
          <use>core_write</use>
        </connection>
      </designercertificate_write>
      <designercertificate_read>
        <connection>
          <use>core_read</use>
        </connection>
      </designercertificate_read>
    </resources>
....
    </global>

Now download the file and just save as

    .....
        $path = Mage::getBaseDir('media') . DS .'customer'. DS . 'designer-certificates' . DS;
                if (!is_dir($path)) {
                    mkdir($path, 0777, true);
                }
                $filename = str_replace(' ', '_', trim($_FILES['designer_certificate']['name']));
Add a comment to this line
                $uploader->save($path, $filename);
                $file = "/designer-certificates/" . $filename;
                $customer->setDesignerCertificate($file);
    .....

the file must be saved in the media, the client folder for the client file attribute, if you want to use the built-in functions.

0
source

Source: https://habr.com/ru/post/1791573/


All Articles