I have created new configurable products, and attached their simple products with PHP.
Now when I edit any configurable product I see this screen:
So in absence of any Magento documentation, what do I call in PHP to perform the same function as the screen above programatically?
I have seen $configurable_product->setConfigurableProductsData() used in some examples, but don't think it is what I need.
You are right, you are creating the association/link between configurable and child products but what's happening is that when you are creating your configurable product you are not setting up the setConfigurableAttributesData that basically setups the superattribute information for that configurable product.
foreach($configAttrCodes as $attrCode){
$super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attrCode->code);
$configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute);
$newAttributes[] = array(
'id' => $configurableAtt->getId(),
'label' => $configurableAtt->getLabel(),
'position' => $super_attribute->getPosition(),
'values' => $configurableAtt->getPrices() ? $configProduct->getPrices() : array(),
'attribute_id' => $super_attribute->getId(),
'attribute_code' => $super_attribute->getAttributeCode(),
'frontend_label' => $super_attribute->getFrontend()->getLabel(),
);
}
$existingAtt = $product->getTypeInstance()->getConfigurableAttributes();
if(empty($existingAtt) && !empty($newAttributes)){
$configProduct->setCanSaveConfigurableAttributes(true);
$configProduct->setConfigurableAttributesData($newAttributes);
$configProduct->save();
}
This is small snippet should get you there, let me know if you have any questions or need further help.
Related
Faced some trouble within prestashop 1.6.0.9 admin products filtering by status in multishop enabled.
To explain in details picture below
As seen in picture product filtered by status "NO", but it displays on. Does anynone has such issue, by looking at controller and database, status is filtered by product table - where product is off, but displays from product_shop table where that shop active field is on. How can i manage filtering by status, am i facing with this alone? is there a fix already to this (HelperList?).
Can i somehow to set that list would be filtered by joint tables?
$this->table = 'product';
$this->fields_list['active'] = array(
'title' => $this->l('Status'),
'active' => 'status',
'filter_key' => $alias.'!active',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
);
maybe you can use ['list'] => $this->countries_array as option in your field list see documentation here http://doc.prestashop.com/display/PS16/Using+the+HelperList+class
I asked this same question on the official forums but received no response. Not sure if anyone here is experienced with PrestaShop but here is my issue.
I need to add an extra field in the manufacturer edit/add tab, I was able to do this by overriding renderForm in AdminManufacturersController.php like this:
public function renderForm()
{
global $shopOptions;
$this->fields_form_override = array(
array(
'type' => 'checkbox',
'label' => 'Shop',
'name' => 'shop_select',
'desc' => 'Choose The Shops This Manufacturer Applies To',
'values' => array(
'query' => $shopOptions, >> comes from array filled by db query in __construct
'id' => 'id',
'name' => 'name'
),
),
);
return parent::renderForm();
}
This works and I am now trying to find the update and create functions for a manufacturer. When editing the product classes, you can easily spot set functions like setQuantity in StockAvailable.php.
I have ssh access to the server so I was able to dig deeper with grep, to no avail. It seems like it uses some sort of function to auto insert into the database whilst some classes use a plain old execute with a normal query.
Any ideas on where this could be found?
On Prestashop 1.6.x you do not need to amend any function for it to have CRUD functionalities. You just need to add it in :
RenderForm (like you already did)
Add the variable in the manufacturer class (Manufacturer.php) like public $shop_select;
Add it in the public static $definition array in the manufacturer class
Add the column in manufacturer or manufacturer_lang table depending on whether your field is a lang field.
Cheers :)
I am making the link between simple and configurable products as follows:
Mage::getResourceSingleton('catalog/product_type_configurable')
->saveProducts($confProduct, $simplesToAddConfig);
But in this way it is not possible to inform the price of the product
I tried that way too, but I did not succeed:
$simpleProductsData = array(
'label' => "abc",
'attribute_id' => '128',
'value_index' => '21',
'is_percent' => '0',
'pricing_value' => '150',
);
$configurableProductsData[ 973 ][] = $simpleProductsData;
$confProduct->setCanSaveConfigurableAttributes(true);
$confProduct->setConfigurableProductsData($configurableProductsData);
Is there any way to report this field?
Thank you so much
----EDIT
I got the solution by adapting this module:
http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/
You can find many article to create the simple and configurable products.
I am sharing a blog post which explained each steps precisely. and also share the module code to create products.
https://blog.amasty.com/creating-magento-simple-configurable-products-programmatically/
I need to show one certain product on front page. I didn't find a module for this. What do I need to do? I need to show product with countdown timer but I can do this, I only do not know how to get product from database by ID or SKU. I guess the code should be like this:
echo $product_option_data[] = array(
'product_option_id' => $product_option['product_option_id'],
'option_id' => $product_option['option_id'],
'name' => $product_option['name'],
'type' => $product_option['type'],
'option_value' => $product_option['option_value'],
'required' => $product_option['required']
);
In OpenCart controller you can call
$this->load->model('catalog/product'); // only if not yet 'loaded' within the controller
$product = $this->model_catalog_product->getProduct($productId);
print_r($product);
which will return you the product by it's ID. Do with it whatever you need afterwards.
I've got the following code:
$filters = array('sku' => array('like'=>'%'));
$items = $magConn->call($sessionID, 'product.list', array($filters));
This will return an array of all the products and their sku, description, and qty.
However, I also need to get the price? Is there a way to get that as well?
I've also got this working,
$properties = ($magConn->call($sessionID, 'product.info', $item['sku']));
which will return all the attributes for one product. I've got over 2,000 products, and this is definitely not feasible if I want it to end tonight. ;)
No way without magento source code modification. You should go to \app\code\core\Mage\Catalog\Model\Product\Api.php, find next lines inside items() method:
$result[] = array( // Basic product data
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'category_ids' => $product->getCategoryIds()
);
and add price here.
Load the collection :
$product = Mage::getModel('catalog/product')->load($productId);
Get actual price :
$product->getPrice();
Get special price :
$product->getFinalPrice();