getSummaryQty() is not working properly magento - php

I used this function for delete cart items. It is working properly but
$cartHelper = Mage::helper('checkout/cart');
foreach ($itemProductArray as $itmeid => $productid)
{
$cartHelper->getCart()->removeItem($itmeid)->save();
}
getSummaryQty() function gives old quantity value. Anyone help please?

A little bit unclear, but I am assuming you need the getSummaryQty for a block, possibly the sidebar/minicart block or something similar.
If this is the case, make sure you have performed all of your quote modification functionality before the loadLayout() in the current controller, or at least before the block in question is initialized.
Alternatively but not really recommended is to refresh/redirect the page after the cart save.

Related

Anyone Added Custom Field in to Task List Show into Dashboard (Phabricator)

I have added due_date into the Manifest Custom Field. Now I want that where ever task list showing to the user then Due Date also displayed over there.
I know its very small change in codebase but I am not able to debug this.
I missed a step you need I think to call $fields->readFieldsFromStoage($task) and then I used $field->getValueForStorage()
I can't say how correct or legal, of even efficient it is, but it does what I think you wanted
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
if ($fields){
$fields->readFieldsFromStorage($task);
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('Due Date:%s', $field->getValueForStorage()));
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
}
Hope that helps
Ok not a solution, but a place to start...
To alter this you need to edit
ManiphestTaskListView.php in
phabricator/src/applications/maniphest/view
Where you want to put due date is where "Assigned:" is put
if ($task->getOwnerPHID()) {
$owner = $handles[$task->getOwnerPHID()];
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
Pulling in the custom fields may require a little more research, I think you can get to the tasks custom fields via the following
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
You could then pull out the field you want like this if you have to, I suspect there is a better way of doing this...so you just ask for the specific field
if ($fields){
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('%s', $field->getXXXX()));
}
}
I'm not sure what you need to do to get the custom field value, i'm using getXXXX() to represent the sort of thing you might need to do, I think the custom fields often have a render() method but again I'm not completely sure how you go about getting that to render in your listview

Magento - setRelatedLinkData() only saves one link

i'm currently working on a little extension to make it possible to adopt related products of a group product on its associated products.
It work really fine, with the exception, that only the last of the 19 related product is saves and written to the database.
I've checked my source code over and over, even with my team collegue - the code seems to be correct.
In the following i've posted the snippet with the essential parts and i hope that anyone can give me a hint or an advice to solve this problem.
Best regards
Markus
$supplyList =$product->getRelatedProductIds();
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
$params = array();
$_associatedProduct = Mage::getModel('catalog/product');
$prodCount=0;
foreach($supplyList as $sup)
{
$params[$sup] = array('position'=>$prodCount);
$prodCount++;
}
foreach($associatedProducts as $prod)
{
$_associatedProduct
->load($prod->getId())
->setRelatedLinkData($params)
->save();
}
following an update for the problem mentioned in the first post.
Today it worked as it should, without changes made by myself or my collegue.
I'm not sure what the cause of the problem was (caches are disabled since last Monday) and the source was already correct implemented.
It works now and this post is solved, sadly without a solution.
best regards

Magento create new product template

I really like the magento structure but finding things is very hard ;)
My problem is that I have a custom attribute. By calling ‘create new product’ this field should be prefilled with an automatic value like the entity-id. This should only happen within the create new function.
I’m absolutely not capable of finding the corresponding code, where the initial values are set, can anyone give me a hint? (a script must run, not a default value :))
Thanks a lot and grettings,
Matthias
You can find the information needed to find the corresponding code in this post:
Finding Correct Templates and Blocks in Magento
Simply change the default attribute of the field to what you need it to be.
The answer to my problem is overwritting the Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes block.
Within this block, you can use a simple if condiition. the following line has to be replaced by the if:
$values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
new solution:
if($attribute->getAttributeCode() == 'my_attribute_code') {
$values[$attribute->getAttributeCode()] = SET_THE_OWN_VALUE;
} else {
$values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
}
That's all :)
Hope this helps some one else, too !!!

Creating configurable product programmatically

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.

Magento - Programmatically reorder

I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.
This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.
$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);
$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
/*
$order_model->save();
$order_model->place();
$order_model->sendNewOrderEmail();
*/
Any help is greatly appreciated!!
$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();
My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...
I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.
Cheers,
JD
If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.

Categories