I have a problem with grocery crud hidden field and set relation .
My code is
$crud->set_relation('created_by','users','user_name');
$crud->edit_fields('title', 'description', 'created_by');
$crud->change_field_type('created_by', 'hidden', $this->user_id);
Here i want to store user_id as created by in hidden form. But problem is that created_by field is still visible in my view page. when I cut off set_relation then created_by field is hidden. What's problem ? plz help me
$state = $crud->getState();
if ($state === 'list') {
$crud->set_relation('created_by','users','user_name');
}
$crud->edit_fields('title', 'description', 'created_by');
$crud->change_field_type('created_by', 'hidden', $this->user_id);
Use the below coding
$crud->change_field_type('created_by', 'hidden', $this->user_id);
to
$crud->field_type('created_by', 'hidden', $this->user_id);
Related
I want to change the attribute set of Magento. I searched through, and everyone suggested to delete the product and re-import it with new attribute set.
I did the same however after importing the data I could not see product reviews and associated blog post with product.
Can anyone tell me is it possible to get product reviews and associated blog post after re-importing the product with new attribute set.
Once set you can't change the attribute set of a product. But it's possible using this module so you don't have to reimport your data
https://marketplace.magento.com/flagbit-magento-changeattributeset.html
It's also possible to change the attribute set directly in the database.
Look up the attribute set ID in table eav_attribute_set
Change the attribute set ID in catalog_product_entity
Of course, be careful when changing data this way.
It is fiddly to do and a bit messy:
Make sure new attribute set is set up
Export the products you want to change
Delete the products that you are changing on the site
Change the attribute set on the downloaded file
Import changed file again
Open each changed product, set their attribute values, save it
Or do what I do, install this great extension from Amasty http://amasty.com/mass-product-actions.html - it makes changing a breeze and gives many more time saving and enhancing options.
Once you delete the product you can't get the old review.
You don't need to delete the product . You can change the attribute set by editing and use.
other wise create a new attribute set and create new product.
Yes. We can change product attribute set programmatically.
I prefer to create massaction in catalog product grid to multiselect product and then select massaction for the products.
Creating massaction in grid.php
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->getMassactionBlock()->addItem('changeattributeset', array(
'label'=> Mage::helper('catalog')->__('Change attribute set'),
'url' => $block->getUrl('*/*/changeattributeset', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'attribute_set',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Attribute Set'),
'values' => $sets
)
)
));
Creating controller action for change attribute sets of the selected products.
public function changeattributesetAction()
{
$productIds = $this->getRequest()->getParam('product');
$storeId = (int)$this->getRequest()->getParam('store', 0);
if (!is_array($productIds)) {
$this->_getSession()->addError($this->__('Please select product(s)'));
} else {
try {
foreach ($productIds as $productId) {
$product = Mage::getSingleton('catalog/product')
->unsetData()
->setStoreId($storeId)
->load($productId)
->setAttributeSetId($this->getRequest()->getParam('attribute_set'))
->setIsMassupdate(true)
->save();
}
Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$productIds));
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($productIds))
);
}
catch (Exception $e) {
$this->_getSession()->addException($e, $e->getMessage());
}
}
$this->_redirect('adminhtml/catalog_product/index/', array());
}
You can add to your data patch apply function something like this:
public function apply(): self
{
$this->moduleDataSetup->getConnection()->startSetup();
/** #var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttributeToSet(
Product::ENTITY,
'Default',
'General',
CustomAttributesInterface::ATTRIBUTE_CODE_MANUFACTURER
);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
This changes the manufacturer products attribute to the Default attribute set. (By default this attribute has no attribute set.)
Hope it helps :)
is it somehow possible to use {{var invoice.increment_id}} in the creditmemo e-mails? It don't work if I do so...
<p><strong>Bestellnummer:</strong> {{var order.increment_id}}</p>
<p><strong>Datum:</strong> {{var creditmemo.created_at}}</p>
<p><strong>Rechnung:</strong> {{var invoice.increment_id}}</p>
<p>Liebe(r) {{htmlescape var=$order.getCustomerName()}},<br/><br/>
Doesn't work. Does someone has a hint for me? Thanks!
EDIT
Is that correct?
Edit the class Mage_Sales_Model_Order_Creditmemo and adding:
//Get Invocie from order Object
if ($order->hasInvoices()) {
// "$_eachInvoice" is each of the Invoice object of the order "$order"
foreach ($order->getInvoiceCollection() as $_eachInvoice) {
$invoice = $_eachInvoice->getIncrementId();
}
//$invoice = $order->getInvoiceCollection();
}
aswell as
$mailer->setTemplateParams(array(
'order' => $order,
'creditmemo' => $this,
'comment' => $comment,
'invoice' => $invoice,
'billing' => $order->getBillingAddress()
)
);
and afterwards calling the variable {{var invoice}} in my email template?
But it doesn't show, what I'm missing here?
You should rewrite Mage_Sales_Model_Order_Creditmemo model in your module and add needed logic to sendUpdateEmail() method to get invoice object in credit memo email templates.
See my frist post. I got it right. Thanks to Zyava.
The problem was, you have to place this code one method above the sendUpdateEMail(), in sendEmail().
Thanks!
I have my controller, my function to insert into the database, and the form.
I just want to insert the user in the database if he enter the email is not already registered in the database.
My controller:
$nome = $this->_request->getParam('nome');
$senha = $this->_request->getParam('senha');
$confirmar = $this->_request->getParam('confirmar');
$email = $this->_request->getParam('email');
$usuarios = new Application_Model_DbTable_Usuarios();
$usuarios->addUsuario($nome, $senha, $email);
My DbTable_Usuario class that contains my function that inserts the user in the database
public function addUsuario($nome, $senha, $email) {
$data = array(
'id' => 'NULL',
'nome' => $nome,
'senha' => $senha,
'email' => $email,
'nivel' => '0'
);
$this->insert($data);
}
And my zend_form
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email:')
->setRequired(true)
->addValidator('EmailAddress')
->addValidator('NotEmpty');
I have some way to add something to the form it checks if the mail entered already exists in the database? If it exists, it displays the message, and if not, insert it in the bank.
Add a Zend_Validate_Db_NoRecordExists validator to the email field.
To give a closer insight on a specific problem using NoRecordExists. The Validator is added just at the way that other validators are
$email->addValidator('Db_NoRecordExists', false, array('table'=>'usario', 'field'=>'email'));
Depending on your form setup, you will use the exact same field for EDITING a user, too. When editing a user the NoRecordExists is a little tricky. As for once, you shouldn't be allowed to change into an existing email, but you should be able to update your other data and keep your email (which though is existing in your db in the current row).
You therefore need to remove the current row from that rule. There are several approaches, which you can see from my own question, but i think the following works best from controller level:
$form = new UserForm();
$form->getElement('email')->getValidator('Db_NoRecordExists')->setExclude(array(
'field' => 'id',
'value' => $idToEdit
))
I have a custom module that adds a field to an element in
<?php
class NS_MN_Block_Cms_Page_Edit_Tab_Main extends Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Main
{
public function _prepareForm()
{
parent::_prepareForm();
$fieldset = $this->getForm()->getElements()->searchById('base_fieldset');
$fieldset->addField('bar', 'text',
array(
'label' => Mage::helper('cms')->__('BaR'),
'class' => 'input-text',
'name' => 'bar',
'required' => false
)
);
return $this;
}
}
I have added the bar field into the cms_page table and the field is rendered, but when I save the cms page, the field is not saved to the database.
Could anyone tell me what I am overlooking here?
You need to remember to flush your cache. This one has caught me out a few times before.
Go into System > Cache Management and click both flush buttons.
Log out of the admin and log back in. Everything should function as expected.
Have you added the field to the database? Having the field in the form is one step, but in order to persist the data it must be able to live in a column in the DB. Once the field is in the DB, you might have to change the controller to recognize the new field, but it might already work for all fields. If it is already doing a setData($data) where $data is all received form data, you should be fine.
I have a dropdown list which is being populated from database. It is working fine but in the form_dropdown in the view file, I want to add class="required" for validating the dropdown using Jquery. I have tried to make it work but as it turned out it won't work. Would you please kindly help me where exactly to put the class="required" - and make the jquery validation work?
Thanks in Advance
I have this in my controller
// To get the batch name
$this->load->model('dropdown_batchlist');
$data['dropdown_batchlist']= $this->dropdown_batchlist->dropdown_batchlist();
this in my model-
function dropdown_batchlist() {
$this->db->select('batchname, batchid');
$records=$this->db->get('batch');
$data=array();
// add it here as the first item in the array,
// assuming you don't have a $row->batchid of 0 in your results.
$data[0] = 'SELECT';
foreach ($records->result() as $row)
{
$data[$row->batchid] = $row->batchname;
}
return ($data);
}
And this in my view file
<?php echo form_dropdown('batchid', $dropdown_batchlist,'', 'class="required"' ); ?>
The Problem is Solved
I have figured out the problem. The view file was okay, all I had to do is replace $data[0] = 'SELECT'; with
$data[' '] = 'SELECT';
Thanks
Try setting the attributes using an associative array:
$attributes = array(
'name' => 'batchid',
'class' => 'required',
'options' => $dropdown_batchlist
);
echo form_dropdown($attributes);