cancel
Showing results for 
Search instead for 
Did you mean: 

hi there, i have a question

hi there, i have a question

I am trying to save a product after updating the price via a new module in admin. I can update and view the prices from the page, but saving always results in empty admin screen, (no data other than page tile is renedered) if I remove the save function from the chain on the template page everything works as expected. Any help whatsoever would be greatly appreciated. I have included what I believe to be the relevant code below including how far I can trace the error below.

 

I have followed the code through "Magento\Framework\Model\ResourceModel\Db\AbstractDB::updateObject()" which reports the data is saving, I havent figured out how to debug getConnection()->update() yet. But all I get on screen is the white page when ever I include save in the chain. I am under the assumption that because the abstract db model shows the error_log after it updates the connection that this is not causing the page to error out?

 

 

The block:

 

"Vendor\Module\Block\Adminhtml\Index"

protected $_PRODUCTMODEL = NULL;
protected $_OBJMANAGER = NULL;

public function __construct(\Magento\Backend\Block\Template\Context $context,\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,array $data = []
)
{$this->_productCollectionFactory = $productCollectionFactory;parent::__construct($context, $data);$this->_OBJMANAGER = \Magento\Framework\App\ObjectManager::getInstance();$this->_PRODUCTMODEL = $this->_OBJMANAGER->get('Magento\Catalog\Model\Product');
}
public function productModel(){
return $this->_PRODUCTMODEL;
}

public function productData($sku){
return $this->productModel()
->loadByAttribute("sku",trim($sku));
}

The template:

 adminhtml/template.phtml
    <?php
    foreach($this->getProducts() as $product){
        //$product->setPrice("19.11");
        //$product->save();        $productModel = $this
            ->productData($product->getSku())
            ->setData("price","22.1111")
            ->save();        echo "ID:<pre>".print_r($productModel->toArray(),1)."</pre>";
    }
    ?>

Output  of print_r() without ->save() in the chain:

Array
(
    [entity_id] => 2052
    [attribute_set_id] => 4
    [type_id] => simple
    [sku] => xxxbxnxnxnxnxnnx
    [has_options] => 0
    [required_options] => 0
    [created_at] => 2016-03-14 13:46:27
    [updated_at] => 2016-03-14 16:04:35
    [name] => Tests Sku
    [meta_title] => Tests Sku
    [meta_description] => Tests Sku 

hello

    [image] => 
    [small_image] => 
    [thumbnail] => 
    [custom_design] => 
    [page_layout] => 
    [options_container] => container2
    [country_of_manufacture] => 
    [url_key] => tests-asin
    [msrp_display_actual_price_type] => 0
    [gift_message_available] => 
    [swatch_image] => 
    [status] => 1
    [visibility] => 4
    [quantity_and_stock_status] => 1
    [tax_class_id] => 2
    [price] => 22.1111
    [special_price] => 
    [cost] => 
    [weight] => 
    [msrp] => 
    [special_from_date] => 
    [special_to_date] => 
    [news_from_date] => 
    [news_to_date] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [description] => 

hello

    [short_description] => 
    [meta_keyword] => Tests Sku
    [custom_layout_update] => 
    [is_salable] => 1
)

 

How far I can trace the error:

 

<?php/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Framework\Model\ResourceModel\Db;

abstract class AbstractDb extends AbstractResource
{
    protected function updateObject(\Magento\Framework\Model\AbstractModel $object)
    {        $condition = $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $object->getId());
        /**
         * Not auto increment primary key support
         */
        if ($this->_isPkAutoIncrement) {            error_log("auto inc jamesk");            $data = $this->prepareDataForUpdate($object);
            if (!empty($data)) {                error_log("data not empty jamesk");                error_log(json_encode($data));                $this->getConnection()->update($this->getMainTable(), $data, $condition);                error_log("done saving jamesk"); <<should be succesful if it displays in error_log?
            }
        }
1 REPLY 1

Re: hi there, i have a question

Try to look at the page's source code (Ctrl + U) there should be an error message