Domanda

ho aggiunto un nuovo atribute chiamato frontend_price nel backend di Magento nel gestire la selezione dei prodotti.

Nel valore di questo attributo vorrebbe ottenere il prezzo del prodotto e si moltiplicano con l'Iva e la valuta. Niente di speciale solo per sé prezzo frontend del prodotto nel backend, ma non memorizzati in qualsiasi tavolo del db. Questo attributo è solo porpose interno, quindi non deve essere visibile nel frontend.

pensavo:

Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
$currencyrate = Mage::app()->getStore()->getCurrentCurrencyRate(); 
$price_normal = $_product->getPrice();
$_product->getResource()->getAttribute('frontend_price')->getFrontend()->getValue($_product) = $price_normal*$currencyrate*1.24;

Purtroppo non so dove ad applicare queste regole per vederlo in backend. Qualsiasi ideea dove per modificare la pagina per la pagina di selezione del prodotto backend.

Grazie.

È stato utile?

Soluzione

È possibile utilizzare un modello di backend per questo, in primo luogo è necessario creare l'attributo (nello script di installazione del modulo):

// This attribute will get installed in all attribute sets
$installer->addAttribute('catalog_product', 'frontend_price', 
    array(
       'type'                          => 'decimal',
       'label'                         => 'Frontend price',
       'class'                         => '',
       'global'                        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
       'backend'            => 'feprice/entity_attribute_backend_feprice',
       'visible'                      => true,
       'required'                   => true,
       'user_defined'           => false, // this is what determines if it will be a system attribute or not
        'default'                   => '',
        'searchable'            => false,
        'filterable'                => false,
        'comparable'            => false,
        'visible_on_front'      => false,
        'unique'                    => false
       ));

Avanti si crea il modello di backend:

class My_FrontendPrice_Model_Entity_Attribute_Backend_Feprice extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract {

    public function beforeSave($object) {
        // This is where we would perform the audit (or any other logic we wanted)
        // We could email the changes to a store admin, for example
        $currencyrate = Mage::app()->getStore()->getCurrentCurrencyRate(); 
        $price_normal = $object->getPrice();

        $object->setFrontendPrice($price_normal*$currencyrate*1.24);
        return $this;
    }
}

Ora il prezzo frontend sarà aggiornata ogni volta che si salva il vostro prodotto.

Codice si basa sul frammento: http://magebase.com/magento-tutorials/using-a-backend-model-to-customize-magento-a-tip-from-magento-developers-paradise/

Altri suggerimenti

È possibile utilizzare l'catalog_product_save_before manifestazione e nel metodo che gestisce questo evento aggiungere qualcosa di simile:

public function catalog_product_save_before($observer){
    $product = $observer->getEvent()->getProduct();
    $frontendPrice = ...Your algorithm here
    $product->setFrontendPrice($frontendPrice);
}

Ora, ogni volta che si Salva un prodotto della frontend_price attributo sarà calcolato e anche se si dispone di un campo per esso nel backend, il suo valore sarà ricalcolato ad ogni salvataggio processo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top