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');
        if ( !array_key_exists($validityDate, $orderProductArray) ) {
            $orderProductArray[$validityDate] = array();

        array_push($orderProductArray[$validityDate], array(
          'product' => $product->getId(),
          'qty' => $product->getQtyOrdered()

    return $orderProductArray;

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,

                <validity_data />

inside global tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.