0

I am loading products from a order with this

private function _addItens()
{

    $this->_xml["itens"] = array();
    $this->_xml["itens"]["item"] = array();

    $cont=0;
    foreach ($this->_orderModel->getItemsCollection() as $itemId => $item) {

        $_product = Mage::getModel('catalog/product')->load( $item->product_id );

        $this->_xml["itens"]["item"][$cont] = 
            array(
                "cod" => $item->getSku(),
                "description" => $_product->getData(Lema21_Nfe_Model_TransformToXML::ATTR_OPERATION_NAME),
                "un"    => $_product->getData(Lema21_Nfe_Model_TransformToXML::ATTR_OPERATION_UNIT),
                "qty"  => $item->getData("qty_ordered"),
                "un_price" => $item->getPrice(),
                "type" => self::PRODUCT_OR_SERVICE,
                "weight" => $item->getWeight(),
                "final_weight"  => $item->getWeight(),

                //##HACK##
                "manufacturer" => $_product->getAttributeText(Lema21_Nfe_Model_TransformToXML::ATTR_NAME_MANUFACTURER),
                "class_fiscal" => $_product->getData(Lema21_Nfe_Model_TransformToXML::ATTR_COD_NCM),
                "_icms" => $_product->getData(Lema21_Nfe_Model_TransformToXML::ATTR_COD_ICMS),
                //##/HACK##

                "origin"    => $_product->getData( Lema21_Nfe_Model_TransformToXML::ATTR_COD_ORIGIN )
            );

        $cont++;
    }

    return $this;
}

and that's working for all kinds of products, but when a configurable product arrives, the code return 2 results: the configurable product and the simple product. Since the program work with taxes and stuff, I can't hold these 2 results, I need just one. I need only the simple product, the one that my client chose.

1

You can use:

$item->getParentId() and $item->getProductType() 

to determine if must be included or not in the array.

If you want to export just simple products data exclude those who are 'configurables' if you want to export the configurable but not their childs just exclude those who are 'simples' and has parent.

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.