creating product with installer script in magento custom module - magento

i am trying to create a product (with basic attributes) when the custom module get installed.
i am developing a magento custom module which requires a product to be created at the time of its installation. i have successfully created a product in programmatic way (on fly) but it requires to be created only when the specific parameter received and also after successful transaction it needs to be deleted so i was asked ,in order to save the hassle why not create the product when the module get installed via installer script (in setup directory).
but i am not able to find the way yet as i am new to the magento module development.
any suggestions , is it a right approach? if so what should be the process? is there a specific even that can be triggered when the module get installed?
thanking you all in anticipation

Try in this way:
$data = array(
'name' => '<name>',
'sku' => '<sku>',
'attribute_set_id' => <attribute_set_id>,
'type_id' => <product_type_code>,
'website_ids' => array(1),
'description' => '<description>',
'short_description' => '<short_description>',
'price' => <price>,
'tax_class_id' => <tax_class_id>,
'visibility' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
'status' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
'category_ids' => array(<category_ids>),
);
$productModel = Mage::getModel('catalog/product');
$productModel->setData($data)
->save();

Related

Laravel - Payone

Is there an easy wrapper for the payone(https://www.payone.de/) API for Laravel? I only found one company who sells a package but nothing that is open source. I would appreciate any help.
You should consider Omnipay: http://omnipay.thephpleague.com/
Because:
It is gateway independent.
It is framework independent. It works well with Laravel but also Symfony, Yii, etc.
There is an Omnipay plugin for PayOne: https://github.com/academe/OmniPay-Payone
The code to make a purchase via Omnipay is pretty much the same regardless of the gateway. Here is some sample code that should work, although you should check the details of the Payone classes for other information that you need to send. The Payone gateway can work in multiple different ways depending on how your account is set up.
$gateway = Omnipay::create('Payone_ShopServer');
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
// ... etc
));
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
}
// At this point you should get $response->getTransactionReference()
// and store that or something similar.

Magento Bundle products created with SOAP v1 API don't show up in frontend

The Problem
I'm creating and updating products in a Magento 1.9 shop using the SOAP v1 API with PHP.
Everything is working as expected, but bundle products never show up in the frontend.
If I create a simple product instead everything works just fine.
By now I have programmatically created bundle products that show exactly the same data in the backend as a manually created one. However, they don't appear in categories or search.
What I checked so far
The created product:
is enabled
is visible (catalog/search)
is assigned to a category
is assigned to the right website
is assigned to the right store view
is in stock
has a simple product assigned which
has stock
is in stock
I also...
disabled the compiler
tried flushing the cache
tried reindexing
manually went to the static product page URL -> bundle product shows up
Is there anything else I missed or can check for? I'm really out of ideas and went through everything I could find on Google and SO.
Example API call
This is the data of a particular API call in PHP.
$productData = array (
'category_ids' => array (2),
'website_ids' => array (1),
'name' => 'AK 000016 Bundle',
'description' => 'AK00016 Bundle descr',
'short_description' => 'AK00016 Bundle short',
'status' => '1',
'url_key' => 'AK000016',
'visibility' => 4,
'tax_class_id' => 2,
'stock_data' => array (
'qty' => '10',
'is_in_stock' => '1',
),
);
// Attribute-set id 4, store view code 'en'
$client->call($session, 'catalog_product.create',
array ('bundle', '4', 'AK000016', $productData, 'en'));

How to get a list of cms pages in Magento?

What i'm trying todo
I have created an admin form where the user needs to select a CMS page from a drop down.
What i have tried
$form->addField('cms_page_id', 'select', array(
'label' => Mage::helper('custom/data')->__('CMS Page'),
'class' => 'required-entry',
'required' => true,
'name' => 'cms_page_id',
'values' => Mage::getSingleton('cms/page')->toOptionArray(),
'value' => $this->getCmsPageId()
));
The idea is the code gets the an option array from the CMS model. However "toOptionArray" is an invalid function for the 'cms/page' model.
My Question
How can I get an option array of CMS pages for use in an admin form in Magento?
With your code you are loading a new cms page model. To get a collection use following code and toOptionArray() will at least return something:
Mage::getModel('cms/page')->getCollection()->toOptionArray()
CMS Pages array with Links
$cms_arr = Mage::getModel('cms/page')->getCollection()->toOptionArray();
$cms_pages[""] = "-Select CMS Page-";
foreach($cms_arr as $cms){
$url = $this->getUrl($cms["value"]);
$cms_pages[$url] = $cms["label"];
}

Magento module setup/installer script

I'm trying to setup attribute-sets and attributes automatically via a setup script. The script is working and all attributes are added to the sets, no problem with that... however, when I look at the attributes the visible_on_front, the used_in_product_listing and the global are not set properly. This is what I have:
$installer->addAttribute('catalog_product', '<attribute_code>', array(
'group' => 'General',
'input' => 'date',
'type' => 'datetime',
'label' => '<some_label>',
'backend' => 'eav/entity_attribute_backend_datetime',
'is_global' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
'is_visible_on_front' => 1,
'visible_on_front' => 1,
'used_in_product_listing' => 1,
));
Anyone know how I can fix this so it works?
The trick here is to make sure that you are using the correct Setup object. The default Setup object is Mage_Eav_Model_Entity_Setup which will add your attribute into eav_attribute table but it is not aware of the extra fields in catalog_eav_attribute such as used_in_product_listing (or customer_eav_attribute and it's fields for that matter).
So, add this at the top of the install script:
$installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$installer->startSetup();
That should make the difference.
FYI, you can use Mage_Customer_Model_Entity_Setup to achieve the same end for customer attributes.

Change Customer to Company on Magento Administrator Dashboard

On the Magento administrator Dashboard I'm looking to update the 'Last 5 Orders' block so that instead of displaying the customer name, it shows the company billing name instead.
My understanding is that this can't be done using the standard reports collection, I've seen examples for doing this on the main sales grid screen, but not on the dashboard. To add further complexity this is for the latest version of Magento 1.6.1.0 and it appears the method of doing this may have changed somewhere around 1.4.
The file I believe needs editing is:
app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php
Hopefully this is one of those 'easy when you know how' solutions that lots of people can benefit from.
Here is the code
PS : I haven't got time to test this code block.
The code block available in the :
app\code\core\Mage\Adminhtml\Block\Dashboard\Tab\Customers\Most.php
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => $this->__('Customer Name'),
'sortable' => false,
'index' => 'name'
));
$this->addColumn('orders_count', array(
'header' => $this->__('Number of Orders'),
'sortable' => false,
'index' => 'orders_count',
'type' => 'number'
));
and here is the sample link that you can override the magento admin sales grid
Override Admin Sales Order Search Grid

Resources