if ($category_fee_pub > 0) {
                    payment_pro_cart_add('PUB' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'], sprintf(__('Publish fee for listing %d', 'payment_pro'), $item['pk_i_id']), $category_fee_pub);
                }
            }
            echo json_encode(array('error' => 0, 'msg' => __('Product added to your cart', 'payment_pro')));
            die;
        }
    }
    echo json_encode(array('error' => 1, 'msg' => __('This listing does not belong to you', 'payment_pro')));
    die;
}
if (Params::getParam('pub') != '') {
    $pub = Params::getParam('pub');
    if (!ModelPaymentPro::newInstance()->isEnabled($pub)) {
        echo json_encode(array('error' => 1, 'msg' => __('This listing is not enabled yet', 'payment_pro')));
        die;
    }
    if ($pub != Params::getParam('prm')) {
        $item = Item::newInstance()->findByPrimaryKey($pub);
    }
    if ($item['fk_i_user_id'] == null || $item['fk_i_user_id'] != null && $item['fk_i_user_id'] == osc_logged_user_id()) {
        $category_fee = ModelPaymentPro::newInstance()->getPublishPrice($item['fk_i_category_id']);
        if ($category_fee > 0) {
            payment_pro_cart_add('PUB' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'], sprintf(__('Publish fee for listing %d', 'payment_pro'), $item['pk_i_id']), $category_fee);
            echo json_encode(array('error' => 0, 'msg' => __('Product added to your cart', 'payment_pro')));
            die;
        }
    }
    echo json_encode(array('error' => 1, 'msg' => __('This listing does not belong to you', 'payment_pro')));
    die;
}
function payment_pro_publish($item, $do_edit = false)
{
    $item = Item::newInstance()->findByPrimaryKey($item['pk_i_id']);
    if (!$do_edit) {
        ModelPaymentPro::newInstance()->createItem($item['pk_i_id'], 0, null, null, $item['b_enabled']);
    }
    $checkout = false;
    $category_fee = 0;
    $premium_fee = 0;
    // Need to pay to publish ?
    if (osc_get_preference('pay_per_post', 'payment_pro') == 1) {
        $is_paid = false;
        if ($do_edit) {
            $is_paid = ModelPaymentPro::newInstance()->publishFeeIsPaid($item['pk_i_id']);
        }
        if (!$is_paid) {
            $category_fee = ModelPaymentPro::newInstance()->getPublishPrice($item['fk_i_category_id']);
            if ($category_fee > 0) {
                // Catch and re-set FlashMessages
                osc_resend_flash_messages();
                $mItems = new ItemActions(false);
                $mItems->disable($item['pk_i_id']);
                if ($item['b_enabled'] == 1) {
                    ModelPaymentPro::newInstance()->enableItem($item['pk_i_id']);
                    payment_pro_cart_add('PUB' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'], sprintf(__('Publish fee for item %s', 'payment_pro'), $item['pk_i_id']), $category_fee, 1);
                    $checkout = true;
                }
            } else {
                // PRICE IS ZERO
                if (!$do_edit) {
                    ModelPaymentPro::newInstance()->payPostItem($item['pk_i_id']);
                    ModelPaymentPro::newInstance()->createItem($item['pk_i_id'], 1, null, null, $item['b_enabled']);
                }
            }
        }
    }
    if (osc_get_preference('allow_premium', 'payment_pro') == 1) {
        $premium_fee = ModelPaymentPro::newInstance()->getPremiumPrice($item['fk_i_category_id']);
        if ($premium_fee > 0) {
            if (Params::getParam('payment_pro_make_premium') == 1) {
                if ($item['b_enabled'] == 1) {
                    payment_pro_cart_add('PRM' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'], sprintf(__('Premium fee for item %s', 'payment_pro'), $item['pk_i_id']), $premium_fee, 1);
                    $checkout = true;
                }
            }
        }
    }
    if ($checkout && !OC_ADMIN) {
        ModelPaymentPro::newInstance()->addQueue(date('Y-m-d H:i:s', time() + 1800), $item['pk_i_id'], $category_fee != 0, $premium_fee != 0);
        osc_redirect_to(osc_route_url('payment-pro-checkout', array('itemId' => $item['pk_i_id'])));
    }
}