I request anyone to please give me a solution to write my own SQL query.
I have a controller like this.
class Mage_Sampleorder_TsampleController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
I want to execute my own query in the function , something like $query->setquery(’insert into tablename values (’aaa’,bbb’’,ccc’’) ‘);
Can anyone please give me a solution with steps?
Hello Moshe,
What i am doing is this.
I have a form in sampleorder/tsample with 5 steps.
1) address 2) shipping 3) information form 4) payment 5) review
First time i open http://mydomain.com/sampleorder/tsample/ i get address form.
i will enter the details of address and submit and go to next step.
my address details should get saved in a different table which i have created.
So i want to write my own query in my tsample controller.
Can you tell me how to write?
Also can you tell me how to check session and get the address of logged in customer id?
Please provide me a solution. I need help as i am new to magento.
Are you going to create the whole database structure and html forms for this process?
Or you were looking to use Magento’s models and database structure?
In first case i do not see why it should be part of Magento, in 2nd case I do not think that I will be able to address all specifics and details of custom checkout process.
If you are trying to do this only for learning interest, here’s how you would get customer info:
/** var $session Mage_Customer_Model_Session */ $session = Mage::getSingleton('customer/session');
/** var $customer Mage_Customer_Model_Customer */ $customer = $session->getCustomer();
/** var $address Mage_Customer_Model_Address */ $address = $customer->getPrimaryBillingAddress();
Hi Moshe,
Thank you so much. The requirement is i need to create new form with 5 different steps. The form is similar to checkout but the fields are totally different except for the address.
There are 2 things,
1) checkout as a guest - the details will be a new entry to customers and address table
2) login - if logged in, it has to fetch details of the logged in customer from the same table.
Can you please tell me how to go about this.
Also i would like to know the tables related to fetch customers details right from name,pwd,etc…
Can you explain please?
DevHasMag - as we are focusing our efforts here at Varien on getting the first stable version of Magento released, please wait before trying to implement such massive customizations until we release some documentation.
// now $write is an instance of Zend_Db_Adapter_Abstract $readresult=$write->query("SELECT * FROM `pepitashop_catalog_product_super_attribute_pricing` , `pepitashop_catalog_product_entity`,`pepitashop_catalog_product_super_attribute` WHERE `pepitashop_catalog_product_super_attribute`.product_super_attribute_id = `pepitashop_catalog_product_super_attribute_pricing`.product_super_attribute_id AND pepitashop_catalog_product_super_attribute.product_id = `pepitashop_catalog_product_entity`.entity_id AND pepitashop_catalog_product_super_attribute.product_id = '".$_id."' ORDER BY `pepitashop_catalog_product_super_attribute_pricing`.pricing_value DESC LIMIT 0 , 30 ");
while ($row = $readresult->fetch() ) { $categoryIds[]=$row['id']; }
foreach ($categoryIds as $entity_id) { $write->query( 'INSERT INTO cataloginventory_stock_item (`product_id`,`stock_id`,`qty`,`is_in_stock`) VALUES ( '.$_id.', 1, 99999, 1)' ); }
What exactly i want to do is to also allow ”plural search” when i try to search from the search box
eg: The result that i get after searching for “ Television” i should be getting the same result when i try searching for ”Televisions”.
class Australia_Model_Mysql4_Shipping_Carrier_Australiapost extends Mage_Core_Model_Mysql4_Abstract
{
protected function _construct()
{
$this->_init(’au/postcode/b2b’, ‘postcode’);
}
public function getRegion($toPostCode)
{
$write = Mage::getSingleton(’core/resource’)->getConnection(’core_write’);
$write->query("select region from au_postcode_b2b where postcode = 821");
// echo get_class($write);
$row = $write->fetch();
return $row[’region’];
}
}
but I am getting this error message:
Fatal error: Call to undefined method Varien_Db_Adapter_Pdo_Mysql::fetch() in /home/edscoco/public_html/dev/app/code/community/Fontis/Australia/Model/Mysql4/Shipping/Carrier/Australiapost.php on line 26
if I uncomment the get_class line, I can see the Varien_Db_Adapter_Pdo_Mysql class assigned to the variable.
Any clue of what is wrong?
I’m trying to execute a query on Magento 1.4 from the mentioned sample, it turns out that every time I try to display the select result it doesn’t appear anything on the page.