
<?php
    $helper = $this->helper("Magetop\Agency\Helper\Data");
    $product = $helper->getCurrentProduct();
    $productId = $product->getId();
    $type = $product->getTypeId();
    if ($productId) {
        $assignProdcuts = $helper->getAssignProducts($productId, '', 'ASC', false);
    }
    $mediaUrl = $helper->getBaseMediaUrl();
?>
<div class="wk-ap-product-details">
    <?php if ($productId && $assignProdcuts->getSize()): ?>
        <table>
            <thead>
                <th><?php echo __("Seller Info") ?></th>
                <th></th>
                <th><?php echo __("Condition") ?></th>
                <?php if ($type == "configurable"): ?>
                    <th><?php echo __("Associated Product") ?></th>
                <?php endif; ?>
                <th><?php echo __("Price") ?></th>
                <th><?php echo __("Quantity") ?></th>
            </thead>
        </div>
        <tbody>
            <?php foreach ($assignProdcuts as $product): ?>
                <?php
                    $assignId = $product->getId();
                    $price = $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($product->getPrice(), true, false);
                    $sellerId = $product->getSellerId();
                    $shopTitle = $product->getShopTitle();
                    if (!$shopTitle) {
                        $shopTitle = $product->getShopUrl();
                    }
                    $logo = $product->getLogoPic() != '' ? $product->getLogoPic():"noimage.png";
                    $logo = $mediaUrl.'avatar/'.$logo;
                    $baseImage = $product->getImage();
                    $condition = $product->getCondition();
                    if ($condition == 1) {
                        $condition = __("New");
                    } else {
                        $condition = __("Used");
                    }
                    $qty = $product->getQty();
                    if ($type == "configurable") {
                        $associatedProducts = $helper->getAssignedAssociatedProducts($assignId);
                        $productHtml = "";
                        $qtyHtml = "";
                        $priceHtml = "";
                        foreach ($associatedProducts as $associate) {
                            $productHtml .= "<div class='wk-ap-associate-name'>".$associate->getName()."</div>";
                            $qtyHtml .= "<div class='wk-ap-associate-name'>".$associate->getQty()."</div>";
                            $price = $this->helper('Magento\Framework\Pricing\Helper\Data')
                                        ->currency($associate->getPrice(), true, false);
                            $priceHtml .= "<div class='wk-ap-associate-name'>".$price."</div>";
                        }
                    }
                ?>
                <tr>
                    <td class="wk-ap-seller-logo"><img src="<?php echo $logo; ?>"></td>
                    <td><?php echo $shopTitle; ?></td>
                    <td><?php echo $condition; ?></td>
                    <?php if ($type == "configurable"): ?>
                        <td><?php echo $productHtml; ?></td>
                        <td><?php echo $priceHtml; ?></td>
                        <td><?php echo $qtyHtml; ?></td>
                    <?php else: ?>
                        <td><?php echo $price; ?></td>
                        <td><?php echo $qty; ?></td>
                    <?php endif; ?>
                    
                </tr>
            <?php endforeach; ?>
        </tbody>
    <?php else: ?>
        <?php echo __('No assigned products'); ?>
    <?php endif; ?>
</div>