/**
  * @return \DVDoug\BoxPacker\PackedBoxList
  */
 public function getPackages()
 {
     $packer = new ClerkPacker();
     $boxes = StoreClerkPackage::getPackages();
     foreach ($boxes as $box) {
         $packer->addBox($box);
     }
     $cartItems = StoreCart::getCart();
     foreach ($cartItems as $cartItem) {
         $product = StoreProduct::getByID((int) $cartItem['product']['pID']);
         $description = $product->getProductName();
         $width = StoreCalculator::convertToMM($product->getDimensions('w'));
         $length = StoreCalculator::convertToMM($product->getDimensions('l'));
         $depth = StoreCalculator::convertToMM($product->getDimensions('h'));
         $weight = StoreCalculator::convertToGrams($product->getProductWeight());
         $packer->addItem(new StoreClerkItem($description, $width, $length, $depth, $weight));
         //TODO: If an item doesn't fit in any box, make it it's own box.
     }
     return $packer->pack();
 }
 public static function getGroupsForProduct(StoreProduct $product)
 {
     $db = Database::connection();
     $em = $db->getEntityManager();
     $groups = $em->getRepository('Concrete\\Package\\VividStore\\Src\\VividStore\\Product\\ProductGroup')->findBy(array('pID' => $product->getProductID()));
     foreach ($groups as $key => $value) {
         $group = new StoreGroup\Group();
         $groups[$key]->gName = $group->getByID($groups[$key]->gID)->getGroupName();
     }
     return $groups;
 }
 public function submitPayment()
 {
     $crypt = Loader::helper('encryption');
     $paypal = new \Concrete\Package\PaypalExpressVividStore\Src\VividStore\Payment\Methods\PaypalExpress\Helpers\PaypalExpressHelper();
     $totals = VividCart::getTotals();
     if (Config::get('vividstore.paypalExpressMode') == 'test') {
         $type = 'sandbox';
     } else {
         $type = 'live';
     }
     $invoice = Invoice::get();
     $conf = ['type' => $type, 'username' => Config::get('vividstore.paypalExpressUsername'), 'password' => Config::get('vividstore.paypalExpressPassword'), 'signature' => Config::get('vividstore.paypalExpressSignature'), 'notify_url' => (string) URL::to('/paypal_express_vivid_store/notify'), 'cancel_url' => (string) URL::to('/paypal_express_vivid_store/cancel'), 'return_url' => (string) URL::to('/paypal_express_vivid_store/return'), 'cart_total' => $totals['total'], 'cart_subtotal' => $totals['subTotal'], 'cart_tax' => $totals['taxTotal'], 'cart_shipping' => $totals['shippingTotal'], 'invoice' => $crypt->encrypt($invoice), 'description' => t(SITE), 'currency_code' => Config::get('vividstore.paypalExpressCurrencyCode'), 'payment_action' => Config::get('vividstore.paypalExpressTransactionType')];
     $paypal->setConfig($conf);
     if (isset($_GET['token']) && isset($_GET['PayerID'])) {
         $token = urldecode($_GET['token']);
         $payer_id = urldecode($_GET['PayerID']);
         $data_get = $paypal->getExpressCheckout($token, $payer_id);
         $response = $paypal->makeRequest($data_get, $type);
         if ($response['ACK'] == 'Success') {
             $data_do = $paypal->doExpressCheckout($token, $payer_id);
             $response = $paypal->makeRequest($data_do, $type);
             if ($response['ACK'] == 'Success') {
                 return true;
             }
         }
     } else {
         $items = [];
         $cart = Session::get('cart');
         if ($cart) {
             foreach ($cart as $cartItem) {
                 $pID = $cartItem['product']['pID'];
                 $qty = $cartItem['product']['qty'];
                 $product = VividProduct::getByID($pID);
                 if (is_object($product)) {
                     $tempItem = [];
                     $tempItem['name'] = $product->getProductName();
                     $tempItem['desc'] = strip_tags($product->getProductDesc());
                     $tempItem['price'] = $product->getFormattedPrice();
                     $tempItem['qty'] = $qty;
                     $items[] = $tempItem;
                 }
             }
         }
         $configData = [];
         $configData['items'] = $items;
         $configData['item_sum'] = $totals['total'];
         $data = $paypal->setExpressCheckout($configData);
         $response = $paypal->makeRequest($data, $type);
         if ($response['ACK'] == 'Success') {
             //Redirect to paypal payment page
             header('Location: ' . $paypal->getPaypalUrl($response['TOKEN']));
             exit;
         } else {
             return ['error' => 1, 'errorMessage' => print_r($response, true)];
         }
     }
 }
Exemple #4
0
 public function add()
 {
     $data = $this->post();
     VividCart::add($data);
     $product = VividProduct::getByID($data['pID']);
     $returndata = array('success' => true, 'quantity' => (int) $data['quantity'], 'product' => $product);
     echo json_encode($returndata);
     exit;
 }
 public function getProductModal()
 {
     $pID = $this->post('pID');
     $product = StoreProduct::getByID($pID);
     if (Filesystem::exists(DIR_BASE . "/application/elements/product_modal.php")) {
         View::element("product_modal", array("product" => $product));
     } else {
         View::element("product_modal", array("product" => $product), "vivid_store");
     }
 }
Exemple #6
0
 public function view()
 {
     if ($this->productLocation == 'page') {
         $cID = Page::getCurrentPage()->getCollectionID();
         $p = VividProduct::getByCollectionID($cID);
     } else {
         $p = VividProduct::getByID($this->pID);
     }
     $this->set('p', $p);
 }
Exemple #7
0
 public function add()
 {
     $data = $this->post();
     $result = StoreCart::add($data);
     $added = $result['added'];
     $product = StoreProduct::getByID($data['pID']);
     $productdata['pAutoCheckout'] = $product->autoCheckout();
     $productdata['pName'] = $product->getProductName();
     $returndata = array('success' => true, 'quantity' => (int) $data['quantity'], 'added' => $added, 'product' => $productdata, 'action' => 'add');
     echo json_encode($returndata);
     exit;
 }
Exemple #8
0
 public function getTaxForProduct($cartItem)
 {
     $product = StoreProduct::getByID($cartItem['product']['pID']);
     $qty = $cartItem['product']['qty'];
     $taxRates = self::getTaxRates();
     $taxes = array();
     if (count($taxRates) > 0) {
         foreach ($taxRates as $taxRate) {
             if ($taxRate->isTaxable()) {
                 $taxAmount = $taxRate->calculateProduct($product, $qty);
                 $taxes[] = array('name' => $taxRate->getTaxLabel(), 'taxamount' => $taxAmount, 'based' => $taxRate->getTaxBasedOn());
             }
         }
     }
     return $taxes;
 }
 public static function getSubTotal()
 {
     $cart = StoreCart::getCart();
     $subtotal = 0;
     if ($cart) {
         foreach ($cart as $cartItem) {
             $pID = $cartItem['product']['pID'];
             $qty = $cartItem['product']['qty'];
             $product = StoreProduct::getByID($pID);
             if (is_object($product)) {
                 $productSubTotal = $product->getActivePrice() * $qty;
                 $subtotal = $subtotal + $productSubTotal;
             }
         }
     }
     return max($subtotal, 0);
 }
 public function setProducts()
 {
     $products = array();
     foreach ($this->orderItems as $oi) {
         if (array_key_exists($oi->getProductID(), $products)) {
             $products[$oi->getProductID()]['pricePaid'] = intval($products[$oi->getProductID()]['pricePaid']) + intval($oi->getPricePaid());
             $products[$oi->getProductID()]['quantity'] = intval($products[$oi->getProductID()]['quantity']) + intval($oi->getQty());
         } else {
             //first figure out what the current product name is.
             //if the product no longer exist, the OI name is fine.
             $product = StoreProduct::getByID($oi->getProductID());
             if (is_object($product)) {
                 $name = $product->getProductName();
             } else {
                 $name = $oi->getProductName();
             }
             $products[$oi->getProductID()] = array('name' => $name, 'pID' => $oi->getProductID(), 'pricePaid' => intval($oi->getPricePaid()) * intval($oi->getQty()), 'quantity' => intval($oi->getQty()));
         }
     }
     $this->products = $products;
 }
 public static function add(StoreProduct $product, $pogID, $name, $sort)
 {
     $productOptionItem = new self();
     $pID = $product->getProductID();
     $productOptionItem->setProductID($pID);
     $productOptionItem->setProductOptionGroupID($pogID);
     $productOptionItem->setName($name);
     $productOptionItem->setSort($sort);
     $obj->save();
     return $productOptionItem;
 }
Exemple #12
0
 public function calculate()
 {
     $cart = StoreCart::getCart();
     $taxtotal = 0;
     if ($cart) {
         foreach ($cart as $cartItem) {
             $pID = $cartItem['product']['pID'];
             $qty = $cartItem['product']['qty'];
             $product = StoreProduct::getByID($pID);
             if (is_object($product)) {
                 if ($product->isTaxable()) {
                     //if this tax rate is in the tax class associated with this product
                     if (is_object($product->getTaxClass())) {
                         if ($product->getTaxClass()->taxClassContainsTaxRate($this)) {
                             $taxCalc = Config::get('vividstore.calculation');
                             if ($taxCalc == 'extract') {
                                 $taxrate = 10 / ($this->getTaxRate() + 100);
                             } else {
                                 $taxrate = $this->getTaxRate() / 100;
                             }
                             switch ($this->getTaxBasedOn()) {
                                 case "subtotal":
                                     $productSubTotal = $product->getActivePrice() * $qty;
                                     $tax = $taxrate * $productSubTotal;
                                     $taxtotal = $taxtotal + $tax;
                                     break;
                                 case "grandtotal":
                                     $productSubTotal = $product->getActivePrice() * $qty;
                                     $shippingTotal = StorePrice::getFloat(StoreCalculator::getShippingTotal());
                                     $taxableTotal = $productSubTotal + $shippingTotal;
                                     $tax = $taxrate * $taxableTotal;
                                     $taxtotal = $taxtotal + $tax;
                                     break;
                             }
                         }
                     }
                     //if in products tax class
                 }
                 //if product is taxable
             }
             //if obj
         }
         //foreach
     }
     //if cart
     return $taxtotal;
 }
 public function getQuantityBasedRate($shippableItems)
 {
     $baserate = $this->getBaseRate();
     $peritemrate = $this->getPerItemRate();
     $totalQty = 0;
     //go through items
     foreach ($shippableItems as $item) {
         //check if items are shippable
         $product = VividProduct::getByID($item['product']['pID']);
         if ($product->isShippable()) {
             $totalQty = $totalQty + $item['product']['qty'];
         }
     }
     if ($totalQty > 1) {
         $shippingTotal = $baserate + ($totalQty - 1) * $peritemrate;
     } elseif ($totalQty == 1) {
         $shippingTotal = $baserate;
     }
     return $shippingTotal;
 }
Exemple #14
0
?>
</h2>

        <input id='cartURL' type='hidden' data-cart-url='<?php 
echo View::url("/cart/");
?>
'>

        <ul class="cart-page-cart-list">
            <?php 
if ($cart) {
    $i = 1;
    foreach ($cart as $k => $cartItem) {
        $pID = $cartItem['product']['pID'];
        $qty = $cartItem['product']['qty'];
        $product = StoreProduct::getByID($pID);
        if ($cartItem['product']['variation']) {
            $product->setVariation($cartItem['product']['variation']);
        }
        if ($i % 2 == 0) {
            $classes = " striped";
        } else {
            $classes = "";
        }
        if (is_object($product)) {
            ?>

                        <li class="cart-page-cart-list-item clearfix<?php 
            echo $classes;
            ?>
" data-instance-id="<?php 
 public function update(StoreProduct $product, $name, $sort, $hidden = false)
 {
     $pID = $product->getProductID();
     $this->setProductID($pID);
     $this->setName($name);
     $this->setSort($sort);
     $this->setHidden($hidden);
     $this->save();
     return $this;
 }
Exemple #16
0
defined('C5_EXECUTE') or die("Access Denied.");
$listViews = array('view', 'updated', 'removed', 'success');
$addViews = array('add', 'edit', 'save');
$groupViews = array('groups', 'groupadded', 'addgroup');
$attributeViews = array('attributes', 'attributeadded', 'attributeremoved');
$ps = Core::make('helper/form/page_selector');
use Concrete\Package\VividStore\Src\VividStore\Groups\ProductGroup as VividProductGroup;
use Concrete\Package\VividStore\Src\VividStore\Product\Product as VividProduct;
?>

<?php 
if (in_array($controller->getTask(), $addViews)) {
    //if adding or editing a product
    if (!is_object($p)) {
        $p = new VividProduct();
        //does nothing other than shutup errors.}
    }
    $pID = $p->getProductID();
    ?>

    <?php 
    if ($pID > 0) {
        ?>
    <div class="ccm-dashboard-header-buttons">
        <form method="post" id="delete" action="<?php 
        echo View::url('/dashboard/store/products/delete/', $pID);
        ?>
" >
            <button class="btn btn-danger"><?php 
        echo t("Delete Product");
Exemple #17
0
            </div>
            <?php 
            if ($cartItem['productAttributes']) {
                ?>
            <div class="cart-list-item-attributes">
                <?php 
                foreach ($cartItem['productAttributes'] as $groupID => $valID) {
                    $groupID = str_replace("pog", "", $groupID);
                    ?>
                    <div class="cart-list-item-attribute">
                        <span class="cart-list-item-attribute-label"><?php 
                    echo VividProduct::getProductOptionGroupNameByID($groupID);
                    ?>
:</span>
                        <span class="cart-list-item-attribute-value"><?php 
                    echo VividProduct::getProductOptionValueByID($valID);
                    ?>
</span>
                    </div>
                <?php 
                }
                ?>
            </div>    
            <?php 
            }
            ?>
            
            
        </li>
    
    <?php 
Exemple #18
0
 public function getProductObject($pID = null)
 {
     return VividProduct::getByID($this->pID);
 }
Exemple #19
0
defined('C5_EXECUTE') or die("Access Denied.");
$listViews = array('view', 'updated', 'removed', 'success');
$addViews = array('add', 'edit', 'save');
$groupViews = array('groups', 'groupadded', 'addgroup');
$attributeViews = array('attributes', 'attributeadded', 'attributeremoved');
$ps = Core::make('helper/form/page_selector');
use Config;
use Concrete\Package\VividStore\Src\VividStore\Groups\ProductGroup as VividProductGroup;
use Concrete\Package\VividStore\Src\VividStore\Product\Product as VividProduct;
?>

<?php 
if (in_array($controller->getTask(), $addViews)) {
    //if adding or editing a product
    if (!is_object($p)) {
        $p = new VividProduct();
        //does nothing other than shutup errors.}
    }
    $pID = $p->getProductID();
    ?>

    <?php 
    if ($pID > 0) {
        ?>
    <div class="ccm-dashboard-header-buttons">
        <form method="post" id="delete" action="<?php 
        echo View::url('/dashboard/store/products/delete/', $pID);
        ?>
" >
            <button class="btn btn-danger"><?php 
        echo t("Delete Product");
Exemple #20
0
 public function requiresLogin()
 {
     if (self::getCart()) {
         foreach (self::getCart() as $item) {
             $product = VividProduct::getByID($item['product']['pID']);
             if ($product) {
                 if ($product->hasUserGroups() || $product->hasDigitalDownload()) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #21
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
$listViews = array('view', 'updated', 'removed', 'success');
$addViews = array('add', 'edit', 'save');
$groupViews = array('groups', 'groupadded', 'addgroup');
$attributeViews = array('attributes', 'attributeadded', 'attributeremoved');
$ps = Core::make('helper/form/page_selector');
use Concrete\Package\VividStore\Src\VividStore\Product\Product as StoreProduct;
?>

<?php 
if (in_array($controller->getTask(), $addViews)) {
    //if adding or editing a product
    if (!is_object($p)) {
        $p = new StoreProduct();
        //does nothing other than shutup errors.}
    }
    $pID = $p->getProductID();
    ?>

    <?php 
    if ($pID > 0) {
        ?>
    <div class="ccm-dashboard-header-buttons">
        <form method="post" id="delete" action="<?php 
        echo View::url('/dashboard/store/products/delete/', $pID);
        ?>
" >
            <button class="btn btn-danger"><?php 
        echo t("Delete Product");
Exemple #22
0
 public function save()
 {
     $data = $this->post();
     if ($data['pID']) {
         $this->edit($data['pID']);
     } else {
         $this->add();
     }
     if ($this->isPost()) {
         $errors = $this->validate($data);
         $this->error = null;
         //clear errors
         $this->error = $errors;
         if (!$errors->has()) {
             $product = VividProduct::save($data);
             $aks = StoreProductKey::getList();
             foreach ($aks as $uak) {
                 $uak->saveAttributeForm($product);
             }
             if ($data['pID']) {
                 $this->redirect('/dashboard/store/products/', 'updated');
             } else {
                 $this->redirect('/dashboard/store/products/', 'success');
             }
         }
         //if no errors
     }
     //if post
 }
Exemple #23
0
 public function getResult($queryRow)
 {
     return Product::getByID($queryRow['pID']);
 }
Exemple #24
0
use Concrete\Package\VividStore\Src\VividStore\Product\Product as VividProduct;
?>
	    
    <?php 
if (in_array($controller->getTask(), $addViews)) {
    //if adding a product
    ?>
    
        <form method="post" action="<?php 
    echo $view->action('save');
    ?>
">
        
            <?php 
    if (!is_object($p)) {
        $p = new VividProduct();
        //does nothing other than shutup errors.
    }
    ?>
            <input type="hidden" name="pID" value="<?php 
    echo $p->getProductID();
    ?>
"/>
            

            <div class="row">
                <div class="col-sm-4">
                    <div class="vivid-store-side-panel">
                        <ul>
                            <li><a href="#product-overview" data-pane-toggle class="active"><?php 
    echo t('Overview');
Exemple #25
0
 public function createsAccount()
 {
     if (self::getCart()) {
         foreach (self::getCart() as $item) {
             $product = StoreProduct::getByID($item['product']['pID']);
             if ($product) {
                 if ($product->createsLogin()) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #26
0
 public function save($data)
 {
     $db = Database::get();
     if ($data['pID']) {
         //if we know the pID, we're updating.
         $pID = $data['pID'];
         //update product details
         $vals = array($data['gID'], $data['pName'], $data['pDesc'], $data['pDetail'], $data['pPrice'], $data['pFeatured'], $data['pQty'], $data['pTaxable'], $data['pfID'], $data['pActive'], $data['pShippable'], $data['pWidth'], $data['pHeight'], $data['pLength'], $data['pWeight'], $data['pID']);
         $db->Execute('UPDATE VividStoreProducts SET gID=?,pName=?,pDesc=?,pDetail=?,pPrice=?,pFeatured=?,pQty=?,pTaxable=?,pfID=?,pActive=?,pShippable=?,pWidth=?,pHeight=?,pLength=?,pWeight=? WHERE pID = ?', $vals);
         //update additional images
         $db->Execute('DELETE FROM VividStoreProductImages WHERE pID = ?', $data['pID']);
         $count = count($data['pifID']);
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($data['pID'], $data['pifID'][$i], $data['piSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductImages (pID,pifID,piSort) VALUES (?,?,?)", $vals);
             }
         }
         //update user groups
         $db->Execute('DELETE FROM VividStoreProductUserGroups WHERE pID = ?', $data['pID']);
         if (!empty($data['pUserGroups'])) {
             foreach ($data['pUserGroups'] as $gID) {
                 $vals = array($data['pID'], $gID);
                 $db->Execute("INSERT INTO VividStoreProductUserGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //update product groups
         $db->Execute('DELETE FROM VividStoreProductGroups WHERE pID = ?', $data['pID']);
         if (!empty($data['pProductGroups'])) {
             foreach ($data['pProductGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //update option groups
         $db->Execute('DELETE FROM VividStoreProductOptionGroups WHERE pID = ?', $data['pID']);
         $db->Execute('DELETE FROM VividStoreProductOptionItems WHERE pID = ?', $data['pID']);
         $count = count($data['pogSort']);
         $ii = 0;
         //set counter for items
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($data['pID'], $data['pogName'][$i], $data['pogSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductOptionGroups (pID,pogName,pogSort) VALUES (?,?,?)", $vals);
                 //add option items
                 $pogID = $db->lastInsertId();
                 $itemsInGroup = count($data['optGroup' . $i]);
                 if ($itemsInGroup > 0) {
                     for ($gi = 0; $gi < $itemsInGroup; $gi++, $ii++) {
                         $vals = array($data['pID'], $pogID, $data['poiName'][$ii], $data['poiSort'][$ii]);
                         $db->Execute("INSERT INTO VividStoreProductOptionItems (pID,pogID,poiName,poiSort) VALUES (?,?,?,?)", $vals);
                     }
                 }
             }
         }
     } else {
         //else, we don't know it, so we're adding
         $dt = Core::make('helper/date');
         $now = $dt->getLocalDateTime();
         //add product details
         $vals = array($data['gID'], $data['pName'], $data['pDesc'], $data['pDetail'], $data['pPrice'], $data['pFeatured'], $data['pQty'], $data['pTaxable'], $data['pfID'], $data['pActive'], $data['pShippable'], $data['pWidth'], $data['pHeight'], $data['pLength'], $data['pWeight'], $now);
         $db->Execute("INSERT INTO VividStoreProducts (gID,pName,pDesc,pDetail,pPrice,pFeatured,pQty,pTaxable,pfID,pActive,pShippable,pWidth,pHeight,pLength,pWeight,pDateAdded) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", $vals);
         //add additional images
         $pID = $db->lastInsertId();
         $count = count($data['pifID']);
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($pID, $data['pifID'][$i], $data['piSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductImages (pID,pifID,piSort) VALUES (?,?,?)", $vals);
             }
         }
         //insert user groups
         if (!empty($data['pUserGroups'])) {
             foreach ($data['pUserGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductUserGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //insert product groups
         if (!empty($data['pProductGroups'])) {
             foreach ($data['pProductGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //add option groups
         $count = count($data['pogSort']);
         $ii = 0;
         //set counter for items
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($pID, $data['pogName'][$i], $data['pogSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductOptionGroups (pID,pogName,pogSort) VALUES (?,?,?)", $vals);
                 //add option items
                 $pogID = $db->lastInsertId();
                 $itemsInGroup = count($data['optGroup' . $i]);
                 if ($itemsInGroup > 0) {
                     for ($gi = 0; $gi < $itemsInGroup; $gi++, $ii++) {
                         $vals = array($pID, $pogID, $data['poiName'][$ii], $data['poiSort'][$ii]);
                         $db->Execute("INSERT INTO VividStoreProductOptionItems (pID,pogID,poiName,poiSort) VALUES (?,?,?,?)", $vals);
                     }
                 }
             }
         }
         $product = Product::getByID($pID);
         $product->generatePage($data['selectPageTemplate']);
     }
     //save files
     $db->Execute("DELETE FROM VividStoreDigitalFiles WHERE pID=?", $pID);
     $u = User::getByUserID(1);
     $ui = \UserInfo::getByID($u->getUserID());
     if ($data['dffID']) {
         foreach ($data['dffID'] as $dffID) {
             if ($dffID) {
                 $db->Execute("INSERT INTO VividStoreDigitalFiles(dffID,pID) VALUES (?,?)", array($dffID, $pID));
                 $fileObj = File::getByID($dffID);
                 $fs = \FileSet::getByName("Digital Downloads");
                 $fs->addFileToSet($fileObj);
                 $fileObj->resetPermissions(1);
                 $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
                 $pk->setPermissionObject($fileObj);
                 $pao = $pk->getPermissionAssignmentObject();
                 $groupEntity = \Concrete\Core\Permission\Access\Entity\GroupEntity::getOrCreate(\Group::getByID(GUEST_GROUP_ID));
                 $pa = $pk->getPermissionAccessObject();
                 if ($pa) {
                     $pa->removeListItem($groupEntity);
                     $pao->assignPermissionAccess($pa);
                 }
             }
         }
     }
     $db->Execute("DELETE FROM VividStoreProductLocations where pID = ?", array($pID));
     foreach ($data['cID'] as $cID) {
         if ($cID > 0) {
             $db->Execute("REPLACE INTO VividStoreProductLocations(pID,cID) VALUES (?,?)", array($pID, (int) $cID));
         }
     }
     $product = Product::getByID($pID);
     return $product;
 }
Exemple #27
0
 public function add($data, $pm, $status = null)
 {
     $taxBased = Config::get('vividstore.taxBased');
     $taxlabel = Config::get('vividstore.taxName');
     $this->set('taxlabel', $taxlabel);
     $taxCalc = Config::get('vividstore.calculation');
     $db = Database::get();
     //get who ordered it
     $customer = new Customer();
     //what time is it?
     $dt = Core::make('helper/date');
     $now = $dt->getLocalDateTime();
     //get the price details
     $shipping = VividCart::getShippingTotal();
     $shipping = Price::formatFloat($shipping);
     $taxvalue = VividCart::getTaxTotal();
     $taxName = Config::get('vividstore.taxName');
     $total = VividCart::getTotal();
     $total = Price::formatFloat($total);
     $tax = 0;
     $taxIncluded = 0;
     if ($taxCalc == 'extract') {
         $taxIncluded = $taxvalue;
     } else {
         $tax = $taxvalue;
     }
     $tax = Price::formatFloat($tax);
     //get payment method
     $pmID = $pm->getPaymentMethodID();
     //add the order
     $vals = array($customer->getUserID(), $now, $pmID, $shipping, $tax, $taxIncluded, $taxName, $total);
     $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmID,oShippingTotal,oTax,oTaxIncluded,oTaxName,oTotal) VALUES (?,?,?,?,?,?,?,?)", $vals);
     $oID = $db->lastInsertId();
     $order = Order::getByID($oID);
     if ($status) {
         $order->updateStatus($status);
     } else {
         $order->updateStatus(OrderStatus::getStartingStatus()->getHandle());
     }
     $order->setAttribute("email", $customer->getEmail());
     $order->setAttribute("billing_first_name", $customer->getValue("billing_first_name"));
     $order->setAttribute("billing_last_name", $customer->getValue("billing_last_name"));
     $order->setAttribute("billing_address", $customer->getValueArray("billing_address"));
     $order->setAttribute("billing_phone", $customer->getValue("billing_phone"));
     $order->setAttribute("shipping_first_name", $customer->getValue("shipping_first_name"));
     $order->setAttribute("shipping_last_name", $customer->getValue("shipping_last_name"));
     $order->setAttribute("shipping_address", $customer->getValueArray("shipping_address"));
     $customer->setLastOrderID($oID);
     //add the order items
     $cart = VividCart::getCart();
     foreach ($cart as $cartItem) {
         $taxvalue = VividCart::getTaxProduct($cartItem['product']['pID']);
         $tax = 0;
         $taxIncluded = 0;
         if ($taxCalc == 'extract') {
             $taxIncluded = $taxvalue;
         } else {
             $tax = $taxvalue;
         }
         $productTaxName = $taxName;
         if ($taxvalue == 0) {
             $productTaxName = '';
         }
         OrderItem::add($cartItem, $oID, $tax, $taxIncluded, $productTaxName);
         $product = VividProduct::getByID($cartItem['product']['pID']);
         if ($product && $product->hasUserGroups()) {
             $usergroupstoadd = $product->getProductUserGroups();
             foreach ($usergroupstoadd as $id) {
                 $g = Group::getByID($id);
                 if ($g) {
                     $customer->getUserInfo()->enterGroup($g);
                 }
             }
         }
     }
     if (!$customer->isGuest()) {
         //add user to Store Customers group
         $group = \Group::getByName('Store Customer');
         if (is_object($group) || $group->getGroupID() < 1) {
             $customer->getUserInfo()->enterGroup($group);
         }
     }
     // create order event and dispatch
     $event = new OrderEvent($order);
     Events::dispatch('on_vividstore_order', $event);
     //send out the alerts
     $mh = new MailService();
     $pkg = Package::getByHandle('vivid_store');
     $fromEmail = Config::get('vividstore.emailalerts');
     if (!$fromEmail) {
         $fromEmail = "store@" . $_SERVER['SERVER_NAME'];
     }
     $alertEmails = explode(",", Config::get('vividstore.notificationemails'));
     $alertEmails = array_map('trim', $alertEmails);
     //receipt
     $mh->from($fromEmail);
     $mh->to($customer->getEmail());
     $mh->addParameter("order", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("order_receipt", "vivid_store");
     $mh->sendMail();
     //order notification
     $mh->from($fromEmail);
     foreach ($alertEmails as $alertEmail) {
         $mh->to($alertEmail);
     }
     $mh->addParameter("order", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("new_order_notification", "vivid_store");
     $mh->sendMail();
     VividCart::clear();
     return $order;
 }
 public static function getOptionGroupsForProduct(StoreProduct $product)
 {
     $db = Database::connection();
     $em = $db->getEntityManager();
     return $em->getRepository('Concrete\\Package\\VividStore\\Src\\VividStore\\Product\\ProductOption\\ProductOptionGroup')->findBy(array('pID' => $product->getProductID()));
 }
Exemple #29
0
 public function save()
 {
     $data = $this->post();
     if ($data['pID']) {
         $this->edit($data['pID']);
     } else {
         $this->add();
     }
     if ($this->isPost()) {
         $errors = $this->validate($data);
         $this->error = null;
         //clear errors
         $this->error = $errors;
         if (!$errors->has()) {
             //save the product
             $product = StoreProduct::saveProduct($data);
             //save product attributes
             $aks = StoreProductKey::getList();
             foreach ($aks as $uak) {
                 $uak->saveAttributeForm($product);
             }
             //save images
             StoreProductImage::addImagesForProduct($data, $product);
             //save product groups
             StoreProductGroup::addGroupsForProduct($data, $product);
             //save product user groups
             StoreProductUserGroup::addUserGroupsForProduct($data, $product);
             //save product options
             StoreProductOption::addProductOptions($data, $product);
             //save files
             StoreProductFile::addFilesForProduct($data, $product);
             //save category locations
             StoreProductLocation::addLocationsForProduct($data, $product);
             if ($data['pID']) {
                 $this->redirect('/dashboard/store/products/', 'updated');
             } else {
                 $this->redirect('/dashboard/store/products/', 'success');
             }
         }
         //if no errors
     }
     //if post
 }