2

I created a custom attribute called validity_date and assigned it to the default product attribute set. When I create a product I have to enter some values for it. Seems all to be fine, but in the checkout process I have a function that should group the products in a specific way. The problem is that the validity_date is not delivered with the product. I wonder what I can do to get the attribute value, set to the product.

public function getProductsOrderedByValidityDate($order) { // get all products $productCollection = $order->getAllItems(); // sort all products for each day $orderProductArray = array(); foreach ($productCollection as $product) { $validityDate = $product->getData('validity_date'); Mage::log($product->debug()); if ( !array_key_exists($validityDate, $orderProductArray) ) { $orderProductArray[$validityDate] = array(); } array_push($orderProductArray[$validityDate], array( 'product' => $product->getId(), 'qty' => $product->getQtyOrdered() )); } return $orderProductArray; } 

1 Answer 1

2

What you created, was a product attribute. In order to access that with the quote/order items(which are not "Product" objects), you can go with one of the 2 choices :

1.) Get product object from the order item object and then calling the attribute. It will be like $product->getProduct()->getData('validity_date); in your particular case.

2.) You can instruct magento to convert that attribute into attribute of quote object, although, it will still not be available after order is placed without actually storing it with the order items. To get attribute from quote, you'll need to have something like this in some config.xml file,

<sales> <quote> <item> <product_attributes> <validity_data /> </product_attributes> </item> </quote> </sales> 

inside global tag.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.