Adik Posted October 21, 2020 Posted October 21, 2020 (edited) Hello, I would like to create an additional checkbox in the Quantities tab on Admin Product Page. After checking the Ext_warehouse checkbox, the information on the product's availability in external storage will appear on the product page. So much for the theory, below the code 🙂 quantities.tpl <div class="form-group"> <div class="col-lg-1"> <span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="ext_warehouse" type="checkbox" multilang="false"}</span></div> <label class="control-label col-lg-2" for="ext_warehouse"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='external Warehouse'"> {l s='external Warehouse'} </span> </label> <div class="col-lg-9"> <input class="admin-form-check form-control" type="checkbox" id="ext_warehouse" name="ext_warehousee" value="1" {if $product->ext_warehouse}checked{/if}/> </div> </div> added to override/classes/Product.php: public $ext_warehouse = false; function __construct( $id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null ) { Product::$definition['fields']['ext_warehouse'] = array('type' => self::TYPE_BOOL, 'lang' => false, 'validate' => 'isBool'); } I've created override/controllers/admin/AdminProductsController.php: class AdminProductsController extends AdminProductsControllerCore { protected function copyFromPost(&$object, $table) { if ( $this->isTabSubmitted( 'Quantities' ) ) { if ( $this->checkMultishopBox( 'ext_warehouse', $this->context ) ) { $object->ext_warehouse = (int) Tools::getValue( 'ext_warehouse' ); } } } } Unfortunately, an error appears on the product page: Product not found There's also error on Admin product page: The object cannot be loaded (or found) Edited October 21, 2020 by Adik
datakick Posted October 21, 2020 Posted October 21, 2020 You need to call parent constructor in your override file. It should look something like this class Product extends ProductCore { public $ext_warehouse = false; function __construct( $id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null ) { static::$definition['fields']['ext_warehouse'] = array('type' => self::TYPE_BOOL, 'lang' => false, 'validate' => 'isBool'); parent::__construct($id_product, $full, $id_lang, $id_shop, $context); } } Also, you need to create the field in database table, but I guess you already did that.
Adik Posted October 21, 2020 Author Posted October 21, 2020 (edited) Hello Petr, Thank you, could you look what's wrong with override/controllers/admin/AdminProductsController.php the translations in the fields below (Products->Quantities) are not saved anymore Displayed text when in-stock Displayed text when backordering is allow protected function copyFromPost(&$object, $table) { if ( $this->isTabSubmitted( 'Quantities' ) ) { if ( $this->checkMultishopBox( 'ext_warehouse', $this->context ) ) { $object->ext_warehouse = (int) Tools::getValue( 'ext_warehouse' ); } } } Edited October 21, 2020 by Adik
Adik Posted October 21, 2020 Author Posted October 21, 2020 (edited) Ok, now it's works when I've added parent::copyFromPost($object, $table); Unfortunately only in test store. 😶 In the production shop (also ThirtyBees v1.1.0, I've use Cloudflare), when I save in admin panel product Qty tab the values in the tb_product table do not change. What's wrong here? If I change the values in the tb_product table, they are read correctly in the admin panel product tab... Code is 1:1 copied. File cache/class_index.php was deleted. Another difference that reminded me. The test store was installed from the 1.1.0 installer, the production version was updated several times (initial is 1.0.2) Production store - Obsolete files (11) admin/go-to-product.php admin/ajax-load-states-form.php admin/go-to-customer.php admin/ajax-get-order-details.php admin/CoreUpdaterBackup-2020-10-10--17-37-06 admin/ajax-get-immediate-orders.php admin/ajax-set-order-state.php admin/ajax-get-orders-fields.php admin/ajax-update-shipping-number.php Peter - do you have any idea what could be the reason for this? 😥 Edited October 21, 2020 by Adik
datakick Posted October 22, 2020 Posted October 22, 2020 Works fine for me. I've tested on 1.1.x. Looks like you have something extra on your prod store. You'll need to debug
Adik Posted October 22, 2020 Author Posted October 22, 2020 (edited) I checked on the second store, which was updated several times - saving by the admin panel also does not work. How can I find out what is causing the problem? Disable each module? Edited October 22, 2020 by Adik
datakick Posted October 22, 2020 Posted October 22, 2020 You should put debug in various place to figure out what's wrong. I would start by changing copyFromPost, and adding something like this ... d(['ext_warehouse' => Tools::getValue('ext_warehouse')]); $object->ext_warehouse = (int) Tools::getValue( 'ext_warehouse' ); ... i
Adik Posted October 22, 2020 Author Posted October 22, 2020 After placing your code in AdminProductsController.php I have: Array ( [ext_warehouse] => 1 ) END
Adik Posted October 25, 2020 Author Posted October 25, 2020 (edited) On 10/22/2020 at 12:08 PM, datakick said: Quote You should put debug in various place to figure out what's wrong. Do you have any idea what else can be checked? Can the datakick module be used to check stock levels from an external xml file (access via FTP) and then change the status of products? Edited October 25, 2020 by Adik
datakick Posted October 25, 2020 Posted October 25, 2020 14 minutes ago, Adik said: Do you have any idea what else can be checked? There are many things that could be wrong. You need to look into the code, follow the flow, and print debug messages along the way. That will lead you to the root cause 14 minutes ago, Adik said: Can the datakick module be used to check stock levels from an external xml file (access via FTP) and then change the status of products? Yes. Datakick contains xml import functionality that can be used for that purpose
Adik Posted October 25, 2020 Author Posted October 25, 2020 5 hours ago, datakick said: Yes. Datakick contains xml import functionality that can be used for that purpose Are you planning to add support for csv files in the this year? Many vendors export their data in this format.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now