Ben satış / order_shipment modeline "vendorping" adlı bir EAV öznitelik eklemek çalışıyorum. Bunu başarmak için, benim modülünde aşağıdaki dosya oluşturulur:
// app\code\local\Jb\Vendorping\sql\vendorping_setup\mysql4-install-0.1.0.php
$this->startSetup();
$sql = 'SELECT entity_type_id FROM `'.$this->getTable('eav_entity_type').'` WHERE entity_type_code = \'shipment\'';
$row = Mage::getSingleton('core/resource')
->getConnection('core_read')
->fetchRow($sql);
$entityTypeId = $row['entity_type_id'];
$c = array(
'entity_type_id' => $entityTypeId,
'attribute_code' => 'vendorping',
'backend_type' => 'int',
'frontend_input' => 'text',
'is_global' => '1',
'is_visible' => '0',
'is_required' => '0',
'is_user_defined' => '0',
'frontend_label' => 'Vendor Confirmed',
);
$attribute = new Mage_Eav_Model_Entity_Attribute();
$attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
->setStoreId(0)
->addData($c)
->save();
$this->endSetup();
Şimdi, bu iyi çalışıyor - bu özellik başarıyla eklenir:
mysql> mysql> SELECT * FROM eav_attribute WHERE attribute_code LIKE 'vendorping';
+--------------+----------------+----------------+-----------------+---------------+--------------+---------------+----------------+----------------+------------------+----------------+--------------+-------------+-----------------+---------------+-----------+------+
| attribute_id | entity_type_id | attribute_code | attribute_model | backend_model | backend_type | backend_table | frontend_model | frontend_input | frontend_label | frontend_class | source_model | is_required | is_user_defined | default_value | is_unique | note |
+--------------+----------------+----------------+-----------------+---------------+--------------+---------------+----------------+----------------+------------------+----------------+--------------+-------------+-----------------+---------------+-----------+------+
| 127 | 8 | vendorping | NULL | NULL | int | NULL | NULL | text | Vendor Confirmed | NULL | NULL | 0 | 0 | NULL | 0 | |
+--------------+----------------+----------------+-----------------+---------------+--------------+---------------+----------------+----------------+------------------+----------------+--------------+-------------+-----------------+---------------+-----------+------+
1 row in set (0.00 sec)
Ben bu denetleyicisi eylem Ama kaçarsan, başarıyla yeni bir nitelik kurtarmak için görünmüyor olabilir:
// app\code\local\Jb\Vendorping\controllers\IndexController.php ===
class Jb_Vendorping_IndexController extends Mage_Core_Controller_Front_Action
{
public function pingAction()
{
// Get shipment
$shipmentId = 1; // Set manually for now
$shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
var_dump($shipment->getOrder()->getShippingDescription());
// Outputs:
// string(17) "Flat Rate - Fixed" [So the shipment exists]
// Save "vendorping" field and save
$shipment->setVendorping(1);
$shipment->save();
// Reload shipment from database
$shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
// Check "vendorping" field
var_dump($shipment->getVendorping());
// Outputs:
// NULL [Why??]
}
}