0

I'm creating a module to add products from the front-end.When the product is created, it visible in the front-end but once is edited in the back-end don't show up in the front-end. I check WebSite, Stock Options, Visibility, Qty, Categories and everything is fine but don't show up.

Here are the code to see if you find any problem

    public function addAction(){
    if($postData = $this->getRequest()->getPost()){
        $product = new Mage_Catalog_Model_Product();

        $product->setSku("base");
        $product->setName($postData['service_name']);
        $product->setDescription($postData['descripcion']);
        $product->setShortDescription($postData['descripcion']);

        $product->setOwnerName($postData['owner_name']);
        $product->setEmail($postData['email']);
        $product->setMovil($postData['movil']);
        $product->setTelephone($postData['telephone']);
        $product->setPais($postData['pais']);
        $product->setProvincia($postData['provincia']);
        $product->setCuidad($postData['ciudad']);
        $product->setReparto($postData['reparto']);
        $product->setAddress($postData['address']);
        $product->setServiType($postData['servi_type']);
        $product->setServicios($postData['servicio']);
        $product->setCapacidad($postData['telephone']);

        $product->setAttributeSetId(9); // put your attribute set id here.
        $product->setTypeId('grouped');
        $product->setCategoryIds(array(3)); // put your category ids here
        $product->setWebsiteIDs(array(1));// put your website ids here
        $product->setPrice(1000);
        $product->setWeight(200);
        $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
        $product->setStatus(2);
        $product->setTaxClassId(0);
        $product->setStockData(array(
            'is_in_stock'             => 1,
            'manage_stock'            => 0,
            'use_config_manage_stock' => 1
        ));


        try {
            $product->save();

            $group_product_id = $product->getId();
            $simpleProductId = array();
            foreach($postData['habt'] as $habtData){
                $textHabType =strtolower(Mage::helper('octus_services')->getAttribTextValue($habtData['tipo_habitacion'], 'tipo_habitacion'));
                $productGrouped = Mage::getModel('catalog/product');
                // Dinámicos
                $productGrouped->setSku($textHabType.'_'.$group_product_id);
                $productGrouped->setName($textHabType.'_'.$group_product_id);
                $productGrouped->setTipoHabitacion($habtData['tipo_habitacion']);
                $productGrouped->setBano($habtData['bano']);
                $productGrouped->setPrice($habtData['price']);
                $productGrouped->setDescription($textHabType.'_'.$group_product_id);
                $productGrouped->setShortDescription($textHabType.'_'.$group_product_id);
                $productGrouped->setStockData(array(
                                                    'is_in_stock' => 1,
                                                    'manage_stock' => 1,
                                                     'qty' => $habtData['qty']
                                                ));
                //Estáticos
                $productGrouped->setAttributeSetId(10);
                $productGrouped->setTypeId('virtual');
                $productGrouped->setStatus(1);
                $productGrouped->setTaxClassId(0);
                $productGrouped->setPriceType(1);
                $productGrouped->setWebsiteIDs(array(1));
                $productGrouped->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
                $productGrouped->save();
                $simpleProductId[] = $productGrouped->getId();
            }
            $products_links = Mage::getModel('catalog/product_link_api');
            // Map each associate product with the grouped product.
            foreach($simpleProductId as $id){
                $products_links->assign ("grouped",$group_product_id,$id);
            }

            Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__('Los datos de su alojamiento han sido agregados satisfactoriamente'));
        }catch (Exception $ex) {

        }
    }
}

1 Answer 1

0

Curious that the product is visible in the front-end until edited in the admin. Looking at this line...

$product->setStatus(2);

...it shouldn't show up at all. In the Status attribute, 2 means "Disabled". My guess is that it's visible immediately after saving because your module holds it in memory, but any click away would mean it's back to being unavailable.

$product->setStatus(1);

Is what you want for "Enabled".

1
  • I saved the product disabled for the group to review if the data are correct and then enable the back-end but after edited is not displayed in the front-end. But if I save the product Enabled with the script then its appears until is edited in the back-end
    – pdaucht
    Nov 13, 2015 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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