Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor Shipping do not show for some product, but new entered products does #874

Closed
henmaker opened this issue Jul 16, 2020 · 8 comments
Closed

Comments

@henmaker
Copy link

It is weird that the vendor shipping do not display for some product, but new inserted product does, any idea why this happen?

@henmaker
Copy link
Author

There is something to do with this /dokan-pro/includes/functions-wc.php

Line 1406
function dokan_custom_split_shipping_packages( $packages ) {
$cart_content = WC()->cart->get_cart();
$seller_pack = array();
$packages = array();

foreach ( $cart_content as $key => $item ) {
    // If individual seller product shipping is disable then out from here
    if ( \WeDevs\DokanPro\Shipping\Methods\ProductShipping::is_product_disable_shipping( $item['product_id'] ) ) {
        continue;
    }

    $post_author = get_post_field( 'post_author', $item['data']->get_id() );
    $seller_pack[$post_author][$key] = $item;
}

foreach ( $seller_pack as $seller_id => $pack ) {
    $packages[] = array(
        'contents'        => $pack,
        'contents_cost'   => array_sum( wp_list_pluck( $pack, 'line_total' ) ),
        'applied_coupons' => WC()->cart->get_applied_coupons(),
        'user'            => array(
            'ID' => get_current_user_id(),
        ),
        'seller_id'       =>  $seller_id,
        'destination'     => array(
            'country'     => WC()->customer->get_shipping_country(),
            'state'       => WC()->customer->get_shipping_state(),
            'postcode'    => WC()->customer->get_shipping_postcode(),
            'city'        => WC()->customer->get_shipping_city(),
            'address'     => WC()->customer->get_shipping_address(),
            'address_2'   => WC()->customer->get_shipping_address_2()
        )
    );
}

return apply_filters( 'dokan_cart_shipping_packages', $packages );

}

Is there any way i can debug and find whether each product do contain post_author ID? As seems like some of my product do not, which is very weird....

@henmaker
Copy link
Author

Finally found the issue, it seems like the variation if created by the admin, the author will be mark as admin, instead of vendor themselves, as such, the shipping will return the admin as arthur_id, which will not match any vendor shipping. Im not sure how to fix from the script, what i can do is change all the variation author to the vendor ID via mysql, but this is painful, hope you guys can suggest a better solution.

@henmaker
Copy link
Author

I applied this fixed, hope this will help others, i replace this line:

$post_author = get_post_field( 'post_author', $item['data']->get_id() );

With this:

    if (!empty($parent_id) || $parent_id <> 0) {
        $post_author = get_post_field( 'post_author', $item['data']->get_parent_id() );
    } else {
        $post_author = get_post_field( 'post_author', $item['data']->get_id() );
    }

/*
Which will always return the parent id author, instead of variation product author, as that can be admin if admin add it.
*/

@kendesign
Copy link

Thank you, i was hoping that this will solve my issue, too. I use single vendor shipping, since last update there is no vendor shipping shown at old products but on new products it works like it did before ...

@henmaker
Copy link
Author

henmaker commented Aug 15, 2020

Thank you, i was hoping that this will solve my issue, too. I use single vendor shipping, since last update there is no vendor shipping shown at old products but on new products it works like it did before ...

i have to stick to their previous version for this to work, the developer seems didn't fix this on their latest version, and this changes won't help on their latest version. Not sure why.

tareq1988 pushed a commit that referenced this issue Oct 20, 2020
* fix: product variation author id update for product quick save fixed #874 #878 #883

* query limit increased in product query

* fix: codes updated with phpcs standard

* add translation in select option
@henmaker
Copy link
Author

henmaker commented Apr 9, 2021

I can ensure that from latest Version 3.2.4 and pro 3.2.1 this issue still the same not fixed.

@alamgircsebd
Copy link
Contributor

@henmaker if you still getting the issue please submit a ticket to support team with your site details, we will check it.

@henmaker
Copy link
Author

henmaker commented Apr 9, 2021

I need to point out that why your latest version is not fixed because your
includes/Upgrade/Upgrades/BackgroundProcesses/V_3_0_10_ProductAttributesAuthorId.php

            if ( $product_author != $variation_author_id ) {
                dokan_override_author_for_variations( $product, $product_author );
            }
            
            is only update the existing product and this process only run once.
            
            Once we added the product into the cart, say the new added product, that added by admin, not by vendor, but post author is vendor, and when admin help to add the variation, those variation are still not save with vendor author ID, instead, it is save with admin post author ID.
            
            As such, when come to 
            function dokan_custom_split_shipping_packages( $packages )

That from /dokan-pro/includes/functions-wc.php

This check will not return the variation post parent ID to return the author ID to match the shipping package.

My current fixed is, i applied this on /dokan-pro/includes/functions-wc.php

function dokan_custom_split_shipping_packages( $packages ) {
$cart_content = WC()->cart->get_cart();
$seller_pack = [];
$packages = [];

foreach ( $cart_content as $key => $item ) {
    // If individual seller product shipping is disable then out from here
    /*
    if ( \WeDevs\DokanPro\Shipping\Methods\ProductShipping::is_product_disable_shipping( $item['product_id'] ) ) {
        continue;
    }
    */

    $parent_id = $item['data']->get_parent_id();

    if (!empty($parent_id) || $parent_id <> 0) {
        $post_author = get_post_field( 'post_author', $item['data']->get_parent_id() );
    } else {
        $post_author = get_post_field( 'post_author', $item['data']->get_id() );
    }

    $seller_pack[ $post_author ][ $key ] = $item;
}

But im sure you guys. have better way to fixed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants