Exemplo n.º 1
0
 public function testAvailability()
 {
     $this->config->setRuntime('INVENTORY_TRACKING', 'DISABLE');
     $product1 = Product::getNewInstance($this->root);
     $product1->save();
     $product2 = Product::getNewInstance($this->root);
     $product2->save();
     ProductBundle::getNewInstance($this->container, $product1)->save();
     ProductBundle::getNewInstance($this->container, $product2)->save();
     // bundle container not enabled
     $this->assertFalse($this->container->isAvailable());
     $this->container->isEnabled->set(true);
     $this->assertTrue($this->container->isAvailable());
     // turn on inventory tracking
     $this->config->setRuntime('INVENTORY_TRACKING', 'ENABLE_AND_HIDE');
     $product1->stockCount->set(2);
     $product1->save();
     $product2->stockCount->set(2);
     $product2->save();
     $this->assertTrue($this->container->isAvailable());
     // remove inventory for one product
     $product2->stockCount->set(0);
     $product2->save();
     $this->assertFalse($this->container->isAvailable());
 }
 /**
  * Creates new relationship
  *
  * @role update
  */
 public function add()
 {
     $productID = $this->request->get('relatedownerID');
     $ownerID = $this->request->get('id');
     $owner = Product::getInstanceByID($ownerID, Product::LOAD_DATA);
     $product = Product::getInstanceByID($productID, Product::LOAD_DATA, array('ProductImage'));
     if ($product->isBundle()) {
         return new JSONResponse(array('error' => $this->translate('_err_bundle_with_bundle')));
     }
     if (!ProductBundle::hasRelationship($owner, $product)) {
         $instance = ProductBundle::getNewInstance($owner, $product);
         if (!$instance) {
             return new JSONResponse(array('error' => $this->translate('_err_add_to_itself')));
         }
         $instance->save();
         $response = new ActionResponse();
         $response->set('product', $product->toArray());
         $response->set('added', true);
         $response->set('total', $this->getTotal($owner));
         return $response;
     } else {
         return new JSONResponse(array('error' => $this->translate('_err_multiple')));
     }
 }
Exemplo n.º 3
0
 public function testDownloadableBundle()
 {
     $container = Product::getNewInstance(Category::getRootNode());
     $container->isEnabled->set(true);
     $container->type->set(Product::TYPE_BUNDLE);
     $container->setPrice($this->usd, 100);
     $container->save();
     foreach ($this->products as $product) {
         $product->type->set(Product::TYPE_DOWNLOADABLE);
         ProductBundle::getNewInstance($container, $product)->save();
     }
     $order = CustomerOrder::getNewInstance($this->user);
     $order->addProduct($container, 1);
     $order->save();
     $order->finalize();
     $this->assertEqual($order->getShipments()->size(), 1);
     $this->assertFalse($order->getShipments()->get(0)->isShippable());
 }