A G Posted July 16, 2019 Share Posted July 16, 2019 Hello, In Cart (I use 5 step cart) I've added radiobox "stock_action" and I need to send this value to the Cart object because based on the value I would like to add some extra costs to order. In Cart.php Override I've declare $stock_action variable and added it to : public static $definition = array( 'table' => 'cart', 'primary' => 'id_cart', 'fields' => array( 'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'stock_action' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'gift_message' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage'), 'mobile_theme' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'delivery_option' => array('type' => self::TYPE_STRING), 'secure_key' => array('type' => self::TYPE_STRING, 'size' => 32), 'allow_seperated_package' =>array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); But the value of the stock_action radio isn't sending after clicking the button to the next step in Cart. Then I've tried to send that value using AJAX but I'm not sure how to send it correctly and catch it on the other side to assign to a Cart object. I've tried various combination of other functions in cart-summary.js and I came up with something like this: function setStockAction() { var val = $('input[name=stock_action]:checked').val(); $.ajax({ type: 'POST', headers: {'cache-control': 'no-cache'}, url: baseUri + '?rand=' + new Date().getTime(), async: true, cache: false, dataType: 'json', data: 'controller=cart' + '&ajax=true' + '&stock_action=' + val + '&token=' + static_token + '&allow_refresh=1', success: function(jsonData) { alert('ok!'); } }); } Am I on the right track or is there an easier way to do it in Prestashop? Thank you. Link to comment Share on other sites More sharing options...
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