I work on one project, users actively use PDF templates in CRM, the fact is that I need to get the field value in the SalesOrderPDFContoller.php file: I used this code:$this->focusColumnValue('input_name'); So I should get the value from the Products module, but instead of the value i get 0.
$this->focusColumnValue() is used to get Salesorder field value not Product value.
If you know the Product id you can use :
$recordModel = Vtiger_Record_Model::getInstanceById($id, 'Product');
$your_input = $recordModel->get('input_name') ;
Related
I'm a newbie to web designing. I'm using contact form 7 to create a registration form for our conference.
All I wanted to do is, I need to give a unique id for all of them after they have registered for the conference and the further forms should be identified using this unique id.
So far, I have installed contact form 7 and contact form dtx
for this purpose and I have tried Koen de Bakker solution of generating a random number.
But it's slightly different from what I want, since it changes the random number for each refresh.
What I'd like is:
An unique number like "17ICLAA001,..." should be generated for each form submission.
Send the unique number to the applicant after successive submission of the form.(I hope this can be easily done once the shortcode is done).
Editing the form using the unique id.
Any help will be much appreciated. Thank you.
I have found a way to do this. Its just the number of rows+1 in the table.
When you add a record to your table the unique number also gets increased by 1 in the following code. Add the following function in function.php in your theme and use the short code "row_count" to call the function. Use it with dynamichidden text from dtx.
function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->username_wp1.SaveContactForm7_1" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );
Usually when you are creating contact forms using contact form7 it automatically creates a table in your database something like
username_wp1.SaveContactForm7_1
Instead of this replace your database table name.
So in your contact form, type
[dynamichidden uniqueid "row_count"]
and use [uniqueid] in your email body to serve your purpose.
It works fine. I have checked in my site.
Correct way to generate a unique and progressive number is to set a field in wp_option like this:
add_option('unique_number', '1');
When filter is called, you must simply increment this unique number:
function genTicketString() {
$currentUniqueNumber = get_option('unique_number');
$newCurrentUniqueNumber = $currentUniqueNumber + 1;
update_option('unique_number' $newCurrentUniqueNumber );
return $newCurrentUniqueNumber;
}
add_shortcode('quoteticket', 'genTicketString');
I have spent hours searching to find where magento stores full county name.
We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored?
and how is it retrieved using that call?
Thanks in advance.
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class
to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php for full list.
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray method it invokes the Zend_Locale class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963
Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.
I have a custom attribute in the customers section in the magento's admin panel where the admin can upload a file unique to each customer.
I need a way to display this file in the front end thus allowing them to download it.
The module that enables the upload of the file was created by my colleague using a module creater. Link: http://www.silksoftware.com/magento-module-creator/
If anyone has any information regarding this matter and could shed some light on this. I would be very grateful.
Magento version: 1.7
Regards,
Julian
You can load the customer collection, tell it to select all attributes (or if you know the attribute code, use that) and then filter by customer id...
$customerId = 1;
$customer = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('eq' => $customerId))
->getFirstItem();
// There may be a better way, but i've found that using the collection method returns all attributes easily.
var_dump($customer);
die();
From the var_dump, you should be able to see the attribute you want to see, then its just a call to...
$myAttributeName = Mage::getModel('customer/customer')->load(185)->getMyAttributeCode()->getName();
I have an issue. I want to show 4 related products in the product page. That is simple and I have done that. But if the product doesn't have any or has less than 4 products I want the remaining product to randomly appear in the page.
To select 4 random products first you need rewrite class that responsible for related block (or just move this file to local folder) and change logic for function that returns collection to something like next code:
$productsCollection = Mage::getResourceModel('catalog/product_collection');
$productsCollection->getSelect()->order('rand()');
$productsCollection->getSelect()->limit(4);
Hope, it will be helpful
If you're only interested in creating this functionality on the product page you can find most of the magic in Mage_Catalog_Block_Product_List_Related::_prepareData().
To fill out your related products with random products, we first need to know exactly how many random products we'll need. In this case, it's (4 - related products found):
// Existing Magento code near end of method
$this->_itemCollection->load();
// Our code
$numRandomsToGet = 4 - count($this->_itemCollection);
Then we can fetch the appropriate number of random products and add them to the collection:
// Our code
$randCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($randCollection);
$randCollection->getSelect()->order('rand()');
$randCollection->addStoreFilter();
$randCollection->setPage(1, $numRandomsToGet);
$randCollection->addIdFilter($this->_itemCollection->getAllIds(), true);
foreach($randCollection as $randProduct)
{
$this->_itemCollection->addItem($randProduct);
}
// Existing Magento code
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
Caveat/Plug: I pulled this code from our Related Products Manager extension for Magento so there might be some fiddling external to this method that needs to get done but I don't think so. If you get stuck you can try downloading the extension and examining the code in its entirety. Or, of course, you can just use the extension as-is.
I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.